Original Post
Im trying to rotate a polygon but Im having trouble. Here's my code:
Then I call the function like this:
CPolygon2D Shape;
Shape.Draw_Polygon2D(back_buffer, back_lpitch);
Shape.Rotate_Polygon2D(5);
Only problem is instead of rotating the polygon it just draws a dot on the screen. I know it's not the Draw_Polygon2D fault because if I comment out the rotate it draws the polygon fine. I think maybe it has to do with my class not copying the vertex list but im not sure. Anyone have any ideas what Im doing wrong?
Edited by - dj9781 on 8/23/00 4:45:53 PM
int CPolygon2D::Rotate_Polygon2D(int theta)
{
float xr,yr;
int curr_vert;
// test for negative rotation angle
if (theta < 0)
theta+=360;
// loop and rotate each point
for (curr_vert=0; curr_vert<num_verts; curr_vert++)
{
// perform rotation
xr=(float)vlist[curr_vert].x*cos_look[theta] -
(float)vlist[curr_vert].y*sin_look[theta];
yr=(float)vlist[curr_vert].x*sin_look[theta] +
(float)vlist[curr_vert].y*cos_look[theta];
// store result back
vlist[curr_vert].x = xr;
vlist[curr_vert].y = yr;
}
// return success
return(1);
}
Heres my CPolygon2D class (only the relevant stuff):
class CPolygon2D
{
public:
int state; // state of polygon
int num_verts; // number of vertices
int x0,y0; // position of center of polygon
int xv,yv; // initial velocity
DWORD color; // could be index or PALETTENTRY
VERTEX2DF *vlist; // pointer to vertex list
int Rotate_Polygon2D(int theta);
};
|