   Quad rotation around it's center.
  Hi,I am using glDrawElements to draw multiple sprites (vertices quads), each one with it's own rotation value. I am trying to calculate and rotate vertices quads around their center before calling glDrawElements.The quads type I've got:typedef struct _Quad{float tl_x, tl_y;float tr_x, tr_y;float bl_x, bl_y;float br_x, br_y;} Quad;The code that calculates and rotates vertices is as follows:static inline void CalculateRotatedVerticesAtPoint(float X, float Y, int Width,int Height, Quad* vertices, float ScaleX, float ScaleY,float AngleDegree ){GLfloat quadWidth = Width * ScaleX;GLfloat quadHeight = Height * ScaleY;GLfloat HalfQuadWidth=quadWidth/2;GLfloat HalfQuadHeight=quadHeight/2;//centeredvertices[0].br_x = X + HalfQuadWidth;vertices[0].br_y = Y + HalfQuadHeight;vertices[0].tr_x = X + HalfQuadWidth;vertices[0].tr_y = Y - HalfQuadHeight;vertices[0].bl_x = X - HalfQuadWidth;vertices[0].bl_y = Y + HalfQuadHeight;vertices[0].tl_x = X - HalfQuadWidth;vertices[0].tl_y = Y - HalfQuadHeight;//Degree To Radianfloat angle=AngleDegree/(180/3.14159265);//calculate the center of rotationfloat xCenter=X; //Vertices calculated above with (X,Y) as the center...float yCenter=Y;//Rotate around center using this formula://xRot = xCenter + cos(Angle) * (x - xCenter) - sin(Angle) * (y - yCenter)//yRot = yCenter + sin(Angle) * (x - xCenter) + cos(Angle) * (y - yCenter)}vertices[0].br_x = xCenter + cos(angle) * (vertices[0].br_x - xCenter) - sin(angle) * (vertices[0].br_y - yCenter);vertices[0].br_y = yCenter + sin(angle) * (vertices[0].br_x - xCenter) + cos(angle) * (vertices[0].br_y - yCenter);vertices[0].tr_x = xCenter + cos(angle) * (vertices[0].tr_x - xCenter) - sin(angle) * (vertices[0].tr_y - yCenter);vertices[0].tr_y = yCenter + sin(angle) * (vertices[0].tr_x - xCenter) + cos(angle) * (vertices[0].tr_y - yCenter);vertices[0].bl_x = xCenter + cos(angle) * (vertices[0].bl_x - xCenter) - sin(angle) * (vertices[0].bl_y - yCenter);vertices[0].bl_y = yCenter + sin(angle) * (vertices[0].bl_x - xCenter) + cos(angle) * (vertices[0].bl_y - yCenter);vertices[0].tl_x = xCenter + cos(angle) * (vertices[0].tl_x - xCenter) - sin(angle) * (vertices[0].tl_y - yCenter);vertices[0].tl_y = yCenter + sin(angle) * (vertices[0].tl_x - xCenter) + cos(angle) * (vertices[0].tl_y - yCenter);}The rotation code isn't working as it should, I am getting diferent result from what I get by setting the rotation angle with glRotatef and calling glDrawArrays for each sprite quad.This seems to be an easy to implement issue, but I have been struggling to get it working for over a week now, and have tried several ways to solve this without success.Could anyone please provide me with a simple code that rotates vertices, around their center, to end up with the same result we get by setting rotation angle using glRotatef() for each individual sprite vertices?I would really apreciate any kind help.Thanks.   
  It looks like you might be making the 'standard' mistake here. In this code:vertices[0].br_x = xCenter + cos(angle) * (vertices[0].br_x - xCenter) - sin(angle) * (vertices[0].br_y - yCenter);vertices[0].br_y = yCenter + sin(angle) * (vertices[0].br_x - xCenter) + cos(angle) * (vertices[0].br_y - yCenter);You're overwriting br_x with a new value, but then attempting to use the old value in the next line of code. Instead, use a temporary variable (or temporary variables) to ensure that the old values aren't overwritten until the new values have been computed.   ;  vertices[0].br_x - xCenter would result in HalfQuadWidth, since vertices[0].br_x = X + HalfQuadWidth  and xCenter = X.In order to simplify your calculations you could just use +/- HalfQuadWidth and +/- HalfQuadHeight, i.e. vertices[0].br_x = xCenter + cos(angle) * (vertices[0].br_x - xCenter) - sin(angle) * (vertices[0].br_y - yCenter) would result in vertices[0].br_x = xCenter + cos(angle) * (HalfQuadWidth ) - sin(angle) * (HalfQuadHeight)   ;  Cheers for the help. It is finally working! [smile]Thank you very much.   