mAngAxis.h

Engine/source/math/mAngAxis.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _MANGAXIS_H_
 25#define _MANGAXIS_H_
 26
 27#ifndef _MPOINT3_H_
 28#include "math/mPoint3.h"
 29#endif
 30
 31class MatrixF;
 32class QuatF;
 33
 34//----------------------------------------------------------------------------
 35// rotation about an arbitrary axis through the origin:
 36
 37class AngAxisF
 38{
 39  public:
 40   Point3F axis;
 41   F32  angle;
 42
 43   AngAxisF();
 44   AngAxisF( const Point3F & _axis, F32 _angle );
 45   explicit AngAxisF( const MatrixF &m );
 46   explicit AngAxisF( const QuatF &q );
 47
 48   AngAxisF& set( const Point3F & _axis, F32 _angle );
 49   AngAxisF& set( const MatrixF & m );
 50   AngAxisF& set( const QuatF & q );
 51
 52   bool operator==( const AngAxisF & c ) const;
 53   bool operator!=( const AngAxisF & c ) const;
 54
 55   MatrixF * setMatrix( MatrixF * mat ) const;
 56
 57   static void RotateX(F32 angle, MatrixF * mat);
 58   static void RotateY(F32 angle, MatrixF * mat);
 59   static void RotateZ(F32 angle, MatrixF * mat);
 60
 61   static void RotateX(F32 angle, const Point3F & from, Point3F * to);
 62   static void RotateY(F32 angle, const Point3F & from, Point3F * to);
 63   static void RotateZ(F32 angle, const Point3F & from, Point3F * to);
 64};
 65
 66//----------------------------------------------------------------------------
 67// AngAxisF implementation:
 68
 69inline AngAxisF::AngAxisF()
 70{
 71   axis = Point3F(0.0f,0.0f,1.0f);
 72   angle = 0.0f;
 73}
 74
 75inline AngAxisF::AngAxisF( const Point3F & _axis, F32 _angle )
 76{
 77   set(_axis,_angle);
 78}
 79
 80inline AngAxisF::AngAxisF( const MatrixF & mat )
 81{
 82   set(mat);
 83}
 84
 85inline AngAxisF::AngAxisF( const QuatF & quat )
 86{
 87   set(quat);
 88}
 89
 90inline AngAxisF& AngAxisF::set( const Point3F & _axis, F32 _angle )
 91{
 92   axis = _axis;
 93   angle = _angle;
 94   return *this;
 95}
 96
 97inline bool AngAxisF::operator==( const AngAxisF & c ) const
 98{
 99   return mFabs(angle-c.angle) < 0.0001f && (axis == c.axis);
100}
101
102inline bool AngAxisF::operator!=( const AngAxisF & c ) const
103{
104   return !(*this == c);
105}
106
107#endif // _MANGAXIS_H_
108