Beispiel #1
0
quaternion operator*(quaternion const& lhs,quaternion const& rhs)
{
    return quaternion(lhs.x()*rhs.w() + lhs.w()*rhs.x() + lhs.y()*rhs.z() - lhs.z()*rhs.y(),
                      lhs.y()*rhs.w() + lhs.w()*rhs.y() + lhs.z()*rhs.x() - lhs.x()*rhs.z(),
                      lhs.z()*rhs.w() + lhs.w()*rhs.z() + lhs.x()*rhs.y() - lhs.y()*rhs.x(),
                      lhs.w()*rhs.w() - lhs.x()*rhs.x() - lhs.y()*rhs.y() - lhs.z()*rhs.z());
}
Beispiel #2
0
void matrix4x4::setOrientation( quaternion in )
    {
    jAssert( fcmp( in.length(), 1 ) );

    JFLOAT xx = in.x() * in.x();
    JFLOAT xy = in.x() * in.y();
    JFLOAT xz = in.x() * in.z();
    JFLOAT xw = in.x() * in.w();

    JFLOAT yy = in.y() * in.y();
    JFLOAT yz = in.y() * in.z();
    JFLOAT yw = in.y() * in.w();

    JFLOAT zz = in.z() * in.z();
    JFLOAT zw = in.z() * in.w();


#ifndef USEALTERNATIVEQUATTOMATRIX
    JFLOAT ww = in.w() * in.w();

    RM(0,0) = xx - yy - zz + ww;
    RM(1,0) = 2 * ( xy - zw );
    RM(2,0) = 2 * ( xz + yw );

    RM(0,1) = 2 * ( xy + zw );
    RM(1,1) = -xx + yy - zz + ww;
    RM(2,1) = 2 * ( yz - xw );

    RM(0,2) = 2 * ( xz - yw );
    RM(1,2) = 2 * ( yz + xw );
    RM(2,2) = -xx - yy + zz + ww;
#else
    RM(0,0) = 1.0 - 2.0 * ( yy + zz );
    RM(0,1) = 2 * ( xy + zw );
    RM(0,2) = 2 * ( xz - yw );

    RM(1,0) = 2 * ( xy - zw );
    RM(1,1) = 1 - 2 * ( xx + zz );
    RM(1,2) = 2 * ( yz + xw );

    RM(2,0) = 2 * ( xz + yw );
    RM(2,1) = 2 * ( yz - xw );
    RM(2,2) = 1 - 2 * ( xx + yy );
#endif
    }
Beispiel #3
0
float dot(quaternion const& q0,quaternion const& q1)
{
    return q0.x()*q1.x()+q0.y()*q1.y()+q0.z()*q1.z()+q0.w()*q1.w();
}
Beispiel #4
0
quaternion operator-(quaternion const& q)
{
    return quaternion(-q.x(),-q.y(),-q.z(),-q.w());
}
Beispiel #5
0
quaternion conjugated(quaternion const& q)
{
    return quaternion(-q.x(),-q.y(),-q.z(),q.w());
}
Beispiel #6
0
float norm(quaternion const& q)
{
    return std::sqrt(q.x()*q.x()+q.y()*q.y()+q.z()*q.z()+q.w()*q.w());
}