Sign in to follow this  

[C# MDX] Texture Rotation Help

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

Hey Everyone, I know that this subject has alot of available resources already available, but none of them seem to be able to solve my problem. I know that an excellent sprite class already exists, but for the purpose of my own education I prefer to work from scratch rather than using all of its wonderfull features. So that covers the "Use the Sprite class to do it" answer. This is what I am attempting to do : Rotate a texture about its Z axis using its center as the rotation center, and the textures dimensions must stay constant. I have no problem rotating the texture, its the constant dimensions that are the problem. My device matrices are set up as follows : device.Transform.Projection = Matrix.OrthoLH(1, 1, 0, 1); device.Transform.World = Matrix.Identity; My texture is of type CustomVertex.PositionedColoredTextured, and I am using primitive type TriangleList to render them. I have set up my vertex buffer correctly and can render 2 primitives that form a square ect ect, so my render method is not the problem as far as I know. This is how I am rotating the world before I render the texture. Matrix transform = Matrix.Translation(sclX, sclY, 0f) * Matrix.Translation(-sclX, -sclY, 0f) * Matrix.RotationZ(angle) * Matrix.Scaling(1, 1, 1) * Matrix.Translation(sclX, sclY, 0f); device.Transform.World = transform; Where sclX and sclY represent the world coordinates of the texture, and they are calculated as follows. sclX = WorldXLoc / device.ViewPort.Width; sclY = WorldYLoc / device.ViewPort.Height; By doing this, the texture rotates about its center correctly, except it increases in length/width at different angles of rotation. I am wondering how I might solve this problem, as I have fiddled and fiddled but to no avail! I hope I provided enough information to allow the more experienced people to help me, but if I have not please let me know what information is lacking and I will gladly provide it. This is my first post on Gamdev.net, and as I am not exactly experienced with MDX I am unsure what information is relevant.. Kind Regards Celtic

Share this post


Link to post
Share on other sites
Umm,

Did I post this in the wrong forum? If I have, please let me know and I will move it to the appropriate place.

If this is in the correct forum, then I would really appreciate a poke in the right direction with this one because I am stumped!

Kind Regards

Celtic

Share this post


Link to post
Share on other sites
Hi Celtic.

First off, your terminology is a little confusing. From what I gather, you have a texture-mapped quad, which is being rotated in world space. Your problem lies in the rotation of the quad wrt the world, rather than the texture wrt the quad. So perhaps 'Quad Rotation Help' would be a better name for the thread. No matter.

In your code, that scaling matrix is the identity matrix & in only burning up cycles. Also the first two matrices code are mutually-inverse & so they have no effect:
Quote:
Matrix transform =
Matrix.Translation(sclX, sclY, 0f)
* Matrix.Translation(-sclX, -sclY, 0f) * Matrix.RotationZ(angle)
* Matrix.Scaling(1, 1, 1)
* Matrix.Translation(sclX, sclY, 0f);

It looks like it's suffering from some serious debug artifacting. I take it (WorldLocX, WorldLocY) is the point about which you want to rotate. The overall transform should look like:
Matrix transform = Matrix.Translation(-sclX, -sclY, 0f) *
Matrix.RotationZ(angle) *
Matrix.Translation(sclX, sclY, 0f);
This is a straightforward conjugate-translation operation. The first matrix translates the centre of rotation to the origin, the rotation does what it should, and the last translation restores the origin.

This still doesn't account for the scaling issue you are witnessing, though. At least not the way I understand it. One thing at a time though: replace your rotation code with this and tell us what happens next. It should be easier to diagnose that way.

Regards
Admiral

Share this post


Link to post
Share on other sites

This topic is 4069 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.

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