Jump to content
  • Advertisement
Sign in to follow this  
TheM1ke

Create an object's movement vector

This topic is 3466 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 have a 3D object and I want the user to be able to move it. I have a nice thick line (calling it "the movement vector" for now) coming out of the object's center, aligned with the X Axis. While the user presses one of the 'x','y' or 'z' buttons I increase the vector's angle with the appropriate axis, and in 'glDisplayFunc' I call a glRotatef() for each axis. So far so good, I know the vector's angle with each one of the x-y-z axis. And now the question... What must I add to my object's transformation matrix so that it moves "on" that line?

Share this post


Link to post
Share on other sites
Advertisement
Simple normlaize the this vector and scale it by how much you want to move along this directional movement line. Then add it to your current position vector and you're done.

E.g

vDirVec.norm()
vDirVec.Scale (10)
vPosition.Add (vDirVec)

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!