Jump to content
  • Advertisement

Archived

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

MythoLogical

Moving eyepoint in direction of viewing angles

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

Hi, I want to be able to fly around in my model using the mouse to freelook, and up arrow key to move in the direction of view. My transform is: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(theta, 1.0, 0.0, 0.0); glRotatef(phi, 0.0, 1.0, 0.0); glRotatef(90.0, 1.0, 0.0, 0.0); glTranslatef(eyepoint[0],eyepoint[1],eyepoint[2]); My freelook works fine by changing phi & theta, but I need help moving the eyepoint in the direction of view. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
umm
sheet cant exactly recall what i done for this
umm
theres a tutorial at nehes site which shows u how to properly work out the coordinates to move when facing a certian direction
one of the 2 tutorials on loading a world
they use sin and cos to find the x and y component
ull c
thats waht i ended up using
hope this helps

Share this post


Link to post
Share on other sites
It''s easy for the eyepoint to go fordward or backward the direction of the view, but it is less obvious to determine how you move up/down or left/right. Do those up/down/left/right directions have to be implemented ?
And if yes, what behaviour do you want to give ? Do the viewer always have to look at the center of the object ?

Share this post


Link to post
Share on other sites
If you change the values of phi & theta with moving the mouse, then moving in the right direction should be no problem at all if the mouse is locked in the center of the screen!

just update X & Z at the same time.....

something like this (Not correct i think...)

eyepoint[0] += (float)cos(phi) * speed;
eyepoint[2] += (float)sin(phi) * speed;

Or something like this i think......
Probably not correct.....i don''t write this myself anymore so i can''t remember 100%....


Take Care


- -- ---[XaOs]--- -- -

[ project fy ]

Share this post


Link to post
Share on other sites
hmmm.....i can see that the above lines are not correct.....but i can''t see what it is.....

Just check NeHe''s......he he...

Take Care

- -- ---[XaOs]--- -- -

[ project fy ]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Vincoof,

How do you move forward? If you can show how to do that, then moving perpendicular would be easy (just add 90 degrees to the angles and take cross product to get third vector in frame).

Share this post


Link to post
Share on other sites
Using the code above, moving forward/backward is simply done by incremeting/decrementing eyeposition[2], IMO.

Share this post


Link to post
Share on other sites
ok lets work in 2 dimensions for sake of simplicity. the formula is like this

new_x = old_x + (cos(direction) * how_much_to_move)
new_y = old_y + (sin(direction) * how_much_to_move)

direction is ofcourse the direction youre pointing in, where 0 is to the right - down the positive x axis. remember that with the math library, angles are represented in radians (one complete revolution = 2 * PI) whereas opengl stores angles in degrees.

from the looks of it, you might look into gluLookAt() to simplify the transformation.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That makes sense, but how would you extend that to 3D? Both angles affect all three components of the new eyepoint position:

eye[0] += f(phi, theta, distance)
eye[1] += f(phi, theta, distance)
eye[2] += f(phi, theta, distance)

Right?

Share this post


Link to post
Share on other sites
the equations for 3d rotation should be easy to derive based on knowledge of 3d rotations. All it is is two rotations on two different planes.

do a search for spherical coordinates on google, that should turn up something.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!