Skip to main content
gamedev.net
🔒 Locked

Simple camera: translation issues

Started by RuneLancer 2 replies 400+ views
Original Post
RuneLancer
RuneLancer
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...? :)
nts
nts
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).
RuneLancer
RuneLancer
Huh, omg, that was so easy.

Sweet, thanks! :)
Solias
Solias
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()

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.