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}
 72
 73inline AngAxisF::AngAxisF( const Point3F & _axis, F32 _angle )
 74{
 75   set(_axis,_angle);
 76}
 77
 78inline AngAxisF::AngAxisF( const MatrixF & mat )
 79{
 80   set(mat);
 81}
 82
 83inline AngAxisF::AngAxisF( const QuatF & quat )
 84{
 85   set(quat);
 86}
 87
 88inline AngAxisF& AngAxisF::set( const Point3F & _axis, F32 _angle )
 89{
 90   axis = _axis;
 91   angle = _angle;
 92   return *this;
 93}
 94
 95inline bool AngAxisF::operator==( const AngAxisF & c ) const
 96{
 97   return mFabs(angle-c.angle) < 0.0001f && (axis == c.axis);
 98}
 99
100inline bool AngAxisF::operator!=( const AngAxisF & c ) const
101{
102   return !(*this == c);
103}
104
105#endif // _MANGAXIS_H_
106