Sign in to follow this  

First Person View

Recommended Posts

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

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this