Jump to content
  • Advertisement
Sign in to follow this  
MARS_999

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!