Jump to content
  • Advertisement
Sign in to follow this  


This topic is 2594 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 found this code in one of my old project, I hope you can do something with it.

float MoveX = float(2*sin((CameraAngle-90)*PI/180));
float MoveZ = float(2*cos((CameraAngle-90)*PI/180));
CameraPosX -= MoveX;
CameraLookAtX -= MoveX;
CameraPosZ += MoveZ;
CameraLookAtZ += MoveZ;

CameraAngle is a number from 0 to 360. This is the number that you have to change when rotating.

Share this post

Link to post
Share on other sites

how to move the model in direction of rotation thanks. thanks a lot

A "direction of rotation" in the sense you're asking for doesn't exist. Instead, you want to rotate a direction vector (the one that defines the movement direction of the unrotated model) and use the result as direction of movement. Scale the rotated vector to consider the speed and elapsed time and add it to the position of the model's frame.

E.g. using the local z axis vector [ 0 0 1 0 ][sup]t[/sup] as standard movement direction of the model, the matrix vector product
R * [ 0 0 1 0 ][sup]t[/sup] == R[sub]z[/sub]
effectively extracts the 3rd column vector from the rotation matrix as rotated direction of movement. Its length is 1. Using s as speed and dt as the elapsed time give you
s * dt * R[sub]z[/sub]
as motion vector.

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!