PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Translate

Hi,

I am trying to fix the problem in my project when the object is moving. The Cube should locate in the center, but from the figures below are not.


Image

Image

I think it should be the translate problem. The part code is as following:

-----------------------------
//Before rotating, translating or scaling, reset the cube to its original position to prevent rounding errors
cube.Reset();
cube.Translate(patt_trans[0][3],-patt_trans[1][3],-patt_trans[2][3]);

cube.Rotate((4096/(2*3.14))*rot[0],(4096/(2*3.14))*rot[1],(4096/(2*3.14))*rot[2]);

//Set 3D perspective and move the camera backwards (scale for the Edge internal renderer)
display->Perspective3D(display->GetWidth(), display->GetHeight());

// #if !defined(EGL_USEGL)
display->WorldScale(65536 * 2, 65536 * 2, 65536 * 2);
// #endif

display->WorldScale(65536*patt_width/2, 65536*patt_width/2,65536*patt_width/2);
display->Render(&cube;);
return(E_OK);
display->WorldReset();


------------------------------------
Thanks.
Hi Gar,

It seems the translation is going fine, but your perspective isn't. Are you able to read the perspective matrix/properties from your camera? If you can retrieve the camera's perspective matrix, you can use the ClassEDisplay::SetPerspectiveMatrix function to fix your perpective.

Also, are you using OpenGL or the EDGELIB software 3D renderer?
Hi Edge,

I read the perspective matrix from my camera, but this matrix is 4X4, and the ClassEDisplay::SetPerspectiveMatrix function is reading 20:12 fixed point. What should i do then?

>Also, are you using OpenGL or the EDGELIB software 3D renderer?

I am using EDGELIB software to render.
Hi Gar,

If the source matrix from your camera is floating point, you need to convert the matrix. For example:

Code:

float *cameramatrix = fromyourcamera();
long perspectivematrix[16];
for (int i = 0; i < 16; i++)
perspectivematrix[i] = (int)(cameramatrix[i] * 4096);


If your camera matrix is in another format (such as 16:16 fixed point) then you need to divide each value by 16 (shifting bits 4 positions to the right).