Hey there. I'm currently working on something in c# XNA, and I have a problem I've been stuck on for ages. I have an object which can rotate 360 degrees and can move all over the screen (any x,y coordinates), in relation to an origin on the texture (the center of the texture) . The problem I have is that I need another few points which are 'stuck' to the texture, and will move only in relation to my main object. So if the texture rotates 90 degrees to the left, the other points will all rotate around the texture's origin to stay in the same relative place. I can explain better with a picture (attached). Any help here would be appreciated.

Thanks for reading, and thanks in advance.

**0**

6 replies to this topic

Sponsor:

###
#2
Members - Reputation: **169**

Posted 17 January 2012 - 10:03 AM

Its easier than you think. When you rotate the triangle you actually rotate three points around the origin. Its the same with your "Fixed Point", just rotate it around the origin. Google for transformations, to be exact for 2d rotation. Its a simple matrix multiplication with your "Fixed Point".

the_visualist

the_visualist

###
#3
Members - Reputation: **116**

Posted 17 January 2012 - 10:59 AM

I can't seem to get my head round this. If I have a vector with the coordinates of the origin of triangle, a vector with the coordinates for the fixed point which are, say, (triangleOrigin.X + 20, triangleOrigin.Y + 20), and the angle of the triangle, what am I applying the matrix rotation to?

###
#6
Members - Reputation: **169**

Posted 17 January 2012 - 01:43 PM

Right so now I've got:

point1 = Vector2.Transform(point1, Matrix.CreateRotationZ(angle)); point1 += origin;

Where point1 is the fixed point, and the origin is the well, origin. But this doesn't appear to do anything.

What you need to do is rotate something about the triangles origin. The something is your FixedPoint in relation to the triangles Origin, which means:

Vector something = FixedPoint - Origin; (this is called translation by the way)

Rotate(something, angle);

Afterwards you need to translate it back to where it was to get the correct coordinates:

Vector newFixedPoint = something + origin

Here is the matrix that you need for the rotation - to make sure that you are actually using the correct one:

the_visualist

###
#7
Members - Reputation: **104**

Posted 20 January 2012 - 06:50 AM

Don't forget to make sure that your angle is stored as the correct type (radians vs degrees). I know I've made many mistakes where I assumed a library uses one, but really uses the other. I believe C#'s Math.cos(double) and Math.sin(double) use radians. If so, you can use MathHelper.ToRadians(double) I believe is the name of the function.