Hello!

I was wondering if someone could help explain the camera's view matrix to me. 
The reason I ask is that, when I look at it in the debugger, it is not at all 
what I expected it to be.

Here's what I am doing. Before calling osg::Viewer::run(), I set the camera 
manipulator, and set its home position, like so:


Code:

viewer.setCameraManipulator(new osgGA::TrackballManipulator);
viewer.getCameraManipulator()->setHomePosition(osg::Vec3d(0.0, 500.0, 30.0), 
osg::Vec3d(0.0, 480.0, 30.0), osg::Vec3d(0.0, 0.0, 1.0));




As you can probably tell, this should amount to placing the camera at 0,500,30 
and then swinging it around 180 degrees on the Z axis, such that we're looking 
directly down the -Y axis.

So if I wanted to create a world matrix for this camera, I would first create a 
180 degree z-rotation matrix:

-1 0 0 0
0 -1 0 0
0 0 1 0
0 0 0 1

And then I would multiply it against the translation matrix:

1 0 0 0
0 1 0 0
0 0 1 0
0 500 30 1

Which yields:

-1 0 0 0
0 -1 0 0
0 0 1 0
0 500 30 1

So if there is a point that is [1,1,1] relative to the camera, multiplying it 
by this matrix would yield [-1,499,31], which looks to be the correct 
world-space position.

On the other hand, if I wanted to know what the point [-1, 499, 31] is relative 
to the camera, I would need to know the inverse of the camera's world matrix, 
which is the view matrix, which happens to be what my question is about. So 
anyway, when I calculate the inverse of the camera's world matrix, I get:

-1 0 0 0
0 -1 0 0
0 0 1 0
0 500 -30 1

Multiplying my world-space vector [-1, 499, 31] by this matrix yields [1, 1, 
1], which is what I want. So, I'm satisfied that this is correct.

The problem is, when I actually call osg::Camera::getViewMatrix() for this 
camera, what I get instead is:

1- 0 0 0
0 0 1 0
0 1 0 0
0 -30 -500 1

..and multiplying [-1, 499, 31] by this yields [1, 1, -1], which is close, but 
not what I'm looking for (and I suspect it would be way off if I were 
multiplying with more interesting vectors).

The thing is, the scene seems to render properly, and if I call 
osg::Matrix::getLookAt() on this (seemingly incorrect) view matrix, it gives me 
the correct values for the eye, center, and up vectors.

So I was hoping someone could explain to me why this works the way that it 
does, perhaps by pointing out an error in my reasoning. I am trying to 
implement a shader that is similar to shadow mapping, and it's not working, and 
this is the only step along the way that isn't working as I expected it to.

Thanks!
Frank Sullivan[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=18302#18302





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to