![]() |
|
Rotating polygon coordinates (linear algebra) |
Johan Peitz
Member #9
April 2000
![]() |
Hello Allegators! I'm in the midst of porting Olivier Renaults 2D polygon collision thingy to use Allegro instead of OpenGL so that I can use it in my game engine. I've got mostly everything working but since my linear algebra is shoddy at best I've naturally run into some problems and am currently stuck at some rotation issues. Actually, the logic part runs as it should, it is the drawing that I'm stumped at. Since the original code uses OpenGL it simply applies some rotation matrix before drawing each object making it quick, elegant and easy. This is something that I'm pretty sure isn't as easily done in Allegro so I rush to the source of all knowledge. Here's the original polygon drawing code (some non relevant stuff removed):
I can easily draw the polygon at the right place using the following code: for(int i = 0; i < iNumVertices - 1; i ++) { line(p_buffer, (int)(xOffset.x + axVertices<i>.x), (int)(xOffset.y + axVertices<i>.y), (int)(xOffset.x + axVertices[i+1].x), (int)(xOffset.y + axVertices[i+1].y), ARGBline); } line(p_buffer, (int)(xOffset.x + axVertices[0].x), (int)(xOffset.y + axVertices[0].y), (int)(xOffset.x + axVertices[iNumVertices - 1].x), (int)(xOffset.y + axVertices[iNumVertices - 1].y),ARGBline); but then it will not be rotated. So what I have is a set of coordinates and an offset and I would like to know how to rotate them. I guess I could calculate the distance from origo to all coordninates and then rotate that with some angle and calculate the x and y angain for wacy node, but that seems tedious. Is there some quick and dirty matrix or vector operation I can use? Thank you in advance, -- |
Sirocco
Member #88
April 2000
![]() |
IIRC you can use a standard 3D rotation matrix and ignore the Y or Z component depending on your setup. --> |
Johan Peitz
Member #9
April 2000
![]() |
That's what X-G said too and I kinda got too it myself while I was writing the post. -- |
X-G
Member #856
December 2000
![]() |
COOKIE! -- |
Johan Peitz
Member #9
April 2000
![]() |
Very nice. 2D physics for the win. (It works now.) -- |
|