Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


About translations y rotations

This topic is 6230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

-- -- TRANSLATION QUESTION -- Hi All. I''m making my own 3D engine and at the born of this one I used the following function to translate an object (Relative mode): void KObjet::Translate(const float& fX,const float& fY,const float& fZ) { register KVector kTras(fX,fY,fZ); register KFace * pFace; register int i; // Translate the center m_kCenter+=kTras; // Translate the pivot m_kPivot+=kTras; // Translate the Bounding Box for (i=0;i<8;i++) m_kBoundingBox+=kTras; // Translate the vertex for (i=0;im_nNumElement;i++) m_pVertexList->Get(i)->m_kVertice+=kTras; // Cambiamos la ecuación del plano de las caras for (i=0;im_nNumElement;i++) { pFace=m_pFaceList->Get(i); pFace->m_kPlane.PutD( -(pFace->m_kPlane.GetNormal()%pFace->GetVert(0)->m_kVertice) ); } } But Now I change all this one to use matrices and quaternions. My KObject class have two members variables one is the actual transformation matrix (m_kTransMatrix) and the other is the current quaternion used for orientation. Then in the KView::Render() function I setup the camera transformation and then I load the current model matrix using: Camera.SetupView(); for (i=0; iNumObject; i++) { glPushMatrix(); m_pScene->m_pObjectList->Get(current)->m_kTransMatrix.Get(m); glMultMatrix(m); RenderObject(m_pScene->m_pObjectList->Get(current)); glPopMatrix(); } My new Translate function is the following one: void KObjet::Translate(const float& fX,const float& fY,const float& fZ) { register KVector kTras(fX,fY,fZ); register KCara * pCara; register int i; // Translate the center m_kCentro+=kTras; // Traslate the pivot // m_kPivot+=kTras; // Traslate the Bounding Box // for (i=0;i<8;i++) m_kBoundingBox[i]+=kTras; // Change the plane equation of all the faces // for (i=0;im_nNumElementos;i++) // { // pCara = m_pListaCaras->Obtener(i); // pCara->m_kPlano.PonD( -(pCara->m_kPlano.ObtNormal()%pCara->ObtVert(0)->m_kVertice) ); // } m_kMatTransformacion.Trasladar(fX,fY,fZ); } Using this method if I have a cube with vertex 1=(100,20,13). And I ask to know the value of this vertex I always get (100,20,13) because I don''t modify the vertex list, I only multiply these vertex with the transformation matrix when I render the object. Therefore I must modify the Center, Pivot and Bbox (Face''s plane equation?) of this object when I call any transformation function like Translate because I must now the real position on my scene to make for example frustum culling. So I don''t know if I must multiply all the vertex list with the transformation matrix in every call to Translate or by the way I make the things as this previus way. -- -- ROTATION -- And now another question about transformation but this is about Rotation Recently I have implemented quaternions on my engine and I modified the rotate function as follow: void KObjet::Rotate(const KVector& kRefer, const float &fRotX, const float &fRotY, const float &fRotZ) { // Auxiliar vertex KVector kVectAux=kReferencia; float fM[16]; KMatrix kMatAux; // Translate de object to the reference point (The previus function) Traslate(kVectAux.GetX(),kVectAux.GetY(),kVectAux.GetZ()); // Set the quaternion that represent the rotation m_kQuaternion.Set(fRotX,fRotY,fRotZ); // Get the rotation matix and insert in the auxiliar matrix m_kQuaternion.GetMatrix(fM); kMatAux.Set(fM); // We apply the actual transformation (Multiplying for the previus transformation) m_kMatTransformacion*=kMatAux; // We return to the inicial position kVectAux=-kVectAux; Traslate(kVectAux.GetX(),kVectAux.GetY(),kVectAux.GetZ()); } This function rotate the object using a reference point. This rotate RotX around X-Axis, RotY around Y-Axis and RotZ about Z-Axis. My problem is that if I make this and display the object axis (when I call RenderObject(...)) I can see that the rotation is using object local axis. When I rotate the object the object axis is also rotated and when I make another rotation this last is made using the local axis and not the world¡s axis. I want that if I call: Rotate(ObjectCenter,90,0,0). This rotate the object 45 degrees with regard to the world axis X and if then If I make another rotation also rotated with regard to the world axis specified. Another answer? A lot of thanks

Share this post

Link to post
Share on other sites
I''m trying to provide some answers for both questions:

1st. it''s quite unconvenient and also unefficient to store your geometry transfomed (just think how much faster is to multiply a matrix than transforming 10000 verts)... store the transformation matrix (world to object) instead and do the glLoadMatrix thing before rendering every object, whenever having the need of world absolute coords for your geometry then calculate the transformed vertices, or use a workaround, in case of clipping, transform the plane equation (point/vector) into your object coordinate system (using the inverse of your object''s transformation matrix) and then do the check for the transformed plane, it''s much more efficient than transforming the whole set of vertices...

2nd. it seems that you are using column vector convention in your matrix algebra... and you should be storing the matrix coeficients as arrays of columns as well (this is also the openGL way), so when you postmultiply your object''s transform by the rotation matrix your rotation is indeed referred to your object''s coordinate system... if you want it referred to the world absolute thing just premultiply:


and thats all. However, if you have any doubt about this, you should better revise your matrix algebra before going on...

Espero que te sirva de algo, paisano.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!