Jump to content
  • Advertisement
Sign in to follow this  
bigbrother2000

Maths required to point one object to another?

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

I have one object which i constantly want to point at another so when it moves it moves towards the player. However i do not have a point object at function, only position and rotate. Is there a way to point an object at a another point by changing its rotation values. BOOL cObject::Move(float XPos, float YPos, float ZPos) { return m_Pos.Move(XPos, YPos, ZPos); } BOOL cObject::MoveRel(float XAdd, float YAdd, float ZAdd) { return m_Pos.MoveRel(XAdd, YAdd, ZAdd); } BOOL cObject::Rotate(float XRot, float YRot, float ZRot) { return m_Pos.Rotate(XRot, YRot, ZRot); } BOOL cObject::RotateRel(float XAdd, float YAdd, float ZAdd) { return m_Pos.RotateRel(XAdd, YAdd, ZAdd); }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Whats really going to fry your noodle is that there are multiple solutions.. I can point this pencil at you, for example.. but I can also spin it while still keep it pointed at you.

Assuming that "up" is always in a general upward fashion after you perform your rotations.. then the idea is to first pitch your object towards where its supposed to face and then yaw your object towards where its supposed to face... In this case, atan2() is your first.

Share this post


Link to post
Share on other sites
Quote:
Is there a way to point an object at a another point by changing its rotation values.
Sure, there are a few ways. I do have a question though - what does m_Pos.Rotate() do? I'm guessing m_Pos is the position of your object, and usually you wouldn't 'rotate' an object's position. Rotation would be applied to its orientation, as represented by a matrix, quaternion, etc. So I'm not sure what your functions are actually doing.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!