Skip to main content
gamedev.net
🔒 Locked

2D Camera question

Started by Sardukar Feb 27, 2007 at 3:25 AM 2 replies 1k views
Original Post
Sardukar
Sardukar
Im developing a 2D RTS game and i need to think about how the camera is going to work. Would the best way to move the view around be just to modify all object variables? (unitPosition + ViewChange) etc. Or is there another way to do it that would be more effecient?
TheRedDeath
TheRedDeath
Instead of changing the position of every object to simulate a moving camera (which I think is what you suggested), why not just do a global transform (glTranslatef(x, y, z);) or use gluPerspective() to simulate a camera? In my experience the following form is very easy:

SetupWindow();while(mainLoop) {  GetInput();   clearBuffers();  glTranslatef(x, y, z);  Render();}


where x, y, and z are floats that are manipulated by GetInput().
Sardukar
Sardukar
thx mate i didnt think at all about doing a global gltranslate :D
Sardukar
Sardukar
hmmm, im stuck on another problem now. I'm having trouble getting the y axis to be correct when i move the camera (increase, decrease y value) using gltranslate or glulookat.

My program is using an ortho view. gluUnProject to get mouse coordinates then

mouseY = viewport[3] - objY;

Then simply a glTranslate or gluLookAt to move the scene around (same effect basically for 2d). The problem is the Y value is upside down after the camera is moved. There is no problem with the X axis it works fine. So basically when i move an object in my program after ive moved the camera's y position, the object moves the oppposite Y direction. I've tried inversing the value but it doesnt work.

Any help would be great :) sorry if its explained poorly but this problem is confusing be a fair bit as i just cant get it working.

Topic Locked

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

Sign in to reply to this topic.