Sign in to follow this  


Recommended Posts

[size="2"]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.[/size]

Share this post

Link to post
Share on other sites
[quote name='HappyRocky' timestamp='1305568267' post='4811547']
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
[b]R[/b] * [ 0 0 1 0 ][sup]t[/sup] == [b]R[/b][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 * [b]R[/b][sub]z[/sub]
as motion vector.

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