Sign in to follow this  
TheM1ke

Create an object's movement vector

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this