Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Find forward vector for node different from camera forward vector

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    16

    Find forward vector for node different from camera forward vector

    Hi all,

    I am trying to extract the forward vector from 4x4 transformation matrix.
    I have two forms of calculation one is for nodes in the scene graph and other is for camera.

    This is how I calculate transformation matrix for node.

    Code :
     
    // Matrix44 is a float[16]
     
    Matrix44 nodeTranslationMat; // translation matrix for node
     
    Matrix44 nodeRotationMat; // rotation matrix for node
     
    Matrix44 transformationMatrix= nodeTranslationMat* nodeRotationMat; // transformation matrix

    And this is how I do it for camera

    Code :
    Matrix44 cameraTranslateMat; // translation matrix for camera
     
    Matrix44 cameraRotationMat; // rotation matrix for camera
     
    Matrix44 transformationMatrix= cameraRotationMat* cameraTranslateMat; // transformation matrix, note - multiplication order is different form node

    And then for the camera forward vector I can extract using above transformation matrix like

    Code :
    Vector3f forwardVector = Vector3f(transformationMatrix[2], transformationMatrix[6], transformationMatrix[10]);

    But If I do this above to find the forward vector for node it's not works.

    Could you please help me to find it it?

  2. #2
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    65
    Changing the order of rotation and translation makes for two different transformations .. reasonably with two different z-vectors in the output transformation-matrix.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    16
    Thanks for the reply.

    After doing visual experiments, I realized that the forward vector for node can be calculate as
    Code :
     Math::Vector3f(transformationMatrix[8], transformationMatrix[9], transformationMatrix[10]);

    For camera, forward vector is
    Code :
    Math::Vector3f(transformationMatrix[2], transformationMatrix[6], transformationMatrix[10])

    So if the multiplication order is different

    Code :
    Matrix44 nodeTransformationMatrix= nodeTranslationMat* nodeRotationMat;
    Matrix44 cameraTransformationMatrix= cameraRotationMat * cameraTranslationMat;

    forward vector calculation should also different?

    Sorry I am trying to learn the basics.

  4. #4
    Intern Contributor
    Join Date
    Jul 2013
    Posts
    65
    deshan,
    have you checked the visual differences between the two transformations?
    If you do two nodes, one with each transformation .. you'll see why you may not be able to match up the two 'forward' vectors.
    A 'forward' vector is not an inherent quality of a matrix .. it may fit the z-vector for the camera, but did you make your node in coordinates, where the z-vector is 'forward'?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •