Archived

This topic is now archived and is closed to further replies.

pasman

Camera class for RTS

Recommended Posts

hi, anyone managed to implement a camera class for a 3DRTS? That would have scrolling capabilities, rotating around the center of the screen,zooming, basicly what can be seen in Earth 2150. I tried to tweak the camera tutorials at GameTutorials.com but couldn''t make it work, oh and anyone working or worked on a 3dRTS or knows some resources/links regarding this subject, although i searched for hours the net i couldn''t find anything real good? thank you

Share this post


Link to post
Share on other sites
Modifying? How about take out a sheet of paper and start to put the stuff you need down and then when you think you have the required attributes start to code the class?

I''m not trying to be mean. It is the only way you get something done. Once you know how it works it is easy to go further, unless you don''t know what is going on it is going to be hellishly hard to grasp the "harder" things.

Share this post


Link to post
Share on other sites
thx dak lozar

and i''m not trying to modify some code i just said i also tried that...i wrote my own camera class but i can''t make it work...i''ll try more and if i won''t be able to make it i''ll ask you details...thx

Share this post


Link to post
Share on other sites
a maybe not too clean piece of code i couldnt resist to make up would rotate your cam in a way that will make it look like the world is rotating around the point you clicked on (the easier version would rotate around the screen center)

and of course you can simplify this a lot by not first calculating a point in the world and convert it to cam space ,-)

for the left/right rotation you will want to rotate around the global y axis btw.


float tx,ty,tz;

if (pos) {
float d[3]={pos[0]-Position[0], pos[1]-Position[1], pos[2]-Position[2]};
tx=d[0]*Right[0] + d[1]*Right[1] + d[2]*Right[2];
ty=d[0]*Up[0] + d[1]*Up[1] + d[2]*Up[2];
tz=d[0]*Forward[0] + d[1]*Forward[1] + d[2]*Forward[2];
}

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadMatrixf(Transform);
glRotatef(-deg, x,y,z);
glGetFloatv(GL_MODELVIEW_MATRIX, Transform);
glPopMatrix();

if (pos) {
Transform[12]=pos[0] - (tx*Right[0] + ty*Up[0] + tz*Forward[0]);
Transform[13]=pos[1] - (tx*Right[1] + ty*Up[1] + tz*Forward[1]);
Transform[14]=pos[2] - (tx*Right[2] + ty*Up[2] + tz*Forward[2]);
}

Share this post


Link to post
Share on other sites
thx trienco...ok, i''ve done the rotations and stuff but everything is aroud the world origin. For seting up the camera i use glLookAt, so is there a way to translate first to a point and apply glLookAt to the relative position? simply addin the point coordinates to position and direction vector won''t work

Share this post


Link to post
Share on other sites
erm... how would you apply glulookat to a position? *confused* its just a helper function to set up the modelview matrix.

one way if you dont care about having a camera would be to translate the point you want to rotate to the origin (ie. translate -position), then do the rotation and translate it back by restoring the old position (as the axes have changed).

or, if a few limitations dont mind you can always keep track of an angle, calculate the camera position depending on whatever should be centered on screen and use glulookat as usual.

Share this post


Link to post
Share on other sites
thx guys...i really did it with a little help from prodigy.openglforums.com, it has a nice camera tutorial, used his aproach but i have written the class for my purpose...anyway...it works perfectly...thx

Share this post


Link to post
Share on other sites