Vertice Rotation Calculation.

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Vertice Rotation Calculation.

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post by Falco Girgis »

Tvspelsfreak has mastered rotations. I just barely started Geometry, so I'm not so hot on my sine, cosine and tangent.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

The best scenerio would be a function like.

RotateVert(CenterOfRotation,Vert,angle)

I'll figure it out later.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Tvspelsfreak
Chaos Rift Junior
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:

Post 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:

Code: Select all

rad_angle = deg_angle*(PI/180);
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

GuuHAHHHAA YES! Woot! Now I don't have to think of that myself. Thanks Tvspelsfreak!
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post 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.
Tvspelsfreak
Chaos Rift Junior
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:

Post by Tvspelsfreak »

If anything, download the binary files and transfer through the coders cable.
It's not really worth wasting a disc. :mrgreen:
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post by Falco Girgis »

I used a well-worth it disc.
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post 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.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post 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.
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post by Falco Girgis »

Sorry to move this, but WTF is it doing in DC discussion? Shame on you. . .
User avatar
JS Lemming
Game Developer
Game Developer
Posts: 2383
Joined: Fri May 21, 2004 4:09 pm
Location: C:\CON\CON

Post by JS Lemming »

err... well, it was for the DC.... and we don't have a math forum. sorry, I really didn't notice.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
User avatar
Falco Girgis
Elysian Shadows Team
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:

Post 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!
Post Reply