Jump to content
  • Advertisement
Sign in to follow this  
bballmitch

Gun Rotation

This topic is 4463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!