Rotating a model using gestures

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

Recommended Posts

Hi,

I have a 3d model rendered on the screen. I zoom in/out it using the pinch gesture (that gives me the vectors position1, position2, and the values delta1 and delta2).

Next step would be to calculate the rotation for the model. How could I get so considering the input information I can deal with?

Thanks!

Share on other sites
Hi!

I think there are multiple ways. Which one to choose depends on how you would like the rotation to behave.
I could imagine that the axis to rotate around is perpendicular to the view direction and the swipe direction.
The following code does exactly this:

 // Compute the swipe direction (The forward, up and right vectors are given in world space. They are the first three columns of the view matrix.) // mouseDeltaX and ...Y are the change of the finger (or mouse) position (normalized through division by the viewport resolution.) Vector3 swipeDir = viewMatrix.Right * mouseDeltaX + viewMatrix.Up * mouseDeltaY; // The rotation axis is perpendicular to the swipe direction and the forward axis of the camera. Vector3 rotationAxis = Vector3.Cross(swipeDir, viewMatrix.Forward); // Transform the rotation axis from world space to object space. rotationAxis = Vector3.Transform(rotationAxis, Matrix.Invert(worldMatrix)); // Compute rotation quaternion (the angle is some constant) that spins the object a little bit further. Quaterion rotation = Quaternion.CreateFromAxisAngle(rotationAxis, angle); The actual rotation of the model is then updated by: model.Rotation *= Quaternion.Normalize( rotation ); 

I hope this helps you a little.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• Forum Statistics

• Total Topics
633319
• Total Posts
3011349
• Who's Online (See full list)

There are no registered users currently online

×