Rotation - New (hopefully better) Post

How does gluLookAt(); work???

/******************************/

I have come to understand that the previous post was hard to understand so I will try to explain it more careful this time.

What I am trying to do:

• A spaceship simulator (mush like SpaceWars on NeHe’s Site witch by the way doesn’t work as I want either).
• Control the ship with the Arrow keys.
• The Arrow should represent the ship controls.
This means that if I pull back the controls (DOWN KEY), the ships nose should tilt UP.
And UP KEY should tilt the nose DOWN.
LEFT & RIGHT KEY should SPIN the ship.
• I want the camera to follow the ship.
• I want Asteroids to and they should rotate constantly in the same way.

Problems:

• If I use this for the ship it obviously don’t work.
And it doesn’t work better for the asteroids.

glPushMatrix();

glTranslate(shipXpos, shipYpos, shipZpos):
glRotatef(shipXrot, 1.0f, 0.0f, 0.0f);
glRotatef(shipYrot, 1.0f, 0.0f, 0.0f);
glRotatef(shipZrot, 1.0f, 0.0f, 0.0f);

DrawShip();

glPopMatrix();

Solutions:

• This is where I hoped you fill in.

Well, you might try converting your view angles to vectors. Then you can either use gluLookAt or just do your own glRotate & glTranslate stuff to handle setting the view properly. Additionally, if you are doing a 3rd person thing, you can use the calculated forward vector times some negative amount to push the camera behind the ship so that you will actually see the ship in front of you. At least this is how I would handle the ship’s camera.

GluLookAt()
takes 9 arguments

the first three are co-ordinates of p:
the next three of p’:
and the last three of p’’:

``````   p''
/|
/ |
``````

/ |

/

p p’

okay, so basically p is the position on your “camera” or whatever… I know the “camera” does not exist.

p’ the the object… basically your ship… probably the center it…

and p’’ should be like 22degrees above the ship… so like the same x and z co-ordinates as (p’)s x and y but the y coordinate is different than the p’ one…

I wish I could direct you to a site… but i can’t because I won’t be able to go home for atleast 10 days…

If you don’t wanna figure out the equations your self… (they deal w/ alot of trig.) look up the post I made about the camera or something… few days back. I hope this helps

P.S. remember to setup using glFrustum/GluPerspective(I like the latter), in your init function.

-Navreet Gill

and p’’ should be like 22degrees above the ship… so like the same x and z co-ordinates as (p’)s x and y but the y coordinate is different than the p’ one…

>>and p’’ should be like 22degrees above the >>ship… so like the same x and z co->>ordinates as (p’)s x and y but the y >>coordinate is different than the p’ one…

sorry that’s only if you are looking straight at the ship… basically what I meant to say way that p’’ s coordiantes should be a little above the object you are looking at, like if you were viewing from the top p’’ should be directly in front of the ship… hope this helps…

Navreet