Rotation!!!!

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Warmtoe
DC Developer
DC Developer
Posts: 453
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu May 16, 2002 8:29 am
Location: ice88's house
Has thanked: 0
Been thanked: 0
Contact:

Rotation!!!!

Post by Warmtoe »

God. I am useless at geometry.

I'm trying to work out how to rotate my targets on bloop.

The theory is simple, I take the texture area for my graphic, and when rendering it, rotate all of the vertex points around the centre of the vertices by my angle.

Is the theory sound? If I give the PVR points that represent a 'diamond' rather than a 'square' it should plot them correctly, right?

OK, so based on that, how should I do the rotation? I'm having a real nightmare... a code sample would help ... and it seems so simple.... help?!

=W=
reaper2k2
DC Developer
DC Developer
Posts: 2648
Joined: Sun Mar 24, 2002 7:48 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by reaper2k2 »

I can do it on SDL dont think that will help thou i can make any sprite rotate with a routine i wrote but its heavly SDL dependent
http://homebrew.dcemulation.com/dcgames/ *homebrew webbrowser games *

http://r2k2gate.topcities.com *dev site and my releases*
Image
Im' a Commodorian are you?
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

You just want code to rotate a vertex, yes? So that, given the offset in X and Y coordinates relative to the center of rotation and the angle of rotation, you can work out the rotated X and Y coordinates.

Basically you can use matrices to do it, and then turn those into a simple(ish) formula for rotation.

Taking the initial X and Y coordinates to be X1 and Y1, the angle to be A and the final X and Y coordinates to be X2 and Y2, we get the following matrix equation

Code: Select all

[ cos(A)  sin(A) ][X1] = [X2]
[-sin(A)  cos(A) ][Y1] = [Y2]
Converting this to two standard equations, we get this:

Code: Select all

X2 = X1 * cos(A) + Y1 * sin(A)
Y2 = X1 * -sin(A) + Y1 * cos(A)
And some code that uses it might look like this

Code: Select all

void RotatePoints(float inX, float inY, float ang, float *outX, float *outY)
{
    *outX = inX * cos(ang) + inY * sin(ang);
    *outY = inY * cos(ang) - inX * sin(ang);
}

void whatever()
{
    float rx, ry;
    RotatePoints(10.0, 5.0, 1.3, &rx, &ry);
}
That implementation's crap, but you should get the idea.
Warmtoe
DC Developer
DC Developer
Posts: 453
Joined: Thu May 16, 2002 8:29 am
Location: ice88's house
Has thanked: 0
Been thanked: 0
Contact:

Post by Warmtoe »

OK - that sounds like it ought to work.... I'll have another go!!!!

Thanks!

-W-
Post Reply