MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dualtransformconstraint.h
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 _physicsdualtransformconstraint_h
41 #define _physicsdualtransformconstraint_h
42 
43 #include "Physics/constraint.h"
44 
45 namespace Mezzanine
46 {
47  namespace Physics
48  {
49  ///////////////////////////////////////////////////////////////////////////////
50  /// @brief All constraints that track rotation and location of the Pivot relative to each Actor inherit from this.
51  /// @details Since not all contraints provide tracking for the Actor Transform (location/rotation of the pivot)
52  /// we subdivided the constraints to unify the interface of those that could be unified. This stores nothing, but
53  /// provides uniform access to the transform and rotation functions. \n \n
54  /// Any deriving class must implement every thing from TypedConstraint and the four set/get Transform function. It
55  /// is expected that more derived classes will implement the Set/Get Pivot/Rotation Functino in a more efficient
56  /// Manner if a more efficient way exists. The non-transform get/set function are implmented in terms of the
57  /// get/set transform function extra copies of values and extra reading/writing may occur if the compiler weakly
58  /// optimizes. Of course, implementing more functions could slow down the software if it no longer fits in CPU
59  /// caches. As always benchmark if this is something that may be critically slowing you down.
60  ///////////////////////////////////////////////////////////////////////////////
62  {
63  public:
64  /// @brief Set the Position and Rotation using a Transform
65  /// @param TranA The new Position and rotation
66  virtual void SetPivotATransform(const Transform& TranA) = 0;
67  /// @brief Set the Position and Rotation using a Transform
68  /// @param TranB The new Position and rotation
69  virtual void SetPivotBTransform(const Transform& TranB) = 0;
70  /// @brief Get the current Rotation and Location of Actor A
71  /// @return This returns a Mezzanine::Transform
72  virtual Transform GetPivotATransform() const = 0;
73  /// @brief Get the current Rotation and Location of Actor B
74  /// @return This returns a Mezzanine::Transform
75  virtual Transform GetPivotBTransform() const = 0;
76 
77  /// @brief Set The relative location of the pivot from ActorA's Center of gravity.
78  /// @param Location The New value for PivotA
79  /// @details Ultimately this information winds up being stored in the TransformA.
80  virtual void SetPivotALocation(const Vector3& Location)
81  { SetPivotATransform( Transform(Location, GetPivotARotation()) ); }
82  /// @brief Set The relative location of the pivot from ActorB's Center of gravity.
83  /// @param Location The New value for PivotB
84  /// @details Ultimately this information winds up being stored in the TransformB
85  virtual void SetPivotBLocation(const Vector3& Location)
86  { SetPivotBTransform( Transform(Location, GetPivotBRotation()) ); }
87  /// @brief Get the location of the pivot relative to ActorA's Center of gravity
88  /// @return A Vector3 with the pivot location.
89  virtual Vector3 GetPivotALocation() const
90  { return GetPivotATransform().Location; }
91  /// @brief Get the location of the pivot relative to ActorB's Center of gravity
92  /// @return A Vector3 with the pivot location.
93  virtual Vector3 GetPivotBLocation() const
94  { return GetPivotBTransform().Location; }
95 
96  /// @brief Set The relative rotation of ActorA
97  /// @param Rotation The new rotation amount for A
98  /// @details Ultimately this information winds up being stored in the TransformA
99  virtual void SetPivotARotation(const Quaternion& Rotation)
100  { SetPivotATransform( Transform(GetPivotALocation(), Rotation) ); }
101  /// @brief Set The relative rotation of ActorB
102  /// @param otation The new rotation amount for B
103  /// @details Ultimately this information winds up being stored in the TransformB
104  virtual void SetPivotBRotation(const Quaternion& Rotation)
105  { SetPivotBTransform( Transform(GetPivotBLocation(), Rotation) ); }
106  /// @brief Get the relative rotation for ActorA
107  /// @return A Quaternion that has the rotation
109  { return GetPivotATransform().Rotation; }
110  /// @brief Get the relative rotation for ActorB
111  /// @return A Quaternion that has the rotation
113  { return GetPivotBTransform().Rotation; }
114 
115  ///////////////////////////////////////////////////////////////////////////////
116  // DualTransformConstraint Serialization
117 
118  // Serializable
119  /// @brief Convert this class to an XML::Node ready for serialization
120  /// @param CurrentRoot The point in the XML hierarchy that all this vectorw should be appended to.
121  /// @details This stores each Actor's Transform
122  virtual void ProtoSerialize(XML::Node& CurrentRoot) const;
123 
124  // DeSerializable
125  /// @brief Take the data stored in an XML and overwrite this instance of this object with it
126  /// @param OneNode and XML::Node containing the data.
127  virtual void ProtoDeSerialize(const XML::Node& OneNode);
128 
129  /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
130  /// @return A string containing "DualTransformConstraint"
131  static String SerializableName();
132  };//DualTransformConstraint
133  }//Physics
134 }//Mezzanine
135 
136 ///////////////////////////////////////////////////////////////////////////////
137 // Class External << Operators for streaming or assignment
138 
139 /// @copydoc operator << (std::ostream& stream, const Mezzanine::Physics::Constraint& x)
140 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::Physics::DualTransformConstraint& x);
141 /// @copydoc operator >> (std::istream& stream, Mezzanine::Physics::Constraint& x)
142 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::Physics::DualTransformConstraint& x);
143 /// @copydoc operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Physics::Constraint& x)
144 void operator >> (const Mezzanine::XML::Node& OneNode, Mezzanine::Physics::DualTransformConstraint& x);
145 
146 #endif