Ejemplo n.º 1
0
///==========================================================================================================================================
/// Mutators
///==========================================================================================================================================
float LineSegment3D::SetLength(float newLength){
	float currentLengthSquared = CalcLengthSquared();
	if (currentLengthSquared != 0.0f){
		float currentLength = sqrtf(currentLengthSquared);
		float scale = newLength / currentLength;
		ScaleFromEnd(scale);
		return currentLength;
	}
	return 0.0f;
}
Ejemplo n.º 2
0
bool Vector4::operator == ( const Vector4& vectorToEqual ) const
{
	if (CalcLengthSquared() == vectorToEqual.CalcLengthSquared())
	{
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 3
0
///---------------------------------------------------------------------------------
/// very slow
///---------------------------------------------------------------------------------
float Vector2::Normalize() 
{
	if( CalcLengthSquared() == 0.0f )
		return 0.0f;

	float length = CalcLength();
	if( length == 0.0f ) 
		return 0.0f;

	float inverseLength = 1.0f / length;
	x *= inverseLength;
	y *= inverseLength;

	return length;
}
Ejemplo n.º 4
0
primitiveType Vector4< primitiveType >::Normalize3D()
{
    if( CalcLengthSquared() == (primitiveType) 0 )
        return (primitiveType) 0;

    float length = CalcLength();
    if( length == (primitiveType) 0 )
        return (primitiveType) 0;

    float inverseLength = ( (primitiveType) 1 ) / length;
    x *= inverseLength;
    y *= inverseLength;
    z *= inverseLength;

    return length;
}
Ejemplo n.º 5
0
///---------------------------------------------------------------------------------
///
///---------------------------------------------------------------------------------
const Vector2 Vector2::Normalized() const
{
    if (CalcLengthSquared() == 0.0f)
        return Vector2::ZERO;

    float length = CalcLength();
    if (length == 0.0f)
        return Vector2::ZERO;

    Vector2 returnVec;

    float inverseLength = 1.0f / length;
    returnVec.x = x * inverseLength;
    returnVec.y = y * inverseLength;

    return returnVec;
}
Ejemplo n.º 6
0
///---------------------------------------------------------------------------------
/// very slow
///---------------------------------------------------------------------------------
float Vector2::CalcLength() const
{
	float length = sqrtf( CalcLengthSquared() );
	return length;
}
Ejemplo n.º 7
0
primitiveType Vector4< primitiveType >::CalcLength() const
{
    primitiveType length = sqrt( CalcLengthSquared() );

    return length;
}