# Rotate from one point to face another at XYZ coordinate

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

## Recommended Posts

Not sure if the title works, but anyway....

I have my turret facing some direction, and I want to click on a object and have it point towards that object but it will need to rotate up on also not just XZ planes. So maybe I am making this harder than it needs to be, but any ideas would be great.

I am using CML and I have tried this

cml::matrix_rotation_aim_at(alignMatrix, cml::vector3f(0.0f, 0.0f, 0.0f), targetVector, cml:: axis_order_xyz);

and works but not correct. The turret will not keep its position and rotate accordingly. e.g. the turret will sometimes rotate on y 90 and then face the target(looks like its leaning on its side)

So I am out of ideas here....

##### Share on other sites
An image would probably go a long way here, I'm having a hard time exactly grasping what kind of rotation you desire.

I'm imagining a turret that could rotate 360 degrees and maybe point up/down, if that's your case it seems like the easiest thing would just be to totally decouple the up/down pitching from the XZ rotation.

So every step of the interpolation you would just do:

1) Rotate on the xz axis
2) Pitch up/down in the local space

I'd keep the direction and pitch as separate variables and then just reconstruct the final transformation matrix each frame from these values.

Is this the kind of situation you're going for?

##### Share on other sites

An image would probably go a long way here, I'm having a hard time exactly grasping what kind of rotation you desire.

I'm imagining a turret that could rotate 360 degrees and maybe point up/down, if that's your case it seems like the easiest thing would just be to totally decouple the up/down pitching from the XZ rotation.

So every step of the interpolation you would just do:

1) Rotate on the xz axis
2) Pitch up/down in the local space

I'd keep the direction and pitch as separate variables and then just reconstruct the final transformation matrix each frame from these values.

Is this the kind of situation you're going for?

Thanks for the reply, Yeah that may work, but I found I needed a reference vector for my axis, in this case (0,1,0) and now it works great!

Thanks

1. 1
Rutin
19
2. 2
3. 3
JoeJ
16
4. 4
5. 5

• 26
• 20
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001782
×