rotation math not working

This topic is 4891 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.

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• Forum Statistics

• Total Topics
632909
• Total Posts
3009171
• Who's Online (See full list)

There are no registered users currently online

×