/****************************************************************************** libx42.net - skinned vertex animation library (.NET API) Copyright (C) 2007 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA. ******************************************************************************/ #pragma once namespace Libx42 { namespace Math { public value struct Angle : public IFormattable { private: float rads; public: static Angle FromRadians( float radians ) { Angle ret; ret.rads = radians; return ret; } static Angle FromDegrees( float degrees ) { Angle ret; ret.rads = degrees * (3.14159265358979323846F / 180.0F); return ret; } property float AsRadians { float get( void ) { return rads; } } property float AsDegrees { float get( void ) { return rads * (180.0F / 3.14159265358979323846F); } } virtual String^ ToString( String^ format, IFormatProvider ^formatProvider ) { float value = AsDegrees; String^ units = "\x00B0"; if( format != nullptr ) { array< wchar_t > ^seps = gcnew array< wchar_t >( 2 ); seps[0] = L'*'; seps[1] = L'^'; int idx = format->LastIndexOfAny( seps ); if( idx != -1 ) { if( format[idx] == '*' ) { value = AsDegrees; units = "\x00B0"; } else { value = AsRadians; units = " rad"; } if( idx < format->Length - 1 ) units = format->Substring( idx + 1 ); format = format->Substring( 0, idx ); } } return String::Format( formatProvider, "{0}{1}", value.ToString( format, formatProvider ), units ); } String^ ToString( IFormatProvider ^formatProvider ) { return ToString( nullptr, formatProvider ); } virtual String^ ToString( void ) override { return ToString( nullptr ); } bool Equals( Angle q ) new; virtual bool Equals( Object ^obj ) override; static bool operator == ( Angle a, Angle b ) { return a.Equals( b ); } static bool operator != ( Angle a, Angle b ) { return !a.Equals( b ); } static Angle operator - ( Angle a ) { return Angle::FromRadians( -a.rads ); } static Angle operator + ( Angle a, Angle b ) { return Angle::FromRadians( a.rads + b.rads ); } static Angle operator - ( Angle a, Angle b ) { return Angle::FromRadians( a.rads - b.rads ); } static Angle operator * ( Angle a, float s ) { return Angle::FromRadians( a.rads * s ); } static Angle operator / ( Angle a, float s ) { return Angle::FromRadians( a.rads / s ); } static float operator / ( Angle a, Angle b ) { return a.rads / b.rads; } static property Angle Zero { Angle get( void ) { return Angle::FromRadians( 0 ); } } }; }; };