MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
attachable.h
Go to the documentation of this file.
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 _attachable_h
41 #define _attachable_h
42 
43 #include "transform.h"
44 
45 /// @file attachable.h
46 /// @brief Contains the Mezzanine::Attachable Class and Mezzanine::Attachable::AttachableElement enumeration declarations
47 
48 namespace Mezzanine
49 {
50  class AttachableBase;
51  class AttachableParent;
52  class AttachableChild;
53  ///////////////////////////////////////////////////////////////////////////////
54  /// @class AttachableBase
55  /// @headerfile attachable.h
56  /// @brief This class is the base class for other attachable classes and is responsible for transform updates to attachables.
57  /// @details
58  ///////////////////////////////////////
60  {
61  protected:
62  bool Updating;
63  /// @internal
64  /// @brief Gets the update status of another attachable.
65  bool GetUpdating(AttachableBase* AB) const;
66  public:
67  /// @brief Class constructor.
69  /// @brief Class destructor.
70  virtual ~AttachableBase();
71 
72  ///////////////////////////////////////////////////////////////////////////////
73  // Conversion Functions
74 
75  /// @brief Converts a point in local space to the same point in global space.
76  /// @param Location The point in local space to be converted.
77  /// @return Returns a Vector3 representing the point in global space corresponding to the provided local space point.
78  Vector3 ConvertLocalToGlobal(const Vector3& Location) const;
79  /// @brief Converts a point in global space to the same point in local space.
80  /// @param Location The point in global space to be converted.
81  /// @return Returns a Vector3 representing the point in local space corresponding to the provided global space point.
82  Vector3 ConvertGlobalToLocal(const Vector3& Location) const;
83  /// @brief Converts a rotation in local space to the same rotation in global space.
84  /// @param Orientation The rotation in local space to be converted.
85  /// @return Returns a Quaternion representing the rotation in global space corresponding to the provided local space rotation.
86  Quaternion ConvertLocalToGlobal(const Quaternion& Orientation) const;
87  /// @brief Converts a rotation in global space to the same rotation in local space.
88  /// @param Orientation The rotation in global space to be converted.
89  /// @return Returns a Quaternion representing the rotation in local space corresponding to the provided global space rotation.
90  Quaternion ConvertGlobalToLocal(const Quaternion& Orientation) const;
91 
92  ///////////////////////////////////////////////////////////////////////////////
93  // Utility Functions
94  /// @brief Gets the name of this attachable.
95  /// @return Returns a const reference to a string containing the name of this attachable.
96  virtual ConstString& GetName() const = 0;
97  /// @brief Gets the type of World or Scene object this attachable is.
98  /// @return Returns the type of World or Scene object this attachable is.
99  virtual WorldObjectType GetType() const = 0;
100 
101  ///////////////////////////////////////////////////////////////////////////////
102  // Transform Functions
103 
104  /// @brief Sets the Location of this object.
105  /// @param Location A vector3 representing the location of this object.
106  virtual void SetLocation(const Vector3& Location) = 0;
107  /// @brief Gets the Location of this object.
108  /// @return Returns a vector3 representing the location of this object.
109  virtual Vector3 GetLocation() const = 0;
110  /// @brief Sets the orientation of this object.
111  /// @param Orientation A Quaternion representing the orientation of this object.
112  virtual void SetOrientation(const Quaternion& Orientation) = 0;
113  /// @brief Gets the orientation of this object.
114  /// @return Returns a quaternion representing the orientation of this object.
115  virtual Quaternion GetOrientation() const = 0;
116  /// @brief Sets the scale of this object.
117  /// @param Scale A vector3 representing the scale to be applied to this object.
118  virtual void SetScaling(const Vector3& Scale) = 0;
119  /// @brief Gets the scale of this object.
120  /// @return Returns a vector3 representing the scale being applied to this object.
121  virtual Vector3 GetScaling() const = 0;
122 
123  ///////////////////////////////////////////////////////////////////////////////
124  // Internal Methods
125  };//AttachableBase
126 
127  ///////////////////////////////////////////////////////////////////////////////
128  /// @class AttachableParent
129  /// @headerfile attachable.h
130  /// @brief Base class for objects that can have attachables attached to them.
131  /// @details
132  ///////////////////////////////////////
133  class MEZZ_LIB AttachableParent : virtual public AttachableBase
134  {
135  public:
136  /// @brief Basic container type for AttachableChild storage by this class.
137  typedef std::vector<AttachableChild*> AttachableContainer;
138  /// @brief Iterator type for AttachableChild instances stored by this class.
139  typedef AttachableContainer::iterator AttachableIterator;
140  /// @brief Const Iterator type for AttachableChild instances stored by this class.
141  typedef AttachableContainer::const_iterator ConstAttachableIterator;
142  protected:
143  /// @internal
144  /// @brief A container storing all of the other attachable objects connected to this attachable.
146  public:
147  #ifndef SWIG
148  /// @brief Class constructor.
150  #endif
151  /// @brief Class destructor.
152  virtual ~AttachableParent();
153 
154  ///////////////////////////////////////////////////////////////////////////////
155  // Attachment child management
156 
157  /// @brief Attaches an attachable element to this object.
158  /// @param Target The Attachable to be attached.
159  virtual void AttachObject(AttachableChild* Target);
160  /// @brief Detaches an attachable element from this object.
161  /// @param Target The Attachable to be detached.
162  /// @details Detach an item is done in linear time relative to the amount of attached items.
163  virtual void DetachObject(AttachableChild* Target);
164  /// @brief Detaches all attachables currently attached.
165  virtual void DetachAllChildren();
166  /// @brief Gets the number of elements attached to this object.
167  /// @return Returns the number of elements attached to this object.
168  virtual Whole GetNumAttached() const;
169  /// @brief Get a specific attached Item
170  /// @param Index A number indicating which Attachable you want a pointer to. The WorldNode is like an Array starts at 0 and goes to WorldNode::GetNumAttached() - 1.
171  /// @return A pointer to an Attachable Item attached to this.
172  /// @throw This can throw an out of bounds std::exception if used incorrectly.
173  virtual AttachableChild* GetAttached(const Whole& Index) const;
174  /// @brief Get an AttachableIterator to the first object.
175  /// @return An Iterator to the first object.
176  AttachableIterator BeginChild();
177  /// @brief Get an AttachableIterator to one past the last object.
178  /// @return An Iterator to one past the last object.
179  AttachableIterator EndChild();
180 
181 //#if !(defined(SWIG) && defined(MEZZLUA51)) // Stop Swig from making lua bindings but allow other languages
182 #ifndef SWIG // Since these functions differ only by constness, they make no sense to most(all?) scripting languages
183  /// @brief Get a ConstAttachableIterator to the first object.
184  /// @return An Iterator to the first object.
185  ConstAttachableIterator BeginChild() const;
186  /// @brief Get a ConstAttachableIterator to one past the last object.
187  /// @return An Iterator to one past the last object.
188  ConstAttachableIterator EndChild() const;
189 #endif
190 
191  ///////////////////////////////////////////////////////////////////////////////
192  // Internal Methods
193 
194  /// @brief Recalculates the transforms of all children of this attachable.
195  void _RecalculateAllChildTransforms();
196  };//AttachableParent
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  /// @class AttachableChild
200  /// @headerfile attachable.h
201  /// @brief This class is the base class for objects that can be attached to AttachableParent.
202  /// @details
203  ///////////////////////////////////////
204  class MEZZ_LIB AttachableChild : virtual public AttachableBase
205  {
206  protected:
207  friend class AttachableParent;
208  AttachableParent* Parent;
209  bool LocalTransformDirty;
210  bool GlobalTransformDirty;
211  Transform LocalXform;
212  public:
213  /// @brief Class constructor.
214  AttachableChild();
215  /// @brief Class destructor.
216  virtual ~AttachableChild();
217 
218  ///////////////////////////////////////////////////////////////////////////////
219  // Utility Functions
220 
221  /// @brief Gets the parent of this child.
222  /// @return Returns a pointer to the parent this object is attached to or NULL if it's not attached to anything.
223  AttachableParent* GetParent() const;
224 
225  ///////////////////////////////////////////////////////////////////////////////
226  // Transform Functions
227 
228  /// @brief Sets the Location of this object in local space.
229  /// @param Location A vector3 representing the location of this object.
230  virtual void SetLocalLocation(const Vector3& Location) = 0;
231  /// @brief Gets the Location of this object in local space.
232  /// @return Returns a vector3 representing the location of this object.
233  Vector3 GetLocalLocation() const;
234  /// @brief Sets the orientation of this object in local space.
235  /// @param Orientation A Quaternion representing the orientation of this object.
236  virtual void SetLocalOrientation(const Quaternion& Orientation) = 0;
237  /// @brief Gets the orientation of this object in local space.
238  /// @return Returns a quaternion representing the orientation of this object.
239  Quaternion GetLocalOrientation() const;
240 
241  ///////////////////////////////////////////////////////////////////////////////
242  // Internal Methods
243 
244  /// @brief Recalculates objects global transform from parent.
245  /// @param FromParent Whether this is being invoked from the parent of this attachable.
246  void _RecalculateGlobalTransform(bool FromParent = false);
247  /// @brief Recalculates this objects local transform based on it's current global position.
248  void _RecalculateLocalTransform();
249  };//AttachableChild
250 }//Mezzanine
251 
252 #endif