Jump to content
  • Advertisement


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


Orientation of the coordinate-system

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

The default orientation of the coordinatesystem in openGL has positive X pointing to the right, positive Y pointing upwards and positive Z pointing out from the screen, right? this is the orientation you get when using gluPerspective for example? right? but why do the look- and right-vectors in my camera-class have the wrong sign??? I create the camera-object like this: Camera m_camera(Vector3(0,0,200), Vector3(0,1,0), Vector3(0,0,-1)); where the first argument is the cameras position, second is up-vector and third is the look-direction, the direction in which i want the camera to point. But it doesn''t. If it was i would se stuff located at the world-origo right? like this: glLoadIdentity(); m_camera.realize(); RenderSomeStuffWithoutTranslating(); where Camera::realize() looks like this: Camera::realize() { float m[16]; //create view-matrix m[0] = m_vRight.X(); m[1] = m_vUp.X(); m[2] = m_vLook.X(); m[3] = 0; m[4] = m_vRight.Y(); m[5] = m_vUp.Y(); m[6] = m_vLook.Y(); m[7] = 0; m[8] = m_vRight.Z(); m[9] = m_vUp.Z(); m[10] = m_vLook.Z(); m[11] = 0; m[12] = -m_vPosition.DotProduct(m_vRight); m[13] = -m_vPosition.DotProduct(m_vUp); m[14] = -m_vPosition.DotProduct(m_vLook); m[15] = 1; //translate into the world glMultMatrixf(m); } but i don''t se anything, unless i rotate the camera 180deg around the y-axis ofcourse.... *sigh* This has pretty much been driving me crazy for more or less a month now. I would _really_ appreciate some help with this one

Share this post

Link to post
Share on other sites
not exactly a month but far too long. use glgetfloatv after glulookat and then just compare your matrix with the ''correct'' matrix.

i had to change the sign for all elements of the look-vector (because of course i already did when creating the cam so positive will be forward and not backward. unless i decide to program while sitting behind my monitor thats the way that feels natural to me *g*

Share this post

Link to post
Share on other sites
Could someone please explaing the math behind that? Why would I want my LookDir-vector pointing in the opposite direction from where I actually want to look?
ie. if I want to look down the negative z-axis (into the screen), why would I want to set my m_vLook to (0,0,1)???
Or is that just something that indicates an error somewhere else in my cameraclass? I would really like to thik so, so that i could fix it and understand it. *sigh*


Share this post

Link to post
Share on other sites
You''re forgetting that everything in OpenGL is transformed by the same matrix, the modelview matrix. There is no separate view matrix so to move your virtual camera, you apply the *inverse* of its transform to the world (i.e. the modelview matrix). If you think about it, moving your camera forwards is the same thing as moving the world backwards. Thus applying the inverse of a transform gives you the expected result. It might be a good idea to read up on linear algebra (if you''re not familiar with it) to learn more about matrix inversions and the like. It''s a bit more complex than inverting the elements.

Share this post

Link to post
Share on other sites
i have written the following function to use the quake engine coordinate system in my opinion is much nicer than ogl`s

void CRenderer::LeftHandedIdentityMatrix(vec3_t forward,vec3_t up,vec3_t eye)
vec3_t f;
vec3_t s;
vec3_t u;
float m[16];



LeftHandedIdentityMatrix(gCamera.forward,gCamera.up,origin);//Set up for Quakestyle coordinate system

[edited by - Basiror on January 29, 2003 11:43:06 AM]

Share this post

Link to post
Share on other sites
GameCat: I am applying the inverse of the transformation-matrix to the modelview-matrix. That''s what the whole Camera::realize()-method is all about. Then again, since I don''t want to perform a generic inverse on the cameras transformation-matrix (since I store the data in four separate vectors instead (up, look, right and position)) i create the inverse directly from those vectors.

Anyhow, it''s working now. After following Trienco''s advice i could solve the problem just like him, by setting m_vLook = -m_vLook

But i still don''t understand WHY... *sigh*

/Niklas Andersson

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!