   Rotation error
  I can't pull off this rotation of quads. I simply try to rotate 4 vertexes of a rect around the center axis of the quad while translating the quad. I got part of it to work. It will rotate fine when I haven't added MousePos. But every time I add MousePos to the x and y, the quad's axis never moves. It is like the radius is being lengthened (or shortened, at times), instead of the axis following the literal center of the quad.I'm using DX 9.0. // Set aside the vertices infoSQUAREVERTEX* vertices;//Lock the vertex buffervertexBuffer->Lock(0, 0, (void **)&vertices, NULL);   // Update the vertices to follow the mouse.x +=  MousePos1;y +=  MousePos2;//Setup vertices  vertices[0].Color = color0;vertices[0].x   = x + 1.5f;vertices[0].y   = y + 1.5f;vertices[0].rhw = 1.0f;vertices[0].u   = 0.0f;vertices[0].v   = 0.0f;vertices[1].Color = color1;vertices[1].x   = (float)x + width - 0.5f;vertices[1].y   = (float)y + 1.5f;vertices[1].rhw = 1.0f;vertices[1].u   = 1.0f;vertices[1].v   = 0.0f;vertices[2].Color = color2;vertices[2].x   = (float)x + width - 0.5f;vertices[2].y   = (float)y + height - 0.5f;vertices[2].rhw = 1.0f;vertices[2].u   = 1.0f;vertices[2].v   = 1.0f;vertices[3].Color = color3;vertices[3].x   = (float)x + 1.5f; vertices[3].y   = (float)y + height - 0.5f;vertices[3].rhw = 1.0f;vertices[3].u   = 0.0f;vertices[3].v   = 1.0f;  // Rotation  if (rotate != 0.0f)  {  RECT rOrigin; static float centerX, centerY; //Find center of destination rectangle centerX = (float)(x + width)  / 2; centerY = (float)(y + height) / 2; //Translate destination rect to be centered on the origin rOrigin.top    = (float)x  - (centerY); rOrigin.bottom = (float)x + height - (centerY); rOrigin.left   = (float)y  - (centerX); rOrigin.right  = (float)y + width  - (centerX); //Rotate vertices about the origin vertices[0].x = (float)rOrigin.left * cosf(rotate) -  rOrigin.top * sinf(rotate); vertices[0].y = (float)rOrigin.left * sinf(rotate) +  rOrigin.top * cosf(rotate); vertices[1].x = (float)rOrigin.right * cosf(rotate) - rOrigin.top * sinf(rotate); vertices[1].y = (float)rOrigin.right * sinf(rotate) + rOrigin.top * cosf(rotate); vertices[2].x = (float)rOrigin.right * cosf(rotate) - rOrigin.bottom * sinf(rotate); vertices[2].y = (float)rOrigin.right * sinf(rotate) + rOrigin.bottom * cosf(rotate); vertices[3].x = (float)rOrigin.left * cosf(rotate) - rOrigin.bottom * sinf(rotate); vertices[3].y = (float)rOrigin.left * sinf(rotate) + rOrigin.bottom * cosf(rotate);    //Translate vertices to proper position vertices[0].x += (float)centerX; vertices[0].y += (float)centerY; vertices[1].x += (float)centerX; vertices[1].y += (float)centerY; vertices[2].x += (float)centerX; vertices[2].y += (float)centerY; vertices[3].x += (float)centerX; vertices[3].y += (float)centerY;    }x -=  MousePos1;y -=  MousePos2;// Unlock the Vertex buffervertexBuffer->Unlock();// it looks like this////    0--------1//    |  /|//    | / |  //    |/  | //    |    #   |  //    |   /    |//    |  /|    //    | / | //    2--------3////    # = Center Axis//// But when I add MousePos, I get this:////    0--------1//    |  /|//    | / |  //    |/  | //  # |    /   |  //    |   /    |//    |  /|    //    | / | //    2--------3//// (given the rect is moving around the # in a big circle)
  I think you should add the mouse position after you rotate the quad about it`s axis. I hope I get what you`re trying to do...   ;  I tried adding the MousePos after the rotation, before rotation, everywhere. I tried putting the    //Setup vertices  vertices[0].Color = color0;vertices[0].x   = x+0.5f;vertices[0].y   = y+0.5f;vertices[0].rhw = 1.0f;vertices[0].u   = 0.0f;vertices[0].v   = 0.0f;vertices[1].Color = color1;vertices[1].x   = x+0.5f;vertices[1].y   = y+0.5f;vertices[1].rhw = 1.0f;vertices[1].u   = 1.0f;vertices[1].v   = 0.0f;vertices[2].Color = color2;vertices[2].x   = x+0.5f;vertices[2].y   = y+0.5f;vertices[2].rhw = 1.0f;vertices[2].u   = 1.0f;vertices[2].v   = 1.0f;vertices[3].Color = color3;vertices[3].x   = x+0.5f; vertices[3].y   = y+0.5f;vertices[3].rhw = 1.0f;vertices[3].u   = 0.0f;vertices[3].v   = 1.0f;  after the rotation, and that failed too.All I got, was either nowhere, or the rects never spun.[Edited by - Photon Man on June 23, 2009 12:04:19 PM];  Is this what you're trying to do? I hope I've used your variables correctly, if not you should be able to see where I'm coming from. It's crucial that you do *all* the rotation stuff first, *then* you translate. If you set up the vertices relative to the centre point in the first place, then you can just go ahead and rotate away. // Set aside the vertices infoSQUAREVERTEX* vertices;//Lock the vertex buffervertexBuffer->Lock(0, 0, (void **)&vertices, NULL);//Setup vertices  vertices[0].Color = color0;vertices[0].x   = -width*0.5f;vertices[0].y   = -height*0.5f;vertices[0].rhw = 1.0f;vertices[0].u   = 0.0f;vertices[0].v   = 0.0f;vertices[1].Color = color1;vertices[1].x   = width*0.5f;vertices[1].y   = -height*0.5f;vertices[1].rhw = 1.0f;vertices[1].u   = 1.0f;vertices[1].v   = 0.0f;vertices[2].Color = color2;vertices[2].x   = -width*0.5f;vertices[2].y   = height*0.5f;vertices[2].rhw = 1.0f;vertices[2].u   = 1.0f;vertices[2].v   = 1.0f;vertices[3].Color = color3;vertices[3].x   = width*0.5f; vertices[3].y   = height*0.5f;vertices[3].rhw = 1.0f;vertices[3].u   = 0.0f;vertices[3].v   = 1.0f;  // Rotation  if (rotate != 0.0f)  { SQUAREVERTEX tempvertex; float cosr = cosf(rotate), sinr = sinf(rotate); for(UINT i=0;i<4;++i) {    //Store temporary vertex position    tempvertex.x = vertices.x;    tempvertex.y = vertices.y;    //Rotate vertices about the origin    vertices.x = tempvertex.x * cosr - tempvertex.y * sinr;    vertices.y = tempvertex.x * sinr + tempvertex.y * cosr; }   }    // Update the vertices to follow the mouse.    for(UINT i=0;i<4;++i)    {    //Translate vertices to proper position vertices.x += (float)MousePos1; vertices.y += (float)MousePos2;    }    // Unlock the Vertex buffer    vertexBuffer->Unlock();;  Thanks! That is it! I had to mod it a little, but it is up and running. You guys were right about putting the translation after the rotation. Once I did that, it panned out. I had put this:x +=  MousePos1;y +=  MousePos2; // Which I should have put thisvertices[].x +=  MousePos1;vertices[].y +=  MousePos2;Thanks for pointing that out, shaolinspin.   ;  You're welcome. Glad you got it working!   