# figuring out the direction that something is facing based on vector

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

## Recommended Posts

OK, so i'm working on an OGL program where there is a simulated aquarium. There are 2 fish. One moves randomly about, the other moves directly toward the first. The problem that I am encountering is that i can't figure out mathematically how to figure out what angles to rotate the fish to make them face in the direction they are moving in. I have a vector for each that denotes the location, and another for each that is a displacement vector (i.e. the fish is moving a units on the x axis, b units on the y axis, and c units on the z axis). Thanks for any help!

##### Share on other sites
You can get a displacement vector between the two fish in fish2 local space by multiplying the (world-space) displacement (f1-f2) by fish2's orientation matrix. That vector then 'is' a representation of the angles by which you need to turn – you can calculate YPR angles or an axis-angle pair from it or create a transformation matrix that will rotate fish2's current velocity vector to it.

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×