rotation math not working

Started by
0 comments, last by Zakwayda 18 years, 11 months ago
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;
- relpats_eht
Advertisement
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.

This topic is closed to new replies.

Advertisement