示例#1
0
    //
    // LookAtRH
    //
    bool Mat4::LookAtRH( const Vec3<float>& Eye, const Vec3<float>& At, const Vec3<float>& _Up )
    {
    #ifdef _DEBUG
        _Up.Assume();
    #endif

        Vec3<float> Dir = Eye - At; // RHS
        Dir.Normalize();
        Vec3<float> Side = CrossProduct( _Up, Dir );
	    Side.Normalize();
        Vec3<float> Up = CrossProduct( Dir, Side );

	    m[ 0 ][ 0 ] = Side.x;    
        m[ 1 ][ 0 ] = Side.y;    
        m[ 2 ][ 0 ] = Side.z;     
        m[ 3 ][ 0 ] = -DotProduct( Side, Eye );

	    m[ 0 ][ 1 ] = Up.x;    
        m[ 1 ][ 1 ] = Up.y;    
        m[ 2 ][ 1 ] = Up.z;     
        m[ 3 ][ 1 ] = -DotProduct( Up, Eye );

	    m[ 0 ][ 2 ] = Dir.x;  
        m[ 1 ][ 2 ] = Dir.y;   
        m[ 2 ][ 2 ] = Dir.z;    
        m[ 3 ][ 2 ] = -DotProduct( Dir, Eye );

	    m[ 0 ][ 3 ] = 0.0f;   
        m[ 1 ][ 3 ] = 0.0f;   
        m[ 2 ][ 3 ] = 0.0f;
        m[ 3 ][ 3 ] = 1.0f;

        return true;
    }
示例#2
0
    //
    // RotationAroundAxis
    //
    void Mat4::RotationAroundAxis( const Vec3<float>& Axis, float Angle )
    {
	    // x^2 + (1 - x^2) * cos(a) => x^2 + cos(a) - x^2 * cos(a) => 
        // x^2 * (1 - cos(a)) + cos(a)

    #ifdef _DEBUG
	    Axis.Assume();
    #endif

        float Rad = Radians( Angle );

        float s = Sin( Rad );
        float c = Cos( Rad );
	    float d = 1.0f - c;

	    float xs = Axis.x * s;
	    float ys = Axis.y * s;
	    float zs = Axis.z * s;

	    float xyd = Axis.x * Axis.y * d;
	    float xzd = Axis.x * Axis.z * d;
	    float yzd = Axis.y * Axis.z * d;

	    m[ 0 ].x = Axis.x * Axis.x * d + c; 
	    m[ 0 ].y = xyd + zs;
	    m[ 0 ].z = xzd - ys;
        m[ 0 ].w = 0.0f;

	    m[ 1 ].x = xyd - zs;
	    m[ 1 ].y = Axis.y * Axis.y * d + c; 
	    m[ 1 ].z = yzd + xs;
        m[ 1 ].w = 0.0f;

	    m[ 2 ].x = xzd + ys;
	    m[ 2 ].y = yzd - xs;
	    m[ 2 ].z = Axis.z * Axis.z * d + c;
        m[ 2 ].w = 0.0f;

        m[ 3 ].x = 0.0f;
	    m[ 3 ].y = 0.0f;
	    m[ 3 ].z = 0.0f;
	    m[ 3 ].w = 1.0f;
    }