Vertice Rotation Calculation.
Moderator: Coders of Rage
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
Vertice Rotation Calculation.
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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
-
- Chaos Rift Junior
- Posts: 272
- Joined: Wed Sep 29, 2004 5:53 pm
- Favorite Gaming Platforms: NES, SNES
- Programming Language of Choice: C/C++
- Location: Umeå, Sweden
- Contact:
Basically something like this:
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:
Where (x,y) is the new position after rotating.
So as an example, here's the code to rotate the sprite above:
All angles have to be in radians, to convert from degrees to radians do:
Code: Select all
V1 __________________ V2
| |
| |
| |
| |
| Origin |
| |
| |
| |
| |
V3 ------------------ V4
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));
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));
Code: Select all
rad_angle = deg_angle*(PI/180);
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
-
- Chaos Rift Junior
- Posts: 272
- Joined: Wed Sep 29, 2004 5:53 pm
- Favorite Gaming Platforms: NES, SNES
- Programming Language of Choice: C/C++
- Location: Umeå, Sweden
- Contact:
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
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.
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.
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
- JS Lemming
- Game Developer
- Posts: 2383
- Joined: Fri May 21, 2004 4:09 pm
- Location: C:\CON\CON
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
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!
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!