# Rotate 3D Object On the Spot

• ### Question

• Hi all,
I would like to know how I can rotate a 3d object on its own axis. It is a 3d Cube. Everytime I try - it keeps rotating about a point outside itself - in a circle. I tried setting the center of the rotation but it doesnt work.

Thanks

Q
Monday, February 9, 2009 10:53 PM

### All replies

• Proposed as answer by Tuesday, February 10, 2009 2:14 AM
Tuesday, February 10, 2009 2:13 AM
• Thanks for the links. Unfortunately it doesnt contain the solution I was looking for. Is there some sort of algorithm for calculating the centre?
Tuesday, February 10, 2009 2:04 PM
• OK. Before the following code is executed I transform the 3d model in the viewport

 Dim myNumx As Integer = tx.Text Dim myNumy As Integer = ty.Text Dim myNumz As Integer = tz.Text Dim myNumAngel As Integer = ta.Text Dim XV As New Vector3D(myNumx, myNumy, myNumz) Dim AAR As New AxisAngleRotation3D(XV, myNumAngel) Dim myRotateTransformTry As New RotateTransform3D(AAR) myRotateTransformTry.CenterX = V.Children.Item(0).Transform.Value.OffsetX myRotateTransformTry.CenterY = V.Children.Item(0).Transform.Value.OffsetY myRotateTransformTry.CenterZ = V.Children.Item(0).Transform.Value.OffsetZ V.Children.Item(0).Transform = myRotateTransformTry

Tuesday, February 10, 2009 2:11 PM
• As you can see, I tried setting the center of the rotation to the new coordinates of the 3d object after its transformed.
Tuesday, February 10, 2009 2:14 PM
• Hi,

http://www.codeproject.com/kb/wpf/colorcube.aspx

here i have bind x axis,y axis and z axis of cube to the slider.

Just above binding I have given all offset to zero. so that here in my example only x axis used to rotate in center, but not other 2 axis.



now you just update OffsetY="-0.5"



so that all x,y and z axis will rotate in center.

I hope this will help you :)