Jump to content
  • Advertisement
Sign in to follow this  
ktuluorion

figuring out the direction that something is facing based on vector

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!