Turning a ship towards a point in space...

Started by
5 comments, last by DirectXFreak 20 years, 4 months ago
What if there''s an object sitting in space with a position and rotation... now say that I want the ship to turn toward any point in 3d space, how would I do that? and please realize that the ship has a rotation vector (x,y,z). thanks
--m_nPostCount++
Advertisement
that depends on what your rotation vector is. if it is a collection of three angles then delete it and forget the approach, it will throw away the order of applied rotations which is important to get the right result.

next: do you want to turn or just place it correctly? the latter would be easier but is usually not too useful. so you need two things: angle and axis. the axis should be the crossproduct between your current view direction and the vector from your position to the target point. the angle will be the inverse cos of the dotproduct (normalize them before). things will get more complicated if you dont just want to look at a point but also want a certain orientation.

another way would be transforming your current and target matrix to quaternions which are nicer to interpolate but introduce more overhead for converting back and forth.
f@dzhttp://festini.device-zero.de
If I understand your need correctly - you should be able to use the same methodology as camera pointing. It is basic vector geometry to point something at something else (ie, get the angles between them).

There are loads of articles and tutorials on cameras and vectors. Check out the articles on this site or google it.


"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan
I want it to turn in the direction of the vector, not point directly toward it...
could you maybe show me some code?
Thanks
--m_nPostCount++
Make this ship have a state describing its rotational velocity, then just set that velocity to make it turn toward the point. On each frame draw/ time elapse rotate the ship according to the rotational velocity.

Pat
could i see some code please?
--m_nPostCount++
There is a thread here which deals with 3D enemy spaceship control. It discusses various techniques.

http://www.gamedev.net/community/forums/topic.asp?topic_id=180533
do unto others... and then run like hell.

This topic is closed to new replies.

Advertisement