Example #1
0
void ExtendedWmlCamera::SetAxes (const Matrix3f& rkAxes)
{
    m_kLeft = rkAxes.GetColumn(0);
    m_kUp = rkAxes.GetColumn(1);
    m_kDirection = rkAxes.GetColumn(2);
    OnFrameChange();
}
//----------------------------------------------------------------------------
void AffineTransform (int warmups, Ellipsoid3f& ellipsoid0,
                      Ellipsoid3f& ellipsoid1)
{
	float random = 0.0f;
	for (int i = 0; i < warmups; ++i)
	{
		random = Mathf::SymmetricRandom();
	}

	Matrix3f A;
	Vector3f B;
	for (int row = 0; row < 3; ++row)
	{
		for (int col = 0; col < 3; ++col)
		{
			A[row][col] = Mathf::SymmetricRandom();
		}
		B[row] = Mathf::SymmetricRandom();
	}
	if (A.Determinant() < 0.0f)
	{
		A[0][0] = -A[0][0];
		A[0][1] = -A[0][1];
		A[0][2] = -A[0][2];
	}

	Matrix3f invA = A.Inverse();
	Vector3f K = invA*(ellipsoid0.Center - B);
	Matrix3f D(
	    1.0f/(ellipsoid0.Extent[0]*ellipsoid0.Extent[0]),
	    1.0f/(ellipsoid0.Extent[1]*ellipsoid0.Extent[1]),
	    1.0f/(ellipsoid0.Extent[2]*ellipsoid0.Extent[2]));
	Matrix3f N = A.TransposeTimes(D)*A;
	Matrix3f R;
	N.EigenDecomposition(R, D);

	ellipsoid0.Center = K;
	ellipsoid0.Axis[0] = R.GetColumn(0);
	ellipsoid0.Axis[1] = R.GetColumn(1);
	ellipsoid0.Axis[2] = R.GetColumn(2);
	ellipsoid0.Extent[0] = Mathf::InvSqrt(D[0][0]);
	ellipsoid0.Extent[1] = Mathf::InvSqrt(D[1][1]);
	ellipsoid0.Extent[2] = Mathf::InvSqrt(D[2][2]);

	K = invA*(ellipsoid1.Center - B);
	D = Matrix3f(
	        1.0f/(ellipsoid1.Extent[0]*ellipsoid1.Extent[0]),
	        1.0f/(ellipsoid1.Extent[1]*ellipsoid1.Extent[1]),
	        1.0f/(ellipsoid1.Extent[1]*ellipsoid1.Extent[1]));
	N = A.TransposeTimes(D)*A;
	N.EigenDecomposition(R, D);

	ellipsoid1.Center = K;
	ellipsoid1.Axis[0] = R.GetColumn(0);
	ellipsoid1.Axis[1] = R.GetColumn(1);
	ellipsoid1.Axis[2] = R.GetColumn(2);
	ellipsoid1.Extent[0] = Mathf::InvSqrt(D[0][0]);
	ellipsoid1.Extent[1] = Mathf::InvSqrt(D[1][1]);
	ellipsoid1.Extent[2] = Mathf::InvSqrt(D[2][2]);
}
Example #3
0
//----------------------------------------------------------------------------
void LightNode::UpdateWorldData (float fAppTime)
{
    Node::UpdateWorldData(fAppTime);

    if ( m_spkLight )
    {
        Matrix3f kLWorldRotate = m_kWorldRotate*m_kLRotate;
        Vector3f kLWorldTranslate = m_kWorldTranslate +
            m_fWorldScale*(m_kWorldRotate*m_kLTranslate);

        switch ( m_spkLight->GetType() )
        {
        case Light::LT_DIRECTIONAL:
        {
            DirectionalLight* pkDLight =
                WmlStaticCast(DirectionalLight,m_spkLight);
            pkDLight->Direction() = kLWorldRotate.GetColumn(2);
            break;
        }
        case Light::LT_POINT:
        {
            PointLight* pkPLight = WmlStaticCast(PointLight,m_spkLight);
            pkPLight->Location() = kLWorldTranslate;
            break;
        }
        case Light::LT_SPOT:
        {
            SpotLight* pkSLight = WmlStaticCast(SpotLight,m_spkLight);
            pkSLight->Location() = kLWorldTranslate;
            pkSLight->Direction() = kLWorldRotate.GetColumn(2);
            break;
        }
        default:  // Light::LT_AMBIENT, Light::LT_QUANTITY
            break;
        }
    }
}