Results 1 to 6 of 6

Thread: C#: Rotating Mesh

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    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.

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.


    ØØ

  3. #3

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    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

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.


    ØØ

  5. #5

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    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

  6. #6
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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
  •  



Click Here to Expand Forum to Full Width