Jump to content
  • Advertisement
Sign in to follow this  
at0m

look at

This topic is 3064 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

Hi, I represent an entity using three vectors describing the position, the up and forward. I can't find the way to compute the new forward and up vector to make them point towards a position eg computing the correct rotation matrix (or is there another way?) ?

Share this post


Link to post
Share on other sites
Advertisement
If you are using Direct3D then you can use D3DX maths library to create a rotation matrix about an axis (D3DXMatrixRotationAxis()). To compute the axis to rotate around cross the look direction with the target direction and to work out the rotation angle take the arc cosine of the dot product of the two vectors.

You need to be careful if you don't want roll too, but try this and see if it gives you what you want.

Share this post


Link to post
Share on other sites
Yeah looks good!
I'm using glm, but I have everything I need for these calculations though. Thanks for this I'll try it out and keep you posted !

Share this post


Link to post
Share on other sites
Ok I finally found a simpler solution here it goes :

I compute the right vector with cross(fwd, target). Then I have :
fwd = target - pos and
up = cross (fwd, right)
and it works fine (+no angle manipulation) !
I hope it's still mathematically correct...

Share this post


Link to post
Share on other sites
There are an infinity of frame of reference which can be constructed starting from a point and a vector. Your problem isn't therefore well defined. Your method computes a possible frame of reference, but there are some issue.

I don't understand why you have chosen fwd and target to compute the right vector. I think they should be fwd and up. Target is a general point and it can also be zero. It can also be parallel to fwd. This isn't therefore a good choice in my opinion. On the other hand up is always perpendicular to fwd by construction.

right = cross(fwd, up); // now you have the initial reference
fwd = normalize(target - pos); // now you have a new unit forward vector
up = normalize(cross(right, fwd)); // in this way we obtains a new up vector

This method works iff (target - pos) isn't parallel to the current right vector. If this can't happen because for example the new target is always in a neighborhood of the old one, then you can just ignore this problem. If this isn't possible you have to choose a different vector.

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!