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.

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?

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

• 14
• 12
• 9
• 12
• 37
• Forum Statistics

• Total Topics
631425
• Total Posts
3000011
×