# Rotating a model using gestures

This topic is 2492 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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634096
• Total Posts
3015493
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!