Sign in to follow this  
bballmitch

Gun Rotation

Recommended Posts

glPushMatrix();
glTranslatef( player1->getX(), player1->getY(), player1->getZ() );
Gun->draw();
glPopMatrix();

I have this gun model and I draw it. If I always look foreward and never move my line of sight, then the model works fine. But I want to be able to change my line of sight ( both verticle and horizontal ) and move and the model should still show up correctly. I suspect that I should need to call glRotatef() a couple times and maybe even change the parameters of glTranslatef(). The horizontal line of sight is defined as "view_angle" and verticle is "sight" ( both in radians ). Could someone help me out?

Share this post


Link to post
Share on other sites
If this is an FPS, you shouldn't have to even translate before rendering the gun. It's supposed to be in the same place all the time (ie, don't let the camera effect it either)

If not fps, use whatever it's attached to, translation, rotation etc, add add to that.

Good luck!

Share this post


Link to post
Share on other sites
Call glLoadIdentity(), render the gun with translation and that's it! The gun will not be affected by camera rotation. The translation is only needed to position the gun. I suggest using a depth hack to draw the gun so it doesn't penetrate the walls or other geometry. Clearing the depth buffer before rendering it should do the trick.

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