Jump to content
  • Advertisement
Sign in to follow this  
SeeMe

Math little problem

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

Hello, I'm reviewing my math for the moment, but I'm stuck on this simple problem. The data at my disposal : My location inside a vector called Location. My direction inside a vector called Direction. The distance of the move called Distance How can I compute my new location based on those data : NewLocation = Location where I apply a move of Distance unit in the direction Direction. I know it's quite easy, but I really don't know how to do it :( Tx you for your help !

Share this post


Link to post
Share on other sites
Advertisement
If you don't want to overload the + and * operators, it would be
for(int i=0;i<2;i++) NewLocation = Location + Distance * Direction;

Share this post


Link to post
Share on other sites
Tx you for your help !

I suppose that my Direction vector must by normalized for working ?

Share this post


Link to post
Share on other sites
Yes... assuming your vectors use floats. If they are ints, a normalized direction vector won't work too good.

Share this post


Link to post
Share on other sites
If you're going to just multiply the distance by the Direction vector, yes, it must be normalized.

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!