MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bone.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _graphicsbone_cpp
41 #define _graphicsbone_cpp
42 
43 #include "Graphics/skeleton.h"
44 #include "Graphics/bone.h"
45 
46 #include <Ogre.h>
47 
48 namespace Mezzanine
49 {
50  namespace Graphics
51  {
52  namespace
53  {
54  /// @internal
55  /// @brief Converts the transform space used by this class to the internal type.
56  Ogre::Node::TransformSpace ConvertTransformSpace(const Mezzanine::TransformSpace Space)
57  {
58  switch(Space)
59  {
60  case Mezzanine::TS_Local: return Ogre::Node::TS_LOCAL;
61  case Mezzanine::TS_Parent: return Ogre::Node::TS_PARENT;
62  case Mezzanine::TS_World: return Ogre::Node::TS_WORLD;
63  }
64  return Ogre::Node::TS_WORLD;
65  }
66  }
67 
68  Bone::Bone(Skeleton* HostSkel, Ogre::Bone* InternalBone)
69  : GraphicsBone(InternalBone),
70  Host(HostSkel)
71  {
72  Ogre::Any OgreRef(this);
73  GraphicsBone->setUserAny(OgreRef);
74  }
75 
77  {
78  }
79 
80  ///////////////////////////////////////////////////////////////////////////////
81  // Utility Methods
82 
84  { return this->Host; }
85 
86  const String& Bone::GetName() const
87  { return this->GraphicsBone->getName(); }
88 
90  { return this->GraphicsBone->getHandle(); }
91 
92  void Bone::SetManuallyControlled(bool Manual)
93  { this->GraphicsBone->setManuallyControlled(Manual); }
94 
96  { return this->GraphicsBone->isManuallyControlled(); }
97 
98  ///////////////////////////////////////////////////////////////////////////////
99  // Child Methods
100 
101  Bone* Bone::CreateChild(const UInt16 Handle, const Vector3& Trans, const Quaternion& Rot)
102  { return this->Host->_CreateBoneWrapper( this->GraphicsBone->createChild( Handle, Trans.GetOgreVector3(), Rot.GetOgreQuaternion() ) ); }
103 
105  { return this->GraphicsBone->numChildren(); }
106 
107  Bone* Bone::GetChild(const UInt16 Index) const
108  { return Ogre::any_cast<Bone*>( this->GraphicsBone->getChild(Index)->getUserAny() ); }
109 
110  Bone* Bone::GetChild(const String& Name) const
111  { return Ogre::any_cast<Bone*>( this->GraphicsBone->getChild(Name)->getUserAny() ); }
112 
113  void Bone::RemoveChild(Bone* ToBeRemoved)
114  { this->GraphicsBone->removeChild( ToBeRemoved->_GetInternalBone() ); }
115 
116  void Bone::RemoveChild(const UInt16 Index)
117  { this->GraphicsBone->removeChild( Index ); }
118 
119  void Bone::RemoveChild(const String& Name)
120  { this->GraphicsBone->removeChild( Name ); }
121 
122  ///////////////////////////////////////////////////////////////////////////////
123  // Transform Methods
124 
125  void Bone::SetLocation(const Vector3& Loc)
126  { this->GraphicsBone->setPosition( Loc.GetOgreVector3() ); }
127 
128  void Bone::SetLocation(const Real X, const Real Y, const Real Z)
129  { this->GraphicsBone->setPosition(X,Y,Z); }
130 
132  { return Vector3( this->GraphicsBone->getPosition() ); }
133 
135  { this->GraphicsBone->setOrientation( Ori.GetOgreQuaternion() ); }
136 
137  void Bone::SetOrientation(const Real X, const Real Y, const Real Z, const Real W)
138  { this->GraphicsBone->setOrientation(W,X,Y,Z); }
139 
141  { return Quaternion( this->GraphicsBone->getOrientation() ); }
142 
143  void Bone::SetScale(const Vector3& Sc)
144  { this->GraphicsBone->setScale( Sc.GetOgreVector3() ); }
145 
146  void Bone::SetScale(const Real X, const Real Y, const Real Z)
147  { this->GraphicsBone->setScale(X,Y,Z); }
148 
150  { return Vector3( this->GraphicsBone->getScale() ); }
151 
152  void Bone::Translate(const Vector3& Trans, const Mezzanine::TransformSpace Space)
153  { this->GraphicsBone->translate( Trans.GetOgreVector3(), ConvertTransformSpace(Space) ); }
154 
155  void Bone::Translate(const Real X, const Real Y, const Real Z, const Mezzanine::TransformSpace Space)
156  { this->GraphicsBone->translate( X, Y, Z, ConvertTransformSpace(Space) ); }
157 
158  void Bone::Yaw(const Real Angle, const Mezzanine::TransformSpace Space)
159  { this->GraphicsBone->yaw( Ogre::Radian(Angle), ConvertTransformSpace(Space) ); }
160 
161  void Bone::Pitch(const Real Angle, const Mezzanine::TransformSpace Space)
162  { this->GraphicsBone->pitch( Ogre::Radian(Angle), ConvertTransformSpace(Space) ); }
163 
164  void Bone::Roll(const Real Angle, const Mezzanine::TransformSpace Space)
165  { this->GraphicsBone->roll( Ogre::Radian(Angle), ConvertTransformSpace(Space) ); }
166 
167  void Bone::Rotate(const Vector3& Axis, const Real Angle, const Mezzanine::TransformSpace Space)
168  { this->GraphicsBone->rotate( Axis.GetOgreVector3(), Ogre::Radian(Angle), ConvertTransformSpace(Space) ); }
169 
170  void Bone::Rotate(const Quaternion& Rotation, const Mezzanine::TransformSpace Space)
171  { this->GraphicsBone->rotate( Rotation.GetOgreQuaternion(), ConvertTransformSpace(Space) ); }
172 
173  void Bone::Scale(const Vector3& Scale)
174  { this->GraphicsBone->scale( Scale.GetOgreVector3() ); }
175 
176  void Bone::Scale(const Real X, const Real Y, const Real Z)
177  { this->GraphicsBone->scale(X,Y,Z); }
178 
179  ///////////////////////////////////////////////////////////////////////////////
180  // Internal Methods
181 
182  Ogre::Bone* Bone::_GetInternalBone() const
183  { return this->GraphicsBone; }
184  }//Graphics
185 }//Mezzanine
186 
187 #endif