#17925 - ProblemBaby - Wed Mar 17, 2004 4:58 pm
Hi is it possible to rotate a sprite around an another point then the centrum?
then how???
#17926 - poslundc - Wed Mar 17, 2004 5:16 pm
If by centrum you mean the major part of the vertebrae in your spinal column, then the answer is no.
If you mean the centre of a sprite, then just make variables representing the distance from the centre of the sprite to your new origin, then transform those with the same rotation matrix you use for the sprite. Then add the results to your sprite's coordinates.
Dan.
#17928 - ProblemBaby - Wed Mar 17, 2004 5:21 pm
yes, I mean the centre of the sprite.
I don't understand, can you explain with some code?
#17929 - Gopher - Wed Mar 17, 2004 5:34 pm
[ edited : fixed mistake caught by RaBBi ]
The rotation data is a 2x2 matrix, as so
[ A B ]
[ C D ]
any position in a 2d space (like the screen) can be represented by a vector ( x y )
you can multiply the two together like this...
[ A B ] [ x ] = Ax+By
[ C D ] [ y ] = Cx+Dy
so the code for that will look something like this...
rotx = OAMRotData[i].pa * x + OAMRotData[i].pb * y;
roty = OAMRotData[i].pc * x + OAMRotData[i].pd * y;
x and y are the position of your object relative to the the center you want to rotate around. You get this by subtracting the center point from the object's position.
x = ObjectX - CenterX;
y = ObjectY - CenterY;
rotx and roty are that relative position rotated by the matrix around center. To get the final screen position you add them back to the center
finalx =rotx + centerx;
finaly = roty + centery;
Hope that helps.
_________________
"Only two things are infinite: the universe, and human stupidity. The first is debatable." -Albert Einstein
Last edited by Gopher on Wed Mar 17, 2004 6:44 pm; edited 1 time in total
#17932 - RaBBi - Wed Mar 17, 2004 6:28 pm
Shouldn't be :
finalx =rotx + centerx;
finaly = roty + centery;
instead of :
finalx =x + centerx;
finaly = y + centery;
?
_________________
Sorry for my poor english, but it would be worst for you to understand me if I speak in my native language, French ^^
#17933 - Gopher - Wed Mar 17, 2004 6:43 pm
You're right, Rabbi, that was a mistake. I corrected the original post.
_________________
"Only two things are infinite: the universe, and human stupidity. The first is debatable." -Albert Einstein
#17946 - ProblemBaby - Wed Mar 17, 2004 9:58 pm
I can't get it to work=(
it just jumps around the screen!
here is my code:
Code: |
RotData[0].pa = ((1 << 8) * COS[a]) >> 8;
RotData[0].pb = ((1 << 8) * SIN[a]) >> 8;
RotData[0].pc = ((1 << 8) * -SIN[a]) >> 8;
RotData[0].pd = ((1 << 8) * COS[a]) >> 8;
xRel = -16; // is it relative to the center of the sprite
yRel = 0; // or x1, y1 of the sprite??
xRot = ((RotData[0].pa * xRel) >> 8) + ((RotData[0].pb * yRel) >> 8);
yRot = ((RotData[0].pc * xRel) >> 8) + ((RotData[0].pd * yRel) >> 8);
x = x + xRot; // x and y are fixed
y = y + yRot;
// then i shift back x and y and copy it to my sprite attribute
|
#17950 - Gopher - Wed Mar 17, 2004 10:29 pm
firstly, by using a constant (-16,0) for your relative position, you're saying that the rotation center moves with the sprite, which would cause very erratic behavior. You have to subtract the center position you want to rotate around from the sprite's current position to get the relative position.
Second, you're adding the new position to the old position instead of just setting the actual position to the new one. Finally, you don't re-add the center back into the sprite's position afterwords. You say you shift x and y back, so maybe that's what you meant.
[/url]
_________________
"Only two things are infinite: the universe, and human stupidity. The first is debatable." -Albert Einstein
#17952 - ProblemBaby - Wed Mar 17, 2004 10:38 pm
i think it works!
thank you very much!