Well, I''m getting closer now thanks to yellowjon, but it''s still not right. What I''m doing is using OpenGL quads, and I feed in the eight coords (2 pairs) to draw (in essence) a 2d quad that spins. But insatead what Im getting are quads that flip on their x/y coords and now spin around a point.
Here''s the code I use. I use rotX/rotY as the origin coord. Basetl_x, Basetl_y through Basebr_x and Basebr_y are the coord pairs for the four corners of the quad.
The first section is to set the central origin, in here xpos/ypos are the upper left coord of the quad, w/h are width and height:
void Actor::setAutoCentre(){ rotX=xpos+(w*0.5f); rotY=ypos+(h*0.5f); Basetl_x = rotX-(w*0.5f); Basetl_y = rotY-(h*0.5f); Basetr_x = rotX+w*0.5f; Basetr_y = rotY-(h*0.5f); Basebl_x = rotX-(w*0.5f); Basebl_y = rotY+h*0.5f; Basebr_x = rotX+w*0.5f; Basebr_y = rotY+h*0.5f;}
and this second function rotates then draws the quad:
if (oldRotation!=rotation) { float r = deg2rad(rotation); tl_x=cosf(r) * (Basetl_x-rotX) - sinf(r) * (Basetl_y-rotY) + rotX; tl_y=sinf(r) * (Basetl_x-rotX) - cosf(r) * (Basetl_y-rotY) + rotY; bl_x=cosf(r) * (Basebl_x-rotX) - sinf(r) * (Basebl_y-rotY) + rotX; bl_y=sinf(r) * (Basebl_x-rotX) - cosf(r) * (Basebl_y-rotY) + rotY; tr_x=cosf(r) * (Basetr_x-rotX) - sinf(r) * (Basetr_y-rotY) + rotX; tr_y=sinf(r) * (Basetr_x-rotX) - cosf(r) * (Basetr_y-rotY) + rotY; br_x=cosf(r) * (Basebr_x-rotX) - sinf(r) * (Basebr_y-rotY) + rotX; br_y=sinf(r) * (Basebr_x-rotX) - cosf(r) * (Basebr_y-rotY) + rotY; oldRotation=rotation; } renderSprite4f(tl_x, tl_y, tr_x, tr_y, br_x, br_y, bl_x, bl_y, textureID);
renderSprite4f is a function of mine that takes the 4 pairs of coords and a texture ID and draws the quad accordingly. I''m guessing my problem lies in the rotation maths, but I used the same as what yellowjon recommended