First Person View

Started by
-1 comments, last by AliG 14 years, 1 month ago
Hi, I am using Open Scene Graph to code some basic gaming features. If I have my avatar's head position (X,Y,Z) and orientation (Roll, Pitch, Yaw), is there a series of commands I can use to set up a camera that is the same as my avatar's first person view? I have tried doing it by using viewer.getCamera()->setViewMatrixAsLookAt(eye, center, up) but I am getting a bizarre behavior. I have set up my camera as follows: viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3(XCoordinate,YCoordinate,ZCoordinate), osg::Vec3(XCoordinate - 10*cos(osg::DegreesToRadians(Pitch))*sin(osg::DegreesToRadians(Yaw)),YCoordinate + 10*cos(osg::DegreesToRadians(Pitch))*cos(osg::DegreesToRadians(Yaw)),ZCoordinate + 10*sin(osg::DegreesToRadians(Pitch))), osg::Vec3(0.0, 0.0, 1.0)); My XCoordinate, YCoordinate and ZCoordinate values remain constant over the whole code and the values of Roll, Pitch, Yaw change and yet when the Roll, Pitch, Yaw are changed, the position of the camera's eye is being changed. Even though I defined the eye's position as osg::Vec3(XCoordinate,YCoordinate,ZCoordinate). Seems a bit odd for me to understand why this is happening. Does anyone have any suggestions? Thanks

This topic is closed to new replies.

Advertisement