My application allows rotating points around a center based on the mouse position. I’m basically rotating points around another point like this:
void CGlEngineFunctions::RotateAroundPointRad( const POINTFLOAT ¢er, const POINTFLOAT &in, POINTFLOAT &out, float angle )
{
//x' = cos(theta)*x - sin(theta)*y
//y' = sin(theta)*x + cos(theta)*y
POINTFLOAT subtr;
subtr.x = in.x - center.x;
subtr.y = in.y - center.y;
out.x = cos(angle)*subtr.x - sin(angle)*subtr.y;
out.y = sin(angle)*subtr.x + cos(angle)*subtr.y;
out.x += center.x;
out.y += center.y;
}
where POINTFLOAT is simply
struct POINTFLOAT {
float x;
float y;
}
The issue is that the points need to be updated on mousemove. I am looking for a way to do this without doing the following:
Store original points
Rotate Original points
Copy result
Show Result
Rotate Original points
Copy result
Show Result....
I feel storing the originals seems messy and uses extra memory. Is there a way, knowing the previous rotation angle and the current one that I can somehow avoid applying the transformation to the original points all the time and just build upon the points i’m modifying?
*the center will never change until mouse up so thats not an issue
Thanks
If you subtract the old rotation from the new one, you’ll get a value you should be able to use to rotate the already-modified points. Note that this requires storing the old rotation, and the coordinates will get less and less accurate the more you translate them around. It’s close enough for government work, though.