Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

OpenGL Problem with quaternion based camera and object placing, possible cml problem

This topic is 2941 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

For months I've been trying to get object and camera placing to work, and it feels like this should work, except that it is missing a character/sign somewhere causing everything to fail

The properties I'm trying to recreate are:
  • In is positive Z
  • Right is positive X
  • Up is positive Y
  • Identity quaternion is facing In/positive z
    This is how I create my projection matrix:
    gluPerspective(camera.fov, aspect, camera.znear, camera.zfar); pwnAssert_NoGLError();

    This is how I build my camera matrix:
    // camera.rotation is a quaternion representing the rotation of the camera, camera.position.vec is the vector of the object
    const math::mat44 fixOpenGlNegativeZ = cmat44(RightHandAround(Up(), Angle::FromDegrees(180)));
    : mat( fixOpenGlNegativeZ * cmat44(camera.rotation) * cmat44(vec3(-X(camera.position.vec), -Y(camera.position.vec), Z(camera.position.vec))) )

    This is how I generate the modelview matrix per object that is sent to gl through LoadMatrix
    // mat is the camera matrix above, pos is the vec3 worldspace position and rot is a quaterion representing the rotation of the object
    return mat * math::cmat44(pos) * math::cmat44(rot)

    My maths is cml based and here are their definitions:
    typedef cml::vector<real, cml::fixed<3> > vec3;
    typedef cml::quaternion<real, cml::fixed<>, cml::vector_first, cml::positive_cross> quat;
    typedef cml::matrix<real, cml::fixed<4,4>, cml::col_basis, cml::col_major > mat44;

    Along cml I have a few wrappers, mainly ©onverter functions beginning with c and ending with the resulting type, like cmat44 converting it's argument to a 4x4 matrix.
    cmat44(vec3) = cml::matrix_set_translation
    cmat44(quat) = cml::matrix_rotation_quaternion
    RightHandAround = cml::quaternion_rotation_axis_angle

    To get right of a quaternion I do:
    // v is global Right(positive X) and q is the quaternion
    const quat r = q * quat(v, 0) * math::GetConjugate(q);
    return cvec3(r); // ignores w
    // the vector is normalized later before it's used

    If anyone can point out what I'm doing wrong or offer suggestions I would be glad :)

    edit: slighty changed topictitle to better describe the problem

Share this post

Link to post
Share on other sites
I've might have a working implementation now. I changed fixOpenGlNegativeZ to a negative z scaling matrix since I probably want what is called a left handed coordinate space and the OpenGL faq recommends doing this.
Then I changed my lookat from
quaternion_rotation_aim_at(ret, from, to, up,

cml::matrix_look_at_LH(mat, from, to, up);

and that apparently fixed the problems(I still don't know what the difference between those functions are). that I at the moment can detect. I will have to do some more testing but for it seems to be working

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • 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!