Sunday, May 22, 2011

Attempting to solve the rotation problem

Hi Casey,
Sorry for my late reply, as I was doing a lot testing on the code, trying to figure the problem out these two days. I found the over-rotation problem is not caused by this code:
    else if (rotationAxis == -Vector3.Up)
    {

        rotationAxis = Vector3.Backward;

        rotationAngle = MathHelper.Pi;

    }

Now I only use the following code for all cases:
    rotationAxis = Vector3.Normalize(calVectors[i + 1] - calVectors[i]);
    rotationAngle = -(float)Math.Acos(Vector3.Dot(rotationAxis, Vector3.Up));

    rotationAxis = Vector3.Cross(rotationAxis, Vector3.Up);

    rotationAxis.Normalize();
The problem seems to occur only when the rope goes from up to down. I'm currently looking into the secret of these two lines of code. Maybe I need to add more code to cover all cases:
    rotationAngle = -(float)Math.Acos(Vector3.Dot(rotationAxis, Vector3.Up));
    rotationAxis = Vector3.Cross(rotationAxis, Vector3.Up);

No comments:

Post a Comment