Jump to content
  • Advertisement
Sign in to follow this  
RuneLancer

Simple camera: translation issues

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

I'm working on a simple camera for my game which should basically behave as so: It will remain centered on the player, a billboarded sprite, at all times (unless a script takes control of it). The player can move around in the map and the camera will follow at a fixed distance, presumably from a bird's eye view (think SNES RPG, only in a 3D environment). The player will be able to rotate the camera along the X and Y axis, and possibly zoom in and out. Right now, I just have a simple map. My camera moves around the map just fine, so having it follow the player won't be an issue. However, whenever I attempt to rotate the camera, the map is rotated around its origin, as opposed to where the camera "looks" at (which would be the player's position). Basically, I do this... glTranslatef(mEng.xPos, mEng.yPos, mEng.zPos); glRotatef(mEng.xRot, 1.0f, 0.0f, 0.0f); glRotatef(mEng.yRot, 0.0f, 1.0f, 0.0f); ...and then I render the map. I feel like I'm missing something here, perhaps an additional translation which would recenter the map, but experimentation hasn't given any positive results. I've checked around, but my limited knowledge of 3D mathematics has let me down somewhat. Any help...? :)

Share this post


Link to post
Share on other sites
Advertisement
take a look at gluLookAt, may be very helpful in your case (needs the cam position, where to look [the player] and the up vector).

Share this post


Link to post
Share on other sites
gluLookAt may be the best option, but your original problem was caused by haveing the rotation and translation in the wrong order. In ogl transforms are applied in reverse order, so the map was rotating (around it's origin) first and then translating. If you switched the order it would translate to the camera's origin and then rotate around that.

glRotate()
glTranslate()

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!