# Orientation

## Recommended Posts

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

##### Share on other sites
Texus    248
[size="2"]I found this code in one of my old project, I hope you can do something with it.

[code]
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;
[/code]

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

##### Share on other sites
haegarr    7372
[quote name='HappyRocky' timestamp='1305568267' post='4811547']
how to move the model in direction of rotation thanks. thanks a lot
[/quote]
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.