Spinning Topp Logo BlackTopp Studios
inc
bone.cpp
1 // © Copyright 2010 - 2016 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 
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
Ogre::Bone * _GetInternalBone() const
Gets the internal bone pointer.
Definition: bone.cpp:182
UInt16 GetNumChildren() const
Gets the number of child bones contained by this bone.
Definition: bone.cpp:104
World space.
Definition: enumerations.h:142
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
Vector3 GetScale() const
Gets the scaling currently being applied to this object.
Definition: bone.cpp:149
UInt16 GetHandle() const
Gets the unique identifying number belonging to this bone.
Definition: bone.cpp:89
void Roll(const Real Angle, const Mezzanine::TransformSpace Space=Mezzanine::TS_Parent)
Rotate the object around the Z axis.
Definition: bone.cpp:164
Skeleton * GetHost() const
Gets the host skeleton this bone belongs to.
Definition: bone.cpp:83
void SetManuallyControlled(Boole Manual)
Sets whether or not this bone is to be manually controlled.
Definition: bone.cpp:92
Local space, aka the object in questions world position is used as origin.
Definition: enumerations.h:140
Quaternion GetOrientation() const
Gets this objects current orientation.
Definition: bone.cpp:140
void Yaw(const Real Angle, const Mezzanine::TransformSpace Space=Mezzanine::TS_Parent)
Rotate the object around the Y axis.
Definition: bone.cpp:158
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
const String & GetName() const
Gets the name of this Bone.
Definition: bone.cpp:86
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
Bone * _CreateBoneWrapper(Ogre::Bone *InternalBone)
Creates a bone wrapper for a pre-made internal bone.
Definition: skeleton.cpp:135
Ogre::Quaternion GetOgreQuaternion(Boole normalize=false) const
Gets a Ogre quaternion.
Definition: quaternion.cpp:263
Bone * CreateChild(const UInt16 Handle, const Vector3 &Trans, const Quaternion &Rot)
Creates a new bone in the parent skeleton as a child of this bone.
Definition: bone.cpp:101
void Scale(const Vector3 &Scale)
Scales the object from it's current size.
Definition: bone.cpp:173
void SetScale(const Vector3 &Sc)
Sets the scaling to be applied to this object.
Definition: bone.cpp:143
void SetLocation(const Vector3 &Loc)
Sets the location of this object in parent space.
Definition: bone.cpp:125
Ogre::Vector3 GetOgreVector3() const
Gets a Ogre vector3.
Definition: vector3.cpp:572
Ogre::Bone * GraphicsBone
The pointer to the internal Bone this is based on.
Definition: bone.h:65
void Rotate(const Vector3 &Axis, const Real Angle, const Mezzanine::TransformSpace Space=Mezzanine::TS_Parent)
Rotates the object from it's existing rotation.
Definition: bone.cpp:167
Bone * GetChild(const UInt16 Index) const
Gets a child bone by it's index.
Definition: bone.cpp:107
This class encapsulates the bones contained in a skeleton used for animation.
Definition: bone.h:59
void RemoveChild(Bone *ToBeRemoved)
Removes a bone from this bone.
Definition: bone.cpp:113
This class encapsulates the Skeletal animation functionality of a Mesh.
Definition: skeleton.h:63
Bone(Skeleton *HostSkel, Ogre::Bone *InternalBone)
Internal constructor.
Definition: bone.cpp:68
This is used to represent a point in space, or a vector through space.
Definition: vector3.h:77
Mostly reserved for rotations, means a rotation to occur around the parent instead of self...
Definition: enumerations.h:141
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
TransformSpace
Used to define what frame of reference is to be used when positioning or rotating objects...
Definition: enumerations.h:138
void Pitch(const Real Angle, const Mezzanine::TransformSpace Space=Mezzanine::TS_Parent)
Rotate the object around the X axis.
Definition: bone.cpp:161
void SetOrientation(const Quaternion &Ori)
Sets the orientation of this object in parent space.
Definition: bone.cpp:134
This is used to store information about rotation in 3d space.
Definition: quaternion.h:68
Vector3 GetLocation() const
Gets this objects current location.
Definition: bone.cpp:131
Skeleton * Host
The host skeleton this bone belongs to.
Definition: bone.h:68
~Bone()
Class destructor.
Definition: bone.cpp:76
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
Boole GetManuallyControlled() const
Gets whether or not this bone is being manually controlled.
Definition: bone.cpp:95
void Translate(const Vector3 &Trans, const Mezzanine::TransformSpace Space=Mezzanine::TS_Parent)
Moves this object from it's current location.
Definition: bone.cpp:152