Page 1 of 1
Vertice Rotation Calculation.
Posted: Tue Jan 11, 2005 5:20 pm
by JS Lemming
Does anyone happen to know the formulas for calculating the 4 vertices coordinates after a given rotation? If not, I guess I can try to make my own real fast.
Posted: Tue Jan 11, 2005 5:42 pm
by Falco Girgis
Tvspelsfreak has mastered rotations. I just barely started Geometry, so I'm not so hot on my sine, cosine and tangent.
Posted: Wed Jan 12, 2005 7:39 am
by JS Lemming
The best scenerio would be a function like.
RotateVert(CenterOfRotation,Vert,angle)
I'll figure it out later.
Posted: Wed Jan 12, 2005 3:26 pm
by Tvspelsfreak
Basically something like this:
Code: Select all
V1 __________________ V2
| |
| |
| |
| |
| Origin |
| |
| |
| |
| |
V3 ------------------ V4
That's supposed to be a (width)x(height) sprite positioned at the origin.
To calculate the 4 vertices positions at any angle of rotation you do:
Code: Select all
tempx = vertex.x - origin.x;
tempy = vertex.y - origin.y;
x = origin.x+(tempx*cos(angle)-tempy*sin(angle));
y = origin.y+(tempx*sin(angle)+tempy*cos(angle));
Where (x,y) is the new position after rotating.
So as an example, here's the code to rotate the sprite above:
Code: Select all
tempx = origin.x - width/2 - origin.x;
tempy = origin.y - height/2 - origin.y;
v1.x = origin.x+(tempx*cos(angle)-tempy*sin(angle));
v1.y = origin.y+(tempx*sin(angle)+tempy*cos(angle));
tempx = origin.x + width/2 - origin.x;
tempy = origin.y - height/2 - origin.y;
v2.x = origin.x+(tempx*cos(angle)-tempy*sin(angle));
v2.y = origin.y+(tempx*sin(angle)+tempy*cos(angle));
tempx = origin.x - width/2 - origin.x;
tempy = origin.y + height/2 - origin.y;
v3.x = origin.x+(tempx*cos(angle)-tempy*sin(angle));
v3.y = origin.y+(tempx*sin(angle)+tempy*cos(angle));
tempx = origin.x + width/2 - origin.x;
tempy = origin.y + height/2 - origin.y;
v4.x = origin.x+(tempx*cos(angle)-tempy*sin(angle));
v4.y = origin.y+(tempx*sin(angle)+tempy*cos(angle));
All angles have to be in radians, to convert from degrees to radians do:
Posted: Wed Jan 12, 2005 4:17 pm
by JS Lemming
GuuHAHHHAA YES! Woot! Now I don't have to think of that myself. Thanks Tvspelsfreak!
Posted: Wed Jan 12, 2005 4:38 pm
by Falco Girgis
That's what made the most awesome LEVEL 1 thing in Melchior, which is Tvspelsfreak's first released homebrew for the DC.
I think you at least owe it a download and play. It's a great game. Tvspelsfreak is t3h 1337.
Posted: Wed Jan 12, 2005 5:05 pm
by Tvspelsfreak
If anything, download the binary files and transfer through the coders cable.
It's not really worth wasting a disc.
Posted: Wed Jan 12, 2005 6:49 pm
by Falco Girgis
I used a well-worth it disc.
Posted: Thu Jan 13, 2005 7:27 am
by JS Lemming
You know, I never even thought to think to see if Tvspelsfreak had made a homebrew.... I'm not sure why. Anyway, where can I obtain this and about how big was it (in megab)? Do you have your own site or something? Sounds koo.
Posted: Thu Jan 13, 2005 8:50 am
by Falco Girgis
http://dcemulation.com should have the binary files as far as I know.
Tvspelsfreak sent me the the super secret 1337 .ELF file because I'm so cool.
I mean, you could just send the .bin to your DC via coder's cable, but it won't be as fast as the .ELF.
Posted: Sat Jan 15, 2005 11:55 pm
by Falco Girgis
Sorry to move this, but WTF is it doing in DC discussion? Shame on you. . .
Posted: Sun Jan 16, 2005 8:48 pm
by JS Lemming
err... well, it was for the DC.... and we don't have a math forum. sorry, I really didn't notice.
Posted: Sun Jan 16, 2005 10:45 pm
by Falco Girgis
I don't know, there really is a hazy line between DC Dev and Programming discussion.
I like to classify programming things that are hardwares specific as "DC Dev" material, and things that are general programming as "Programming Discussion"
BTW, I rotated my first sprite fool! A rotating Nullset... w00t!