Callum Luke Perks
Callum Luke Perks

Reputation: 49

Rotation is slowly shrinking image

I am drawing a triangle using SDL. The following function is meant to take the coordinates of the triangle which are stored in the 'triCoords' array and rotate them by the specified angle around the center of the triangle which is stored in the 'triPos' array. However, while it seems to rotate correctly it is also shrinking the triangle over time

triCoords[0]=((triCoords[0] - triPos[0])*cos(angle) - (triCoords[1] - triPos[1])*sin(angle)) + triPos[0];
triCoords[1]=((triCoords[1] - triPos[1])*cos(angle) + (triCoords[0] - triPos[0])*sin(angle)) + triPos[1];
triCoords[2]=((triCoords[2] - triPos[0])*cos(angle) - (triCoords[3] - triPos[1])*sin(angle)) + triPos[0];
triCoords[3]=((triCoords[3] - triPos[1])*cos(angle) + (triCoords[2] - triPos[0])*sin(angle)) + triPos[1];
triCoords[4]=((triCoords[4] - triPos[0])*cos(angle) - (triCoords[5] - triPos[1])*sin(angle)) + triPos[0];
triCoords[5]=((triCoords[5] - triPos[1])*cos(angle) + (triCoords[4] - triPos[0])*sin(angle)) + triPos[1];

Upvotes: 0

Views: 47

Answers (1)

genpfault
genpfault

Reputation: 52122

Don't update the coordinates in-place, store the rotated coordinates in a separate array.

Upvotes: 3

Related Questions