Sign in to follow this  

C# MDX :: Rotating a Triangle on User Input?

Recommended Posts

Hey, everyone. I've been learning more about Managed DX using C#. Now, I have set up the world, view, and projection matrices. And I drew a simple colored triangle. Everything works well. Now, I would like to get user input from arrow keys, and rotate the triangle. I have 3 float values (x, y, z of course =P). I use the "Form1_OnKeyDown" function to get user input for arrow keys, and update x, y, and z. Now, how do I rotate the triangle? I know I have to use matrices, but how/what do I call in order to rotate the triangle/scene by x, y, and z? Thanks in advance, Matt U. BTW, this is VS .NET 2005. =)

Share this post

Link to post
Share on other sites
Well, if you want to just rotate the triangle around X, Y, or Z axis, then you just need to write:

device.Transform.World = Matrix.Rotation*(angle);

Where the * represents any of the three axis (X, Y, or Z) and the angle is a float value specifying how much you want to rotate.

If you want to rotate around an axis that's not X, Y or Z, you'll be using:

device.Transform.World = Matrix.RotationAxis(axisVector, angle);

Where axisVector is a Vector3 object that specifies the axis of rotation and angle is the same as before.

Hope that helps get you started.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this