Jump to content
  • Advertisement
Sign in to follow this  
rockmover12

OpenGL Matrix SetTransforms (starting to hate managed directx)

This topic is 4933 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m using c# and DirectX 9 (or trying to). In the past I always wrote using C++ and OpenGL, but I’m now working with C# and it looks like OpenGL and C# don’t play very well together so I’m learning DirectX 9. I’ve been though all the tutorials I can find on the web, and have purchased Toms "Managed DirectX book" but I have not yet received it from Amazon. I’m struggling with generating matrix transformations and applying them to Meshes. Basically I just want to draw a bunch of sphere on the screen, and rotate them using the mouse (I'm familiar with quaternion). I have my mesh, and a transform. mesh = Mesh.Sphere(device,0.25f,15,15); Matrix sphereTxfm = Matrix.Translation(0f,10f,13f); And I just want to move it!!! device.SetTransform(World,sphereTxfm); mesh.DrawSubset(0); I think this is the way, but I can not find a single example showing the SetTransform in use with C#. "World" does not seem to be valid. In openGL, you could basically move an object, and then rest back to your original position and the move the next object, ect. Is there a GOOD example showing how to move meshes around individually, and then rotate the end result in the "world" system? The examples included in the SDK kit...well in my option suck to try and show a new user how to use directX. How can microsoft spend so much time focusing on "performance" and "ease of use" for "managed code" and then suck so bad when actually providing info on how to use this stuff? Very Frustrating....

Share this post


Link to post
Share on other sites
Advertisement
Ok "TransformType.World" was screwing me up.

So now Im using:

Matrix sphereTxfm1 = Matrix.Translation(0f,2f,0f);
Matrix sphereTxfm2 = Matrix.Translation(1f,0f,0f);
Matrix rotAngle = Matrix.RotationY(angle / (float)Math.PI);

Matrix sphereM1 = Matrix.Multiply(sphereTxfm1,rotAngle);
Matrix sphereM2 = Matrix.Multiply(sphereTxfm2,rotAngle);

And I render using:

mesh1.DrawSubset(0);

device.SetTransform(TransformType.World,sphereM1);
mesh1.DrawSubset(0);

device.SetTransform(TransformType.World,sphereM2);
mesh2.DrawSubset(0);

So I guess the "SetTransform" always starts with the identity matrix (Ie it is not accumulative). This seems much less intuitive then OpenGL to me, but I guess it is what it is...


I was also going to ask what genius came up with using a "Left" handed axis scheme? Positive rotations now rotate object is the opposite direction to a right hand system. Ok, yes, increase Z move objects away from the viewer, but come on. I have never in my life seen a mathematics book with a left handed coordinate system.... Again, I guess Microsoft just wants everyone to live in "there" world.

Sorry, just venting...I really do like C#, over C++, it’s so much nicer. But I must say I’m very disappointed in this DirectX stuff compared to the OpenGL stuff I was use to......



Share this post


Link to post
Share on other sites
Ok "TransformType.World" was screwing me up.

So now Im using:

Matrix sphereTxfm1 = Matrix.Translation(0f,2f,0f);
Matrix sphereTxfm2 = Matrix.Translation(1f,0f,0f);
Matrix rotAngle = Matrix.RotationY(angle / (float)Math.PI);

Matrix sphereM1 = Matrix.Multiply(sphereTxfm1,rotAngle);
Matrix sphereM2 = Matrix.Multiply(sphereTxfm2,rotAngle);

And I render using:

mesh1.DrawSubset(0);

device.SetTransform(TransformType.World,sphereM1);
mesh1.DrawSubset(0);

device.SetTransform(TransformType.World,sphereM2);
mesh2.DrawSubset(0);

So I guess the "SetTransform" always starts with the identity matrix (Ie it is not accumulative). This seems much less intuitive then OpenGL to me, but I guess it is what it is...


I was also going to ask what genius came up with using a "Left" handed axis scheme? Positive rotations now rotate object is the opposite direction to a right hand system. Ok, yes, increase Z move objects away from the viewer, but come on. I have never in my life seen a mathematics book with a left handed coordinate system.... Again, I guess Microsoft just wants everyone to live in "there" world.

Sorry, just venting...I really do like C#, over C++, it’s so much nicer. But I must say I’m very disappointed in this DirectX stuff compared to the OpenGL stuff I was use to......



Share this post


Link to post
Share on other sites
Guest Anonymous Poster
By altering your projection matrix you can easily get a right-handed coordinate system in D3D. In ordinary D3D, there's D3DXMatrixPerspectiveRH. I presume there's something similar in managed D3D..

Share this post


Link to post
Share on other sites
A couple of things.
You don't have to use SetTransform, the the device has a property Transform that has a bunch of properties for the various transforms. All symantic, but easier to read.

device.Transform.World = Matrix.Translation(0,0,5f);

this also makes it easier to accumulate transformations (ignoring the speed issue here):

device.Transform.World *= Matrix.Translation(0,0,5f);

For more flexable accumulation look at MatrixStack.

Be careful with your matrix multiplications, I believe that they are reversed from opengl.

DirectX: World * View * Projection
OpenGL : Projection * View * World

If you do use the right handed projection you also have to do some other stuff: use the RH view methods, reverse the culling direction, and you may have to modify your cube maps.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!