3D Math

Started by
3 comments, last by Veslefrikk 16 years, 3 months ago
I have objects in my 3d scene(ships) that I want to turn towards eachother, Im not sure how to do this. I use matrixes for my rotations. What I need is to have a vector interpolating its rotation so its faces a given point in 3d space. Help is much appriciated :) Stefan
Advertisement
Quote:Original post by Veslefrikk
I have objects in my 3d scene(ships) that I want to turn towards eachother, Im not sure how to do this. I use matrixes for my rotations. Help is much appriciated :)

Stefan
There are a number of ways to do this, ranging from potential functions to simple vector math.

A few questions:

1. How is the motion of your ships handled? Is it more or less 'ad hoc', or are you using a physics engine of some sort?

2. How are your object orientations represented? You mentioned matrices, but are the rotation operations applied directly to the rotation matrix? Or is there an intermediate representation, such as Euler angles?

3. Is the motion of the ships 'free' (6DOF), or is it constrained in some way?
Motions of the ships are very basic atm, I will write some simple physics later on.
I do my rotation by adding the new rotation to a stored matrix and then keep that matrix orthoganised.
And there is no constrains on the ships whatsoever in terms of movement or rotation.

Thanks for quick response.


Stefan
Quote:Original post by Veslefrikk
Motions of the ships are very basic atm, I will write some simple physics later on.
I do my rotation by adding the new rotation to a stored matrix and then keep that matrix orthoganised.
And there is no constrains on the ships whatsoever in terms of movement or rotation.
Here is one way you could proceed (this is the simplest method I can think of at the moment):

1. Transform the target position into the local space of the ship (by multiplying the target position with the ship's inverse model matrix).

2. Check the components of the transformed point corresponding to the ship's local-space side and up vector to see if the target is to the left or right, and whether it is 'up' or 'down'.

3. Apply local pitch and yaw as appropriate.

This may need fine tuning, but the basic idea should be sound.

Let me know if you have any questions.
I was ripping the hairs from my socket because I thought I had it but it just wouldnt work properly, and then I saw your reply. Inverted the matrix and now it works like a charm. :) ty

Stefan

This topic is closed to new replies.

Advertisement