Jump to content
  • Advertisement

Archived

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

glProgram

Camera Rotation

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

Can anybody tell me a good way to do camera rotation using gluLookAt()? All tutorials I''ve seen did a terrible job and didn''t work. Also no one ever really explains gluLookAt(). Also it would help if it were done with the camera''s Position X, Y, Z and Look X, Y, Z, and Up X, Y, Z. And if possible can you include how to move in the direction the camera is looking at. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
very similar to a post below, must be the new topic in class

if u want to do rotation on 3 axises (6DOF?)then u will need another method than eular angles eg angle/axis + quaternion/matrices which is much more complicated (check on the net for a lot of examples/tutorials).
if all u want to do is a quakelike movement FPS then u can get away with 1.5 axises using eulars

gluLookAt( cam.x, cam.y, cam.z, cam.x+camDIR.x, cam.y+camDIR.y, cam.z+camDIR.z, 0,1,0 )

cam is where the camera is
camDIR is the direction the camera is looking

the player can rotate on the ground plane 0..360 deg (like a compass) this is called the heading.
the player can also look up and down +90 (at sky) .. -90 (at feet) this is the pitch.(note u prolly want to limit that to 89 .. -89deg

ok to find the camera direction use the following

camDIR.x = cos(heading) * cos(pitch);
camDIR.y = sin(pitch);
camDIR.z = sin(heading) * cos(pitch);

now to move foward u ignore the pitch and just concentrate on the XZ plane

(foward key pressed)
cam.x += sin( heading )
cam.z += cos( heading )

piece of piss right?

note above u need to supply heading/pitch in radians and not degrees to convert degrees to radians multiple the degrees by (PI/180) about 0.017

Share this post


Link to post
Share on other sites
It still doesn''t work....
Here''s what I tried to find the direction:

right and up are the distance up or right for rotation.

camDIR.x = sin((camDIR.x+right)*(180/0.017))*cos((camDIR.y+up)*(180/0.17));
camDIR.y = sin((camDIR.y+up)*(180/0.17));
camDIR.z = sin((camDIR.x+right)*(180/0.017))*cos((camDIR.y+up)*(180/0.17));

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You''ll find your problem is that the computer works in radians. You are sending the angle in degrees and of course this wont work. Here are 2 inline functions that i use lots.

inline float cosd(float p_angle)
{
return cos(p_angle * (3.141592654 / 180));
}

inline float sind(float p_angle)
{
return sin(p_angle * (3.141592654 / 180));
}

This will allow you to enter a degrees angle and get the correct results back. Hope this helps =)

Share this post


Link to post
Share on other sites
Something is really messed up in the code but I can''t
figure out what! I used to be able to move around in the world
with glTranslatef() and the objects looked truley 3D(They still
do but...) and they would shrink as you got further away
and grow larger as you got closer as they should but now you
have to get real close to be able to see them... If you aren''t
real close it doesn''t draw them. The rotation still just spins
all the objects and shoves them either down or left(Even
if you rotate the opposite direction).
This is really starting to make me mad.
Anybody got any ideas? (Mabye if someone actually SHOWED
how to apply the suggestions because no one really gave
too detailed info)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
>>Something is really messed up in the code but I can''t
figure out what! I used to be able to move around in the world
with glTranslatef() and the objects looked truley 3D(They still
do but...) and they would shrink as you got further away
and grow larger as you got closer as they should but now you
have to get real close to be able to see them... If you aren''t
real close it doesn''t draw them. <<

perhaps try this look in your code for gluPerspective() or glFrustum() and make the last number 100x larger.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
inline float cosd(float p_angle)
{
return cos(p_angle * (3.141592654 / 180));
}

wouldnt it be better to precalculate 3.141592654 / 180
this would speed the function up!

Share this post


Link to post
Share on other sites
Thanks, DeathWish. I added glLoadIdentity() and now it
appears to be somewhat closer!
There''s still that problem with distance.(You have to be REAL close)(And also note that when rotating the camera I can
see that object wireframes will get cut off near the camera
and at the ends that are far from the camera.
I did mess with gluPerspective with no sucess.
Currently I can''t tell if it really looks like it is rotating
the camera or rotationg the objects themselves.
It also appears the everythings rotating the opposite direction they''re supposed to.
Also the camera doesn''t move/translate the direction it is facing
And I did put the CamDIR.x/y/z+x/y/z in gluLookAt()

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!