Jump to content
  • Advertisement
Sign in to follow this  

Quaternion Orbitting in C#

This topic is 5073 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

I know there's a bunch of posts here about Quaternions rotations, but I'm still a bit confused. I think there's two versions that I've read... #1 involves a camera rotating about an object and looking at it, and #2 involves a fixed camera with a target rotating about the fixed camera. I am desperately looking for code in C# that deals with #1. (Or can someone enlighten me a bit more..so that i can write it). I'm taking really small steps here... Here's what I have:
Vector3 camLocation = new Vector3(0,0,20);
Vector3 camTarget = new Vector3(5,10,1);
Vector3 camUp = new Vector3(0,1,0);
Vector3 mouseInitialV3;
Vector3 mouseCurrentV3;
this.m_Device.Transform.View = Matrix.LookAtRH(camLocation , camTarget , camUp);
My 'camera' starts at a fixed point in space (camLocation) How do I get camLocation to rotate in a particular direction in a particular angle amount about camTarget? I'm planning on using the mouse and having a "grab and drag" type of feel to how the rotations are done. Up to this point, I only know how to get a ray from the mouse coordinates. My idea is I get an initial Vector3 on MouseDown for mouseInitialV3 and update mouseCurrentV3 on MouseMove. Then I think I can get an angle between those two positions with camTarget as the vertex. With mouseInitialV3 and mouseCurrentV3, I have a direction. I use the negative direction to move the 'camera' in the right direction to get the effect I want. All this plays well in my brain. I don't know if there's something wrong with it. What do you think? I don't know how to implement the Quaternion rotations with this idea, can someone help? How do I update camUp so that the view doesn't spin?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!