Exemple #1
0
float AngleDiff( float lhs, float rhs )
{
	lhs = WrapPi( lhs );
	rhs = WrapPi( rhs );

	return WrapPi( lhs - rhs );
}
void kmEulerAngles::canonize()
{
    // transform pitch into [-pi pi]
    m_pitch = WrapPi(m_pitch);
    // transform pitch into [-pi/2 pi/2]
    if (m_pitch < - kmPiOver2)
    {
        m_pitch = -kmPi - m_pitch;
        m_heading += kmPi;
        m_bank += kmPi;

    }
    else if(m_pitch > kmPiOver2)
    {
        m_pitch = kmPi - m_pitch;
        m_heading += kmPi;
        m_bank += kmPi;

    }

    if (fabs(m_pitch) > kmPiOver2)
    {
        m_heading += m_bank;
        m_bank = 0.0f;
    }
    else
    {
        m_bank = WrapPi(m_bank);
    }

    m_heading = WrapPi(m_heading);
}
Vec3 GetVectorFromYRotation(float angleRadians)
{
	Vec3 lookAt;
	WrapPi(angleRadians);
	lookAt.x = cos(angleRadians);
	lookAt.y = 0;
	lookAt.z = sin(angleRadians);
	lookAt.Normalize();
	return lookAt;
}
Exemple #4
0
//-------------------------------------------------------------------------------------------------------------------
// This function returns the target orientation for a given look-at vector.  The orientation will be along the Y
// axis so the Y component of the look-at vector is ignored.  This function is used by the AI system which doesn't
// care about orientation along any other axis.
//-------------------------------------------------------------------------------------------------------------------
float GetYRotationFromVector(const Vec3& lookAt)
{
	Vec3 zUnit(0,0,1);  // 0 orientation means staring down the positive Z axis
	float angle = (atan2(lookAt.z,lookAt.x*-1) - atan2(zUnit.z,zUnit.x));
	return WrapPi(angle);
}