#### Archived

This topic is now archived and is closed to further replies.

# moving where i'm facing?

This topic is 5938 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i have a class which includes vectors for the position, facing direction, up direction, and left direction. i want to use this class for an object (eg. a pyramid) i want to make the object move in the direction that it is facing and not just along the general world axis. i can rotate the object but cant move it along it''s ''own'' forward axis. can someone please help? im new at this and i hope i am explaining myself good enough

##### Share on other sites
Just multiply all of the vector values in the forward vector of the object times the amount you'd like it to move and add the resultant values to the x,y, and z of the position of the object currently in 3D space to get the new postition.

EDIT: That was assuming that you have normalized all of your axial vectors. If not, then rather than multiplying by the amount you'd like to move, multiply the values by the amount you'd like the object to move over the length of the vector and then add the current location.

--------------------
Matthew Calabrese
Realtime 3D Orchestra:
Programmer, Composer,
and 3D Artist/Animator
"I can see the music..."

[edited by - Matt Calabrese on March 19, 2002 9:32:18 PM]

##### Share on other sites
okay, i understand that part thanks, but....
i thought the rotating was a bit easier, and im having trouble understanding some things.
1) how do i rotate the direction of the facing vector?
2) once i have these values, how do i render my model so that it uses these values, ie faces in the right direction? (i am using openGL)

thanx

[edited by - leedude on March 20, 2002 5:54:42 AM]

##### Share on other sites
I think this is right.

angle is the angle the object has rotated.

x+= sin(angle);
z+= cos(angle);

[edited by - Nazrix on March 20, 2002 11:21:43 AM]

##### Share on other sites
Since you are using OpenGL, there is another easy way to do it. Let''s say you''re starting off facing down the negative z-axis, then define a vector v=[0,0,-1]. Transform this vector by your current modelviewmatrix (use glGet() ). The resulting vector should be your facing direction.

##### Share on other sites
Since you are using OpenGL, there is another easy way to do it. Let''s say you''re starting off facing down the negative z-axis, then define a vector v=[0,0,-1]. Transform this vector by your current modelviewmatrix (use glGet() ). The resulting vector should be your facing direction.

• 11
• 20
• 12
• 10
• 38
• ### Forum Statistics

• Total Topics
631401
• Total Posts
2999864
×