Phoresis

02-15-2007, 03:55 AM

I'm having a problem rotating a 2d shape with the mouse by dragging a corner and pulling it round.

I would like to rotate it manually by multiplying each vertex so that the vertex co-ordinates actually change, but can't figure out the math to do this.

Currently I'm just using glRotate but it doesnt seem to rotate but just rock back and forth when dragging one way. Here is my code.

float centerX = items[test-10]->getX();

float centerY = items[test-10]->getY();

float distFromCenter = abs((long) sqrt(((x - centerX) * (x - centerX)) + ((y - centerY) * (y - centerY))));

float moveDist = sqrt((xDiff * xDiff) + (yDiff * yDiff));

float angle = atan(moveDist / distFromCenter) / 0.0174532925;

// posative negative amount

if(((mouseX > x) && (mouseY < centerY)) &#0124;&#0124; ((mouseX < x) && (mouseY > centerY)) &#0124;&#0124; ((mouseY > y) &&

(mouseX < centerX)) &#0124;&#0124; ((mouseY > y) && (mouseX > centerX)))

{

items[test-10]->rotate(angle);

}

else

{

items[test-10]->rotate(-angle);

}

I would like to rotate it manually by multiplying each vertex so that the vertex co-ordinates actually change, but can't figure out the math to do this.

Currently I'm just using glRotate but it doesnt seem to rotate but just rock back and forth when dragging one way. Here is my code.

float centerX = items[test-10]->getX();

float centerY = items[test-10]->getY();

float distFromCenter = abs((long) sqrt(((x - centerX) * (x - centerX)) + ((y - centerY) * (y - centerY))));

float moveDist = sqrt((xDiff * xDiff) + (yDiff * yDiff));

float angle = atan(moveDist / distFromCenter) / 0.0174532925;

// posative negative amount

if(((mouseX > x) && (mouseY < centerY)) &#0124;&#0124; ((mouseX < x) && (mouseY > centerY)) &#0124;&#0124; ((mouseY > y) &&

(mouseX < centerX)) &#0124;&#0124; ((mouseY > y) && (mouseX > centerX)))

{

items[test-10]->rotate(angle);

}

else

{

items[test-10]->rotate(-angle);

}