# Setting Rotation...

Fayetteville, NC, USA
Alright, I am trying to set rotation in an engine I am working with. Angles go from 0 to 65535. I will supply the X, Y, and Z coordinates for the player's location, and the X, Y, and Z coordinates of where the player should face. How would I do this? I don't need it to roll slowly to the location, because I have that programmed already, and in some cut-scenes I may need it to 'snap' to a specific character. Anybody have the math formula for this?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

• : Alright, I am trying to set rotation in an engine I am working with. Angles go from 0 to 65535. I will supply the X, Y, and Z coordinates for the player's location, and the X, Y, and Z coordinates of where the player should face. How would I do this? I don't need it to roll slowly to the location, because I have that programmed already, and in some cut-scenes I may need it to 'snap' to a specific character. Anybody have the math formula for this?
:
: -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
:

Do you want to know how to orient the player in a particular direction ? Or how to pass the rotation into the engine ?

• Fayetteville, NC, USA
I want to know how to get what vector I should make the player look at. Like if the player is facing north. I want to lock the camera to a torch on the wall. How would I figure out how much to add to the player's yaw? Straight right is 16384 unless I am mistaken. Now what if he was facing south (32768) and wanted him to face right (east)? I can do that in my head, but how would I figure it out?

-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

• Its really simple,

1. Get the direction vector
2. Build the right vector - project it onto a plane - (x-z plane if its z axis is the up vector)
3. Get the up vector by taking cross product of the direction and right vector
4. Build a matrix like this :
target.x, right.x, up.x
target.y, right.y, up.y
target.z, right.z, up.z

5. Take the transpose of this matrix.
6. Multiply it by current matrix of model to rotate it to face the target.

: I want to know how to get what vector I should make the player look at. Like if the player is facing north. I want to lock the camera to a torch on the wall. How would I figure out how much to add to the player's yaw? Straight right is 16384 unless I am mistaken. Now what if he was facing south (32768) and wanted him to face right (east)? I can do that in my head, but how would I figure it out?
:
: -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]
:
: