Rotation of a triangle
Hi,
I`ve got a problem with rotating a triangle. I want to rotated the triangle after a key has been pressed. In pseudocode:
if rightkeypressed then
rotate all points in the negative direction
end
if leftkeypressed the
rotate all points in the positive direction
end
the thing is that I can`t remember how it works with sin and cosine and all that stuff...could somebody please help me out and send me an e-mail at this address bwhw@magentammt.com
THANX
"I never let my schooling interfere with my education" Mark Twain
September 19, 2000 06:54 AM
2D. Below you can see the triangle and I want to make the 3 points (*) to move to the new coordinates and then I will plot the lines in between. So the trick is how to use the sine/cosine funtions work. If a press the rightkey the points should change position and then then traingle point into a new direction, sort of a ship in Asteroids??? Afterwardsi will add velocity and graity and stuff....i hope ;-)
*
/ \
/ \
/ \
*-------*
*
/ \
/ \
/ \
*-------*
September 19, 2000 06:55 AM
SORRY triangle got screwed....but I think you know what i mean...
Here you go:
ptsX and ptsY are arrays of 2D points.
centerX and centerY is the center of rotation.
------------
Cheers
Meduzza
Edited by - Meduzza on September 19, 2000 11:46:36 AM
void RotatePts( int numPts, int* ptsX, int* ptsY, int centerX, int centerY, float angle ){ int i; float x, y, s, c; s = sin( angle ); c = cos( angle ); for( i = 0; i < numPts; i++ ) { x = ptsX<i> - centerX; y = ptsY[i] - centerY; ptsX[i] = ( int )( ( x * c ) - ( y * s ) ) + centerX; ptsY[i] = ( int )( ( x * s ) + ( y * c ) ) + centerY; }}
ptsX and ptsY are arrays of 2D points.
centerX and centerY is the center of rotation.
------------
Cheers
Meduzza
Edited by - Meduzza on September 19, 2000 11:46:36 AM
Thanx Meduzza. Makes it a bit clearer now. Btw I`m programming in a new tool called ''Magenta''. Maybe you like it, you can check it out on http://www.magentammt.com. Leave me a message at the forum, if you like.
Greetz
FreeQ
"I never let my school interfere with my education"
Greetz
FreeQ
"I never let my school interfere with my education"
"I never let my schooling interfere with my education" Mark Twain
Thanx Meduzza. Makes it a bit clearer now. Btw I`m programming in a new tool called ''Magenta''. Maybe you like it, you can check it out on http://www.magentammt.com. Leave me a message at the forum, if you like.
Greetz
FreeQ
"I never let my school interfere with my education"
Greetz
FreeQ
"I never let my school interfere with my education"
"I never let my schooling interfere with my education" Mark Twain
Thanx Meduzza. Makes it a bit clearer now. Btw I`m programming in a new tool called ''Magenta''. Maybe you like it, you can check it out on http://www.magentammt.com. Leave me a message at the forum, if you like.
Greetz
FreeQ
"I never let my school interfere with my education"
Greetz
FreeQ
"I never let my school interfere with my education"
"I never let my schooling interfere with my education" Mark Twain
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement