Advanced Rotation

This section explains how to rotate an object based on where the user is performing the rotation manipulation.

The following image illustrates two different ways that an object can be rotated.

illustration showing two types of single-finger rotation: around the center or around the edge, with the edge involving both rotation and translation

In example A, the object is manipulated around the center point of the object. In example B, the object is rotated around the center point of the manipulation. To support manipulation around a point other than the center point of the object, you must perform a compound manipulation that performs both rotation and translation. The following code shows how this manipulation is performed and calculated.

RotateVector(FLOAT *vector, FLOAT *tVector, FLOAT fAngle) {
    FLOAT fAngleRads = fAngle / 180.0f * 3.14159f;
    FLOAT fSin = sin(fAngleRads);
    FLOAT fCos = cos(fAngleRads);

    FLOAT fNewX = (vector[0]*fCos) - (vector[1]*fSin);
    FLOAT fNewY = (vector[0]*fSin) + (vector[1]*fCos);

    tVector[0] = fNewX;
    tVector[1] = fNewY;
}
     

Advanced Manipulations

Manipulations