Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Camera Rotation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
28 replies to this topic

#1 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 04 September 2001 - 02:25 PM

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.

Sponsor:

#2 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 04 September 2001 - 04:47 PM

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

#3 _Buster_   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 September 2001 - 04:59 PM

Wow, Thanks that helped me too!

_BUSTER_



www.dotspot.cjb.net
______________________________
Check out my for sale domain name!

http://www.theatermonkey.com



#4 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 September 2001 - 12:53 PM

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));



#5 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 15 September 2001 - 01:40 PM

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 =)

#6 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 September 2001 - 03:16 PM

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)

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 15 September 2001 - 08:38 PM

>>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.

#8 DeathWish   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 September 2001 - 11:09 PM

Are you using glLoadIdentity() before you do all the rotations/translations?

DeathWish

#9 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 16 September 2001 - 04:13 AM

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!

#10 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 16 September 2001 - 10:13 AM

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()

#11 DeathWish   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 September 2001 - 05:29 AM

Personally I''ve never used gluLookAt(), I hardly use the glu library except for mipmaps and quadratic shapes. You could try it using just the standard glRotatef() and glTranslatef(), or you could do what I do in my basic 3D engine and translate all the co-ordinates by generating my own translation matrix and keeping the camera at 0,0,0.

Or, one thing you could try:

glLoadIdentity();
glPushMatrix();
// translate, rotate, render
glPopMatrix();

I''m not too sure about it though, so I may be totally wrong on the matrix push/pops... I hardly use them

(BTW, if you want to use your own translation matrix then I''m more than happy to help you if you don''t know how.)

DeathWish

#12 DeathWish   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 September 2001 - 05:31 AM

Another thought... you could try reverse transforming your camera. (Transform -x -y -z, rotate -z -y -x)

DeathWish

#13 Oluseyi   Staff Emeritus   -  Reputation: 1678

Like
Likes
Like

Posted 17 September 2001 - 06:09 AM

quote:
Original post by 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!


The compiler will do that for you. The only real optimization with sine and cosine is to precalculate them (they are horrendously expensive functions):
  
float Sine[360], Cosine[360];
const float M_PI = 3.141592654;
void CreateTrigLUTs( void )
{
for( int i = 0; i < 360; i++ )
{
Sine[i] = (float)sin( i * M_PI / 180 );
Cosine[i] = (float)cos( i * M_PI / 180 );
}
}


EDIT: i as array index.


Edited by - Oluseyi on September 17, 2001 1:10:35 PM

#14 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 17 September 2001 - 09:49 AM

using a LUT for a couple of sin''s cos''s will most likely be slower than using sin(A).
the LUT really is only benificial when youre doing heaps of sin''s at a time

http://members.xoom.com/myBollux

#15 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 September 2001 - 12:46 PM

Hey, none of that was really a reply to my last post.
Does anybody got any clues about the distance problem?

#16 DeathWish   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 September 2001 - 06:04 AM

Ok, I''ve got an idea:

glMatrixMode(GL_PERSPECTIVE);
gluPerspective(...);

glMatrixMode(GL_MODELVIEW);
gluLookAt(...);
glBegin(...);
...
glEnd();

#17 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 18 September 2001 - 09:11 AM

Actually I believe it''s GL_PROJECTION, not GL_PERSPECTIVE.
And that didn''t help at ALL.
You can''t use gluLookAt() in the GL_MODELVIEW matrix.
And I already do use gluPerspective in GL_PROJECTION and it can only be used in that matrix.

#18 zedzeek   Members   -  Reputation: 528

Like
Likes
Like

Posted 18 September 2001 - 11:27 AM

>>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<<

decrease your near planes depth value + increase the far planes value
in gluPerspective they are the 3rd+4th variable

http://members.xoom.com/myBollux

#19 DeathWish   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 September 2001 - 04:20 AM

I meant GL_PROJECTION... sorry I can''t help you then....

#20 glProgram   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 September 2001 - 09:07 AM

zedzeek, that is very obvious and it keeps getting repeated here. I have tried that 3 times! I''ve tried a near distance
of 0.0f and a far distance of 100000.0f, no effect.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS