//===========================================================================// // File: angle.cc // // Project: MUNGA Brick: Math Library // // Contents: Implementation details for angle classes // //---------------------------------------------------------------------------// // Date Who Modification // // -------- --- ---------------------------------------------------------- // // 11/19/94 JMA Initial coding. // //---------------------------------------------------------------------------// // Copyright (C) 1994-1995, Virtual World Entertainment, Inc. // // All Rights reserved worldwide // // This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL // //===========================================================================// #include #pragma hdrstop #if !defined(ANGLE_HPP) #include #endif #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile Radian *) { return False; } #endif // //############################################################################# //############################################################################# // Scalar Radian::Normalize(Scalar Value) { Scalar temp; temp = fmod(Value,TWO_PI); if (temp > PI) { temp -= TWO_PI; } else if (temp < -PI) { temp += TWO_PI; } return temp; } // //############################################################################# //############################################################################# // Radian& Radian::Normalize() { Check(this); angle = fmod(angle,TWO_PI); if (angle > PI) { angle -= TWO_PI; } else if (angle < -PI) { angle += TWO_PI; } return *this; } // //############################################################################# //############################################################################# // Radian& Radian::Lerp(const Radian &a,const Radian &b,Scalar t) { Scalar a1,a2; Check_Pointer(this); Check(&a); Check(&b); a1 = Radian::Normalize(a.angle); a2 = Radian::Normalize(b.angle); if (a2-a1 > PI) { a2 -= TWO_PI; } else if (a2-a1 < -PI) { a2 += TWO_PI; } angle = ::Lerp(a1, a2, t); return *this; } // //############################################################################# //############################################################################# // ostream& operator<<( ostream& stream, const Radian& radian ) { return stream << radian.angle << " rad"; } // //############################################################################# //############################################################################# // Logical Radian::TestInstance() const { return angle >= -100.0f && angle <= 100.0f; } #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile Degree *) { return False; } #endif // //############################################################################# //############################################################################# // ostream& operator<<( ostream& stream, const Degree& degree ) { return stream << degree.angle << " deg"; } // //############################################################################# //############################################################################# // Logical Degree::TestInstance() const { return True; } #if defined(USE_SIGNATURE) int Is_Signature_Bad(const volatile SinCosPair *) { return False; } #endif // //############################################################################# //############################################################################# // SinCosPair& SinCosPair::operator=(const Radian &radian) { Check_Pointer(this); Check(&radian); cosine = cos(radian); sine = sin(radian); #if defined(__BCPLUSPLUS__) cosine = cos(radian); // STUPID FUCKING BORLAND LIBRARY HACK!!!!! #endif Check(this); return *this; } // //############################################################################# //############################################################################# // ostream& operator<<( ostream& stream, const SinCosPair& pair ) { return stream << '{' << pair.cosine << ',' << pair.sine << '}'; } // //############################################################################# //############################################################################# // Logical SinCosPair::TestInstance() const { Scalar t = sine*sine + cosine*cosine; if (!Close_Enough(t,1.0f,0.001f)) { Dump(*this); Dump(t); return False; } return True; } #if defined(TEST_CLASS) # include "angle.tcp" #endif