# rotation math not working

This topic is 4984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i spent most of last night writing a skeletal animation for a model loader im making. The problem is that rotation math isn't quite working correct. It should rotate points around a point, but it rotates points around a point, which also seems to be rotating around a point... heres the math simplified a bit, if possible, please tell me what im doing wrong
float cosTheta = (float)cos(angle);
float sinTheta = (float)sin(angle);

vPos = POINT - CENTER;

vNewPos.x = (cosTheta + (1 - cosTheta) * xAxis * xAxis) * vPos.x;
vNewPos.x += ((1 - cosTheta) * xAxis * yAxis - zAxis * sinTheta) * vPos.y;
vNewPos.x += ((1 - cosTheta) * xAxis * zAxis + yAxis * sinTheta) * vPos.z;

vNewPos.y = ((1 - cosTheta) * xAxis * yAxis + zAxis * sinTheta) * vPos.x;
vNewPos.y += (cosTheta + (1 - cosTheta) * yAxis * yAxis) * vPos.y;
vNewPos.y += ((1 - cosTheta) * yAxis * zAxis - xAxis * sinTheta) * vPos.z;

vNewPos.z = ((1 - cosTheta) * xAxis * zAxis - yAxis * sinTheta) * vPos.x;
vNewPos.z += ((1 - cosTheta) * yAxis * zAxis + xAxis * sinTheta) * vPos.y;
vNewPos.z += (cosTheta + (1 - cosTheta) * zAxis * zAxis) * vPos.z;

POINT = CENTER + vNewPos;


##### Share on other sites
Efficiency issues aside, as far as I can tell there is nothing wrong with your code. It should rotate the point about an axis passing through 'center'.

I'm guessing the problem lies elsewhere, most likely in combining the rotations. Typically this sort of thing is done with matrices or quaternions; with those representations it is considerably easier to concatenate and interpolate the rotations in a hierarchical model.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634059
• Total Posts
3015292
×