# rotation math not working

## Recommended Posts

relpats_eht    138
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 this post

##### Share on other sites
jyk    2094
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.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

## Sign in

Already have an account? Sign in here.

Sign In Now