Jump to content
  • Advertisement
Sign in to follow this  
NimrodPSI

OpenGL 1st Person Shooter Camera Problem... Opengl

This topic is 3804 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

Alright, so im new to gamedev forums, but im alright with opengl and c++. Im currently working with a basic camera system based off glLookAt() and thats all fine and dandy, problem comes with getting somthing to follow the camera. Basically i want like a hand with sword, or gun etc. to float around and follow the camera and its rotations. I have done this before by just setting the object right before the glLookAt() func. but this causes the object to look quite out of place in comparison to other things in the world. So i figure just use translations and rotations, the translating works but i cant get it to rotate with the camera (which uses mouse rotation) it just ends up running off in some other direction... help anyone? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Sooo uh... no one need waste their time trying to help me. I sat around and
got it to work. If anyone has the same problem i solved it by placing the object at the cameras x, and z view (which is how i had it before) but the rotation problem i solved by doing a y-rotation based off the arc-tangent of the distance between the camera xpos, and xview, divided by the zpos and zview differance. If that sounds dumb here:

glTranslatef( Camera.xView, 0.5f, Camera.zView);

rot=(-(atan(((Camera.xPos-Camera.xView)/(Camera.zPos-Camera.zView))))/M_PI*180);

glRotatef( -rot, 0.0f, 1.0f, 0.0f);

drawObject();



Sorry/Thanks!

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!