   Rotating a Rectangle
  So I'm just trying out some tests for a new top down game I'm going to start on and first thing I though id better be able to rotate a rectangle around a point but I'm getting a weird effect anyone see the problem - I'm still new so bear with me (the code is not tidy as its just a test).Key Functions:struct Vertex{    int x;    int y;};void myRect::Draw(){    glEnable2D();  glBegin(GL_QUADS);  glVertex2d(points[0].x,points[0].y);  glVertex2d(points[1].x,points[1].y);  glVertex2d(points[2].x,points[2].y);  glVertex2d(points[3].x,points[3].y);   glEnd();  glDisable2D();}myRect::myRect(int sx, int sy,int width,int height){    x = sx;    y = sy;    w = width;    h = height;    //Set up & store the 4 points    Vertex topleft,topright,bleft,bright;    topleft.x = x;    topleft.y = y;    topright.x = x + width;    topright.y = y;    bleft.x = x;    bleft.y = y + h;    bright.x = x + w;    bright.y = y + h;    container.x = x;    container.y = y;    container.w = RECT_WIDTH;    container.h = RECT_HEIGHT;    points = new Vertex[4];    points[0] = topleft;    points[1] = topright;    points[2] = bright;    points[3] = bleft;    angle = 0;    xVel = 0;    yVel = 0;}Vertex  myRect::Vertex_Rotate(Vertex v ,int px,int py, float angle){    //Local Vertex   Vertex temp;    //Take away to get the x co-ordinates to the origin   int ox = v.x - px;   int oy = v.y - py;    //Do the rotation    int newx = (ox*cos(angle) - oy*sin(angle));    int newy = (oy*cos(angle) + ox*sin(angle));    //Add the point back on    temp.x = newx + px;    temp.y = newy + py;    return temp;}Thanks in advance - P.S the angle does change in the input functions but decided not to include   
  what sort of effect are you getting?also try stepping through your program to see what all the values are set at and see if they match up to what they are supposed to be doing. I thought that you setting your topleft.y and topright.y both to y might cause a couple of problems. Why don't you try setting them to something like ytl = ytopleft etc.. and then try and rotate using those independent variables.Hope this helped!   ;  The first few rotations are fine then it seems to screw and rotate then finally fade to nothing. Weird   ;  As your coordinates are integers, they won't be very exact, and your number will be truncated at each iteration. This probably has the effect of in time shrinking your rectangle. Try using floats instead of ints.   ;Quote:Original post by Erik RufeltAs your coordinates are integers, they won't be very exact, and your number will be truncated at each iteration. This probably has the effect of in time shrinking your rectangle. Try using floats instead of ints.Good idea but still didn't work Any more suggestions? ill paste the full code if you like>   ;  What you need to do is store a copy of the initial (un rotated) points of your rectangle.Then, each time you rotate it, you rotate based on the original points.The problem is that even floating point numbers aren't exact and you start losing precision over time, which leads to the rectangle distorting and going degenerate.So yeah...Keep a copy of the original points around, and use them each time you want to rotate, instead of just rotating the points you already have rotated.   