#### Archived

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

# newb question (help needed)

This topic is 5734 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi, at first don''t be worry about my bad english... I realy enjoy your book OpenGL Game Programming. I try to make a Elite-like SpaceSim. Everything works fine so long, but how can I implement a function to position (rotate) a player straight to an object (eg autopilot). I have the positions of the player and the object in quaternions. Do I need any other information? Please help... A codesnipet where fine Thanks!

##### Share on other sites

The first thing you need to get is the vector towards the object.
1. objectpos - playerpos
2.divide that vector by the magnitude of the vector(m^2=x^2+y^2+z^2)

3. if you want it in degrees then use tigonometry to get the angles

##### Share on other sites
Thanks,

ic_overlord with your help I have the position relative to the player. That''s not hard to code, but how to rotate the player in that direction (it seems that I do not see the forest in case of that many trees)...

Thanks again!

##### Share on other sites
How do you rotate the ship, glRotate or with a matrix?

##### Share on other sites
Hi ic_overlord,

thanks again...

I''ll whant to rotate during the update for the actor. The rotation itself is done with glRotatef for every axis. But in the drawingloop over all actors the calculation must be done. At that moment I have the worldposition of the player and the worldposition of the actor (stored as an vector), the rotation of the player and the rotation of the actor (stored as a quaternion) and the movedirection of the player and the actor (stored as a quaternion). What I whant to do is:

set the new quaternions of the player for rotation and movedirection. This can either be done by putting the new angles per axis, or by putting the eulers of it.

I hope you understand my problem, it is not easy for me to explain this in english.

Thanks again...

##### Share on other sites
I don''t know what the hell quaternions or eulers are.

I persume you know trigenometry decently.

A 2D vector can be described with one triangle(with one 90 degree corner) either as an angle+ a distance or as legth and height

For a 3D vetor it''s the same exept you got two triangles(even tree triangles if you want)

so if you want the x angle(xa) the the formula would be(taken your vector is stored in xyz coords)

tan(xa)=y/z ( xa=atan(y/z)*(180/3.1415); )
the others are then
tan(ya)=x/z
tan(za)=x/y

and the angle you getfrom asin,acos and atan is in radiants.

##### Share on other sites
Hi ic_overlord,

thanks a lot!

My mathematics are a bit rusted... your post was the stub I needed to perform my brain running...

by the way, are you interested in a demo (if it is as far to make one)?

It uses some modified code from the NeHe tutorials. I also changed the 3dsconv.exe to fit it my needs. So I can use 3DS-files and get C++ source-code (even with own calculated vertex-normals for smooth shading). The models can have some moveable (rotable)subobjects and up to 10 particlesystems connected to them.

at the moment i am fighting with GL_BLEND and the order of the objects. it doesn''t look well if parts are blended, but nothing seems to be behind them...

bye for now and again 1000th of thanks!

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002284
×