newb question (help needed)

Started by
5 comments, last by Kalle 21 years, 5 months ago
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!
Advertisement

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
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!
How do you rotate the ship, glRotate or with a matrix?
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...
I understand your problem, sorta.
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

Im'' probably wrong about this, so experiment wildly.
and the angle you getfrom asin,acos and atan is in radiants.





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!

This topic is closed to new replies.

Advertisement