|
-
Dec 8th, 2004, 10:35 AM
#1
Thread Starter
<?="Moderator"?>
C#: Rotating Mesh
Hey i am trying to move and rotate a Mesh. I am using DirectX 9 and C#.
I can move my Mesh backwards and forwards, along the Z axis. But the mesh rotates about a fixed point, the point from where the Mesh was first drawn.
heres the code i am using to draw the Mesh
Code:
device.Transform.World = Matrix.Scaling(Scale,Scale,Scale)
* Matrix.Translation(new Vector3(m_X,m_Y,m_Z))
* Matrix.RotationY( m_Rotation);
for(int i = 0; i < carMaterials.Length; i++)
{
device.Material = carMaterials[i];
device.SetTexture(0,carTextures[i]);
carMesh.DrawSubset(i);
}
I does rotate but about the wrong point? any ideas?
Thanks
Last edited by Electroman; Dec 8th, 2004 at 07:24 PM.
Reason: Added Language to title.
-
Dec 8th, 2004, 10:40 AM
#2
Re: Rotating Mesh
You have to rotate it in model coordinates. Then first translate it down to the axis you want to rotate around, then rotate it, then translate it back. Then change back to world coordinates.
ØØ
-
Dec 8th, 2004, 12:12 PM
#3
Thread Starter
<?="Moderator"?>
Re: Rotating Mesh
Cheers got it to work
One thing, do you have any links that explain which order to put the translations and rotations in. I search the SDK and it didn't come up with an explanation
Thanks
-
Dec 8th, 2004, 01:00 PM
#4
Re: Rotating Mesh
Sorry...I have no links...I have my notes tho'... ....and I am writing on some new tutorials that should come up in January. I have written about vectors, soon finished with matrices, then the next one will be about transformations.
Just remember that they are getting exectuted in the oposite order. And if you have transelated an object away from it's origo, then you have to translate it back to the axis you want to rotate it around, and then rotate, and then translate it back.
ØØ
-
Dec 8th, 2004, 01:50 PM
#5
Thread Starter
<?="Moderator"?>
Re: Rotating Mesh
kool didnt know that, im currently reading "KickStart Managed DirectX 9" at the moment, and havent got that far so maybe im just trying to go too far too quickly
Cheers
-
Dec 8th, 2004, 01:55 PM
#6
Re: Rotating Mesh
No problem. Just ask again if you have more questions. I have never tried Managed DX BTW....so hope you don't ask about that bit..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|