views:

23

answers:

0

Hi! I would like to write quaternion camera. But unfortunatelly it gets "NULLED". I don't know where I was wrong. I have 3 additional quaternion for easy moving (up, look, thirdA) The bad code:

void _camera::rotateX(float angle)
{
    thirdA.w = angle;

    D3DXQUATERNION tmp;
    D3DXQUATERNION tmp2;
    D3DXQuaternionConjugate(&tmp, &thirdA);

    up.w = 0;
    D3DXQuaternionMultiply(&tmp2, &thirdA, &up);
    D3DXQuaternionMultiply(&up, &tmp2, &tmp);

    look.w = 0;
    D3DXQuaternionMultiply(&tmp2, &thirdA, &look);
    D3DXQuaternionMultiply(&look, &tmp2, &tmp);
}

void _camera::rotateY(float angle)
{
    up.w = angle;

    D3DXQUATERNION tmp;
    D3DXQUATERNION tmp2;
    D3DXQuaternionConjugate(&tmp, &up);

    thirdA.w = 0;
    D3DXQuaternionMultiply(&tmp2, &up, &thirdA);
    D3DXQuaternionMultiply(&thirdA, &tmp2, &tmp);

    look.w = 0;
    D3DXQuaternionMultiply(&tmp2, &up, &look);
    D3DXQuaternionMultiply(&look, &tmp2, &tmp);
}

void _camera::rotateZ(float angle)
{
    look.w = angle;

    D3DXQUATERNION tmp;
    D3DXQUATERNION tmp2;
    D3DXQuaternionConjugate(&tmp, &look);

    thirdA.w = 0;
    D3DXQuaternionMultiply(&tmp2, &look, &thirdA);
    D3DXQuaternionMultiply(&thirdA, &tmp2, &tmp);

    up.w = 0;
    D3DXQuaternionMultiply(&tmp2, &look, &up);
    D3DXQuaternionMultiply(&up, &tmp2, &tmp);
}

The 3 quaternion gets NULLED for some reason. Where was I wrong again?