
How to get direction vector of a unit sitting on a triangle?
Basically I have a unit and its position in vector form (x,y,z).
I also have the terrain triangle the unit is sitting on in (x,y,z) form and that triangle''s normal also (x,y,z).
I can already get the height of the unit, what I need is his direction vector according to the triangle he''s on so that if hes on an inclined plane the vehicule will also be inclined.
Thanks in advance

Well you already know which way is up for the unit as that is the triangle's normal. Now I suppose you want to find which way is forward. Obviously this vector is at right angles to the triangle. I'll assume you already have a vector for the direction the unit is facing, before being put on the terrain, or when it was on a different triangle.
Now as far as I can see there are two ways of progressing from here. Either keep the horizontal coords and work out a new vertical. This may look a little strange in some situations. Just keep the original x and y, dot the up and forward, then find z so that the dot is 0. Then normalize if necessary.
The other is to minimize the angle at which it has to change, this is ofcourse the angle the up direction has just changed to, so you need to apply the same change the up direction just underwent to the forward vector. You can find the plane it's rotated in by crossing the up vectors(previous up and normal). Now cross this vector with the up vector to get the forward vector. Ofcourse be careful to make sure you don't end up rotating your unit through 180 degrees by accident.
As you've probably guessed I've never done this and have worked it out as I was writing. The second one is the one to go with.
[edited by - higherspeed on April 26, 2003 7:02:20 PM]
Now as far as I can see there are two ways of progressing from here. Either keep the horizontal coords and work out a new vertical. This may look a little strange in some situations. Just keep the original x and y, dot the up and forward, then find z so that the dot is 0. Then normalize if necessary.
The other is to minimize the angle at which it has to change, this is ofcourse the angle the up direction has just changed to, so you need to apply the same change the up direction just underwent to the forward vector. You can find the plane it's rotated in by crossing the up vectors(previous up and normal). Now cross this vector with the up vector to get the forward vector. Ofcourse be careful to make sure you don't end up rotating your unit through 180 degrees by accident.
As you've probably guessed I've never done this and have worked it out as I was writing. The second one is the one to go with.
[edited by - higherspeed on April 26, 2003 7:02:20 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement