Jump to content
  • Advertisement
Sign in to follow this  
Staticsoul

C# Managed DirectX Transformations problems

This topic is 3618 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

Hi there, I'm having a problem implementing a moused control mesh viewer. This problem occurs for every mesh that don't have the his center on the (0,0,0). I've tried multiple combinations but the output is always the same. Here goes the code: device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue, 1.0f, 0); device.BeginScene(); float angleX = Geometry.DegreeToRadian(spinX); float angleY = Geometry.DegreeToRadian(spinY); //The problem device.Transform.World = Matrix.RotationX(angleX) * Matrix.RotationY(angleY) * // Matrix.Translation(-centerofMesh.X, -centerofMesh.Y, 5); device.Indices = ib; device.SetStreamSource(0, vb, 0); device.VertexFormat = CustomVertex.PositionNormalColored.Format; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, Indices.Length / 3); device.EndScene(); device.Present(); For meshes that don't have its center in (0,0,0) the rotation is wrong since this rotation always happens with that reference. So if someone know how to change the rotation center or some king of workaround for this problem please let me know. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
so you are saying that i have to do the translantion first? like this:

device.Transform.World = Matrix.Translation(-centerofMesh.X, -centerofMesh.Y, 5)*
Matrix.RotationX(angleX) *
Matrix.RotationY(angleY);



It doesn't work.
I've already tried to make first a world translation and then a rotation it doesn't worked either. I've also tried with MatrixStack with no success.

Share this post


Link to post
Share on other sites
Hi there!

I think the last post was a little confusing so I'm going to refrase my question.


I'm displaying a mesh trough a vertex buffer and index buffer and I think the problem discribed above happens because I'm not translating the mesh to the origin.

The problem now is how to do it in directx when is being used a vertex buffer and index buffer.


If someone got the answer please let me know.


Thanks in advance.

Share this post


Link to post
Share on other sites
As Mike said, rotations happen with respect to the origin. If you want to rotate a mesh about it's local-space coordinate (x,y,z), you must: translate(-x,-y,-z) * rotate(theta) * translate(x,y,z). It appears you missed that last step from your post above. Once you have done that, then you can translate the mesh again to place it in the world.

To figure out the amount you need to translate by, you need to know something about the mesh data -- in particular the offset between the mesh's model-space origin and the point at which you want to rotate the mesh around (the mesh's semantic "center"). This data is typically stored with the mesh somehow, either along side it in a different data file, or by using a dummy object in the mesh, or some kind of tag value specifying the offset, et cetera.

If you don't understand this, or it "doesn't work," you're going to need to provide significantly more information about what 'doesn't work' means. As it stands you aren't getting many replies because you have not clearly described the problem you are observing after application of Mike's suggested fix.

Share this post


Link to post
Share on other sites
Thank you very much

With that tip of putting a first translation before the code that I've presented , clearly does its work.
I've realized that it was a bit confusing the way that I presented the problem but it is hard to explain without using images.



But thanks again, it is working thanks to you.


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!