[osg-users] LookAt() function parameter meanings..

208 views
Skip to first unread message

Rowley, Marlin R

unread,
Aug 13, 2018, 10:07:18 AM8/13/18
to OpenSceneGraph Users

All,

 

I’m very confused by the parameters passed into this function.  I am going over some of the legacy code and saw this line of code:

 

osg::Matrixd frustumView;

frustumView.makeLookAt(VIEW_POS, mDirection, mUp);

 

saw the docs, it’s described like this:

 

void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up);

 

So in this context, I would think that “eye” represents the look vector.  However, it seems to work like a position vector.  The “center” parameter expects a direction vector (0, -1, 0) where the look vector is along the -yaxis.

 

This matrix will not translate to OpenGL properly since it’s coordinate system is based off of a right handed coordinate frame.

 

Questions:

 

  1. Am I interpreting these parameters properly?
  2. How would I convert this system to the OpenGL right-handed system?

 

----------------------------------------

Marlin Rowley

Software Engineer, Staff

cid:image002.jpg@01D39374.DEC5A2E0

Missiles and Fire Control

972-603-1931 (office)

214-926-0622 (mobile)

marlin....@lmco.com

 

Ravi Mathur

unread,
Aug 13, 2018, 10:33:01 AM8/13/18
to OpenSceneGraph Users
Hey Martin,

You are not interpreting the parameters properly. Look at the header for Matrixd.cpp:

  /** Set the position and orientation to be a view matrix, 
    * using the same convention as gluLookAt.
  */
  void makeLookAt(const Vec3d& eye,const Vec3d& center,const Vec3d& up    );

It follows the same convention and algorithm as gluLookAt(), so you can look at the many online reference pages for that (microsoft, khronos). There is no question about its correctness or compatibility with OpenGL, since OSG has been used with OpenGL in hundreds of projects for like 20 years. :D

To very directly answer your question, "eye" is the eye position (or camera if you prefer), "center" is a point towards which the eye is looking, and therefore the look vector points from eye towards center. This look vector is the negative z-axis of OpenGL. The "up" vector specifies the direction of the positive y-axis. The x-axis is then defined as y-cross-z, which is the default OpenGL right-handed system. HOWEVER, OSG takes it a step further and maps the y-axis to the look vector (into the screen). With this simple rotation, x points right and z points up, which remains right-handed. I'm guessing this is done because many OSG applications represent physical (real-world) systems, in which the z-axis often does point up. (Robert or someone else can correct me if that's not the reason)

Ravi

_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Rowley, Marlin R

unread,
Aug 13, 2018, 10:58:37 AM8/13/18
to OpenSceneGraph Users

Ravi,

 

During the projection matrix phase, OpenGL switches to left-handed system (i.e. Z-axis points positive going into the screen).  But I missed the rotation, so it stays left-handed with +x (right), -y (look), and +z(up).

 

Thanks for the interpretation of the parameter names.  I interpreted “center” to mean a position point – not a vector.  And “eye” to mean the direction the eye is pointed to.

 

----------------------------------------

Marlin Rowley

Software Engineer, Staff

cid:image002.jpg@01D39374.DEC5A2E0

Missiles and Fire Control

972-603-1931 (office)

214-926-0622 (mobile)

marlin....@lmco.com

 

Missiles and Fire Control

Robert Osfield

unread,
Aug 13, 2018, 11:19:57 AM8/13/18
to OpenSceneGraph Users
The OSG's LookAt implementation is *exactly* the same as gluLookAt,
the parameters and the maths are all identical. I made sure this was
the case to enable users to map GL code across easily as well as for
us to be able to leverage existing GL documentation.

The core OSG doesn't have a fixed "up" direction, but the by
convention the viewer, camera manipulators and most of the loaders
follow the convention that WORLD coordinates are +ve Z up, +ve Y
north, and +ve X east.

When you read OpenGL docs it will describe the EYE coordinates being
+ve Y up, +ve Z out, +ve X to the right.

The key thing to remember that EYE and WORLD coordinates and separated
by the View transform matrix. If this View matrix is Identity then
EYE and WORD orientation are the same, but this is only a special case
as soon as the eye moves through the scene this orientation
consistency is broken.

This is fundamental issue in compute graphics to get your head around,
EYE coordinates and WORLD coords are decoupled, when you think about
what you are doing and what coordinate frame you have you need to know
up front are your world in WORLD coordinates or EYE coordinates.

Another layer upon this is the we have transforms in the scene that
introduce LOCAL coordinates that nest within the WORLD coordinates.
This transforms decouple the LOCAL and WORLD coordinates, so local up
etc. can be very different between WORLD and LOCAL coords - think a
wheel on a car, it doesn't matter than the local up is spinning around
every frame.

Robert.
Reply all
Reply to author
Forward
0 new messages