Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem with rotating a polygon

Started by dj9781 Aug 23, 2000 at 4:43 PM 0 replies 550+ views
Original Post
dj9781
dj9781
Im trying to rotate a polygon but Im having trouble. Here's my code:
        
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);
	
	
};
        
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
Antknei
Antknei
Are you sure that your look up table is working correctly? try using sin and cos and see what happens. It makes sense to me if you are drawing a dot, all the vertices are at the same point, which would happen if you have a bunch of zeros in your lookup talble. Also, I don''t know how you are getting a theta, but if it is critical that theta > 0, maybe use
while ( theta < 0 ) theta += 360;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.