mAngAxis.cpp

Engine/source/math/mAngAxis.cpp

More...

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#include "math/mAngAxis.h"
25#include "math/mQuat.h"
26#include "math/mMatrix.h"
27
28AngAxisF & AngAxisF::set( const QuatF & q )
29{
30   angle = 2.0f * mAcos( q.w );
31   F32 sinHalfAngle = mSqrt(q.x * q.x + q.y * q.y + q.z * q.z);
32   if (sinHalfAngle != 0.0f)
33      axis.set( q.x / sinHalfAngle, q.y / sinHalfAngle, q.z / sinHalfAngle );
34   else
35      axis.set(1.0f,0.0f,0.0f);
36   return *this;
37}
38
39AngAxisF & AngAxisF::set( const MatrixF & mat )
40{
41   QuatF q( mat );
42   set( q );
43   return *this;
44}
45
46MatrixF * AngAxisF::setMatrix( MatrixF * mat ) const
47{
48   QuatF q( *this );
49   return q.setMatrix( mat );
50}
51
52void AngAxisF::RotateX(F32 angle, MatrixF * mat)
53{
54   // for now...do it the easy way
55   AngAxisF rotX(Point3F(1.0f,0.0f,0.0f),angle);
56   rotX.setMatrix(mat);
57}
58
59void AngAxisF::RotateY(F32 angle, MatrixF * mat)
60{
61   // for now...do it the easy way
62   AngAxisF rotY(Point3F(0.0f,1.0f,0.0f),angle);
63   rotY.setMatrix(mat);
64}
65
66void AngAxisF::RotateZ(F32 angle, MatrixF * mat)
67{
68   // for now...do it the easy way
69   AngAxisF rotZ(Point3F(0.0f,0.0f,1.0f),angle);
70   rotZ.setMatrix(mat);
71}
72
73void AngAxisF::RotateX(F32 angle, const Point3F & from, Point3F * to)
74{
75   // for now...do it the easy way
76   MatrixF mat;
77   AngAxisF::RotateX(angle,&mat);
78   mat.mulV(from,to);
79}
80
81void AngAxisF::RotateY(F32 angle, const Point3F & from, Point3F * to)
82{
83   // for now...do it the easy way
84   MatrixF mat;
85   AngAxisF::RotateY(angle,&mat);
86   mat.mulV(from,to);
87}
88
89void AngAxisF::RotateZ(F32 angle, const Point3F & from, Point3F * to)
90{
91   // for now...do it the easy way
92   MatrixF mat;
93   AngAxisF::RotateZ(angle,&mat);
94   mat.mulV(from,to);
95}
96
97