MezzanineEngine March 18, 2012

actorphysicssettings.h

00001 //© Copyright 2010 - 2011 BlackTopp Studios Inc.
00002 /* This file is part of The Mezzanine Engine.
00003 
00004     The Mezzanine Engine is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     The Mezzanine Engine is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with The Mezzanine Engine.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 /* The original authors have included a copy of the license specified above in the
00018    'Docs' folder. See 'gpl.txt'
00019 */
00020 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
00021    Build professional software and charge for their product.
00022 
00023    However there are some practical restrictions, so if your project involves
00024    any of the following you should contact us and we will try to work something
00025    out:
00026     - DRM or Copy Protection of any kind(except Copyrights)
00027     - Software Patents You Do Not Wish to Freely License
00028     - Any Kind of Linking to Non-GPL licensed Works
00029     - Are Currently In Violation of Another Copyright Holder's GPL License
00030     - If You want to change our code and not add a few hundred MB of stuff to
00031         your distribution
00032 
00033    These and other limitations could cause serious legal problems if you ignore
00034    them, so it is best to simply contact us or the Free Software Foundation, if
00035    you have any questions.
00036 
00037    Joseph Toppi - toppij@gmail.com
00038    John Blackwood - makoenergy02@gmail.com
00039 */
00040 #ifndef _actorphysicssettings_h
00041 #define _actorphysicssettings_h
00042 
00043 #include "transform.h"
00044 #include "enumerations.h"
00045 #include "worldobjectphysicssettings.h"
00046 
00047 #ifdef MEZZXML
00048 #include "xml.h"
00049 #include <iostream>
00050 #endif
00051 
00052 class btCollisionObject;
00053 class btRigidBody;
00054 class btSoftBody;
00055 
00056 namespace Mezzanine
00057 {
00058     class ActorBase;
00059     class ActorRigid;
00060     class ActorSoft;
00061     class ActorTerrain;
00062     class Collision;
00063     class CollisionShape;
00064     class Generic6DofConstraint;
00065     class SliderConstraint;
00066 
00067     typedef Generic6DofConstraint StickyConstraint;
00068     /// @struct StickyConstraintConstructionInfo
00069     /// @headerfile actorphysicssettings.h
00070     /// @brief Simple struct for holding information on how sticky constraints should be constructed.
00071     struct MEZZ_LIB StickyConstraintConstructionInfo
00072     {
00073         Transform TransA;
00074         Transform TransB;
00075         ActorRigid* ActA;
00076         ActorRigid* ActB;
00077 
00078         StickyConstraintConstructionInfo()
00079         {
00080             this->ActA = NULL;
00081             this->ActB = NULL;
00082         }
00083         StickyConstraintConstructionInfo(const StickyConstraintConstructionInfo& Other)
00084         {
00085             this->TransA = Other.TransA;
00086             this->TransB = Other.TransB;
00087             this->ActA = Other.ActA;
00088             this->ActB = Other.ActB;
00089         }
00090     };//stickyconstraintconstructioninfo
00091     /// @struct StickyData
00092     /// @headerfile actorphysicssettings.h
00093     /// @brief This is a basic class for storing the data related to the sticky behavior available to actorrigid's.
00094     struct MEZZ_LIB StickyData
00095     {
00096         StickyData() : MaxNumContacts(0) {};
00097         std::vector<StickyConstraint*> StickyConstraints;
00098         std::vector<StickyConstraintConstructionInfo> CreationQueue;
00099         Whole MaxNumContacts;
00100     };//stickydata
00101 
00102     ///////////////////////////////////////////////////////////////////////////////
00103     /// @class ActorBasePhysicsSettings
00104     /// @headerfile actorphysicssettings.h
00105     /// @brief This is a base helper class for configuring physics settings of an actor.
00106     /// @details This class contains functions for the configuring of physics specific settings of an actor.
00107     /// This class can only configure the actors physics.  For configuring actor graphics, see ActorGraphicsSettings.
00108     ///////////////////////////////////////
00109     class MEZZ_LIB ActorBasePhysicsSettings : public NonTriggerPhysicsSettings
00110     {
00111         protected:
00112         public:
00113             /// @brief Standard Constructor.
00114             /// @param Actor The actor this settings class configures.
00115             /// @param PhysicsObject The physics object belonging to the actor this class configures.
00116             ActorBasePhysicsSettings(ActorBase* Actor, btCollisionObject* PhysicsObject);
00117 
00118             /// @brief Class destructor.
00119             virtual ~ActorBasePhysicsSettings();
00120 
00121             /// @brief Sets the parameters used for Continuous Collision Detection.
00122             /// @details If a Swept Sphere Radius is not provided, this function will attempt to find one for you using the currently set Collision Shape.
00123             /// If this fails for any reason or a shape is not set, it will set the radius to 1.
00124             /// @param MotionThreshold The speed at which the object has to be moving in order to enable CCD for the object.  If set to zero CCD will be disabled.
00125             /// @param SweptSphereRadius The radius of the sphere to be used for CCD sweep tests.  Essentially this should be the largest radius in which a sphere can fully fit inside your object.
00126             virtual void SetCCDParams(const Real& MotionThreshold, const Real& SweptSphereRadius = 0);
00127 
00128             /// @brief Gets the amount of motion needed to enable CCD for this object.
00129             /// @return Returns a Real representing the required amount of motion to enable CCD, or zero if CCD is disabled.
00130             virtual Real GetCCDMotionThreshold() const;
00131 
00132             /// @brief Gets the radius of the embedded sphere used for CCD.
00133             /// @return Returns a Real representing the radius of the sphere embedded into the objects collision shape used for CCD.
00134             virtual Real GetCCDSphereRadius() const;
00135 
00136             /// @brief Sets the state of the object to Kinematic.
00137             /// @details This function will set the object to a Kinematic Object. @n
00138             /// Kinematic Objects are like Static Objects but are also able to be moved directly by character controllers.
00139             virtual void SetKinematic();
00140 
00141             /// @brief Sets the state of the object to Static.
00142             /// @details This function will set the object to a Static Object. @n
00143             /// Static Objects don't move or have any force applied to them, but are cabable of exerting force on other objects.
00144             virtual void SetStatic();
00145 
00146             /// @internal
00147             /// @brief Get a pointer to this class of type ActorBasePhysicsSettings
00148             /// @return A pointer ActorBasePhysicsSettings
00149             ActorBasePhysicsSettings* GetBasePointer();
00150 
00151 #ifdef MEZZXML
00152             ///////////////////////////////////////////////////////////////////////////////
00153             // Serialization
00154 
00155             // Serializable
00156             /// @brief Convert this class to an xml::Node ready for serialization
00157             /// @param CurrentRoot The point in the XML hierarchy that all this quaternion should be appended to.
00158             virtual void ProtoSerialize(xml::Node& CurrentRoot) const;
00159 
00160             // DeSerializable
00161             /// @brief Take the data stored in an XML and overwrite this instance of this object with it
00162             /// @param OneNode and xml::Node containing the data.
00163             virtual void ProtoDeSerialize(const xml::Node& OneNode);
00164 
00165             /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
00166             /// @return A string containing "ActorBasePhysicsSettings"
00167             static String SerializableName();
00168 #endif
00169 
00170     };//actorbasephysicssettings
00171 
00172     ///////////////////////////////////////////////////////////////////////////////
00173     /// @class ActorRigidPhysicsSettings
00174     /// @headerfile actorphysicssettings.h
00175     /// @brief This is a helper class for configuring physics settings of an ActorRigid.
00176     /// @details This class contains functions for the configuring of physics specific settings of an ActorRigid.
00177     /// This class can only configure the ActorRigids physics.  For configuring actor graphics, see ActorGraphicsSettings.
00178     ///////////////////////////////////////
00179     class MEZZ_LIB ActorRigidPhysicsSettings : public ActorBasePhysicsSettings
00180     {
00181         protected:
00182             /// @internal
00183             /// @brief Physics Object of the actor.
00184             btRigidBody* ActorRB;
00185             /// @brief The Actor this belongs to.
00186             ActorRigid* RigidParent;
00187             /// @brief Data related to sticky behavior, if any is enabled.
00188             StickyData* StickyContacts;
00189         public:
00190             /// @brief Standard Constructor.
00191             /// @param Actor The actor this settings class configures.
00192             /// @param PhysicsObject The physics object belonging to the actor this class configures.
00193             ActorRigidPhysicsSettings(ActorRigid* Actor, btRigidBody* PhysicsObject);
00194 
00195             /// @brief Class destructor.
00196             virtual ~ActorRigidPhysicsSettings();
00197 
00198             /// @brief Sets the collision shape to be used.
00199             /// @param Shape The shape to be applied.
00200             virtual void SetCollisionShape(CollisionShape* Shape);
00201 
00202             /// @brief Sets the basic parameters for enabling sticky behavior with this actor.
00203             /// @param MaxNumContacts The maximum number of object this object can stick to or have stuck to it.
00204             virtual void SetStickyData(const Whole& MaxNumContacts);
00205             /// @brief Removes all the constraints currently active on this object
00206             virtual void ClearStickyContacts();
00207             /// @brief Gets the struct storing the data related to sticky behavior.
00208             /// @return Returns a pointer to the struct storing the sticky data for this actor.
00209             virtual StickyData* GetStickyData() const;
00210 
00211             /// @brief Sets the Damping for this object.
00212             /// @details Both of Linear Damping and Angular Damping default to zero.  This is useful if you wish to simulate
00213             /// something like air resistance.  Values can range from 0.0 to 1.0.
00214             /// @param LinDamping Real representing the amount of Linear Damping(Movement) to be applied.
00215             /// @param AngDamping Real representing the amount of Angular Damping(Rotation) to be applied.
00216             virtual void SetDamping(const Real& LinDamping, const Real& AngDamping);
00217             /// @brief Get the linear damping
00218             /// @return A Real that has the Linear damping.
00219             virtual Real GetLinearDamping() const;
00220             /// @brief Get the Angular damping
00221             /// @return A Real that has the Angular damping.
00222             virtual Real GetAngularDamping() const;
00223 
00224             /// @brief Sets the Linear Velocity of this object.
00225             /// @param LinVel Vector3 representing the Linear Velocity to be set.
00226             virtual void SetLinearVelocity(const Vector3& LinVel);
00227             /// @brief Gets the Linear Velocity of this object.
00228             /// @return Returns the currently set Linear Velocity of this object.
00229             virtual Vector3 GetLinearVelocity() const;
00230 
00231             /// @brief Sets the Angular Velocity of this object.
00232             /// @param AngVel Vector3 representing the Angular Velocity to be set.
00233             virtual void SetAngularVelocity(const Vector3& AngVel);
00234             /// @brief Gets the Angular Velocity of this object.
00235             /// @return Returns the currently set Angular Velocity of this object.
00236             virtual Vector3 GetAngularVelocity() const;
00237 
00238             /// @brief Sets the gravity for only this object.
00239             /// @details This value will override the world gravity.  Should be called after adding to the world.
00240             /// When the object is added to the world the world gravity is applied to it.
00241             /// @param Gravity Vector3 representing the direction and strength of gravity to be applied.
00242             virtual void SetIndividualGravity(const Vector3& Gravity);
00243             /// @brief Gets the gravity being applied to this object.
00244             /// @details This is the gravity applied to this object, which may or may not be the same as the world gravity.
00245             /// @return Returns a Vector3 representing the gravity currently being applied to this object.
00246             virtual Vector3 GetIndividualGravity() const;
00247 
00248             /// @brief Get the total Force/Movement on the actor
00249             /// @return A Vector3 with the force of the entire Actor
00250             virtual Vector3 GetForce() const;
00251             /// @brief Get the Torque/Rotation
00252             /// @return A Vector3 with the Torque
00253             virtual Vector3 GetTorque() const;
00254             /// @brief Push/Apply force to an object.
00255             /// @param Force The amount and direction of the force in a Vector3
00256             virtual void ApplyForce(const Vector3& Force);
00257             /// @brief Spin/Apply Torque to an object.
00258             /// @param Torque The amount and direction of the torque in a Vector3
00259             virtual void ApplyTorque(const Vector3& Torque);
00260 
00261             /// @brief Get the total Mass of the actor
00262             /// @return A Real with the Mass of the Actor
00263             virtual Real GetMass() const;
00264             /// @brief Get the current intertia of the Actor
00265             /// @return A Vector3 with the Inertia
00266             virtual Vector3 GetLocalInertia() const;
00267             /// @brief Change the mass of the object.
00268             /// @param NewMass The amount of mass this should have.
00269             virtual void SetMass(Real NewMass);
00270             /// @brief Change the mass of the object.
00271             /// @param NewMass The amount of mass this should have.
00272             /// @param NewInertia The new inertia the object has.
00273             virtual void SetMass(Real NewMass, const Vector3& NewInertia);
00274 
00275 #ifdef MEZZXML
00276             ///////////////////////////////////////////////////////////////////////////////
00277             // Serialization
00278 
00279             // Serializable
00280             /// @brief Convert this class to an xml::Node ready for serialization
00281             /// @param CurrentRoot The point in the XML hierarchy that all this quaternion should be appended to.
00282             virtual void ProtoSerialize(xml::Node& CurrentRoot) const;
00283 
00284             // DeSerializable
00285             /// @brief Take the data stored in an XML and overwrite this instance of this object with it
00286             /// @param OneNode and xml::Node containing the data.
00287             virtual void ProtoDeSerialize(const xml::Node& OneNode);
00288 
00289             /// @brief Get the name of the the XML tag this class will leave behind as its instances are serialized.
00290             /// @return A string containing "ActorRigidPhysicsSettings"
00291             static String SerializableName();
00292 #endif
00293     };//actorrigidphysicssettings
00294 
00295     ///////////////////////////////////////////////////////////////////////////////
00296     /// @class ActorSoftPhysicsSettings
00297     /// @headerfile actorphysicssettings.h
00298     /// @brief This is a helper class for configuring physics settings of an ActorSoft.
00299     /// @details This class contains functions for the configuring of physics specific settings of an ActorSoft.
00300     /// This class can only configure the ActorSofts physics.  For configuring actor graphics, see ActorGraphicsSettings.
00301     ///////////////////////////////////////
00302     class MEZZ_LIB ActorSoftPhysicsSettings : public ActorBasePhysicsSettings
00303     {
00304         protected:
00305             /// @internal
00306             /// @brief Physics Object of the actor.
00307             btSoftBody* ActorSB;
00308             /// @brief The Actor this belongs to.
00309             ActorSoft* SoftParent;
00310         public:
00311             /// @brief Standard Constructor.
00312             /// @param Actor The actor this settings class configures.
00313             /// @param PhysicsObject The physics object belonging to the actor this class configures.
00314             ActorSoftPhysicsSettings(ActorSoft* Actor, btSoftBody* PhysicsObject);
00315 
00316             /// @brief Class destructor.
00317             virtual ~ActorSoftPhysicsSettings();
00318 
00319             /// @brief Sets the collision shape to be used.
00320             /// @param Shape The shape to be applied.
00321             virtual void SetCollisionShape(CollisionShape* Shape);
00322     };//actorsoftphysicssettings
00323 }//Mezzanine
00324 
00325 #ifdef MEZZXML
00326 
00327 /// @brief Serializes the passed Mezzanine::ActorBasePhysicsSettings to XML
00328 /// @param stream The ostream to send the xml to.
00329 /// @param Ev the Mezzanine::ActorBasePhysicsSettings to be serialized
00330 /// @return this returns the ostream, now with the serialized data
00331 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::ActorBasePhysicsSettings& Ev);
00332 
00333 /// @brief Deserialize a Mezzanine::ActorBasePhysicsSettings
00334 /// @param stream The istream to get the xml from to (re)make the Mezzanine::ActorBasePhysicsSettings.
00335 /// @param Ev the Mezzanine::ActorBasePhysicsSettings to be deserialized.
00336 /// @return this returns the ostream, advanced past the Mezzanine::ActorBasePhysicsSettings that was recreated onto Ev.
00337 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::ActorBasePhysicsSettings& Ev);
00338 
00339 /// @brief Set all values of a Mezzanine::ActorBasePhysicsSettings from parsed xml.
00340 /// @param OneNode The istream to get the xml from to (re)make the Mezzanine::ActorBasePhysicsSettings.
00341 /// @param Ev the Mezzanine::ActorBasePhysicsSettings to be reset.
00342 void MEZZ_LIB operator >> (const Mezzanine::xml::Node& OneNode, Mezzanine::ActorBasePhysicsSettings& Ev);
00343 
00344 /// @brief Serializes the passed Mezzanine::ActorRigidPhysicsSettings to XML
00345 /// @param stream The ostream to send the xml to.
00346 /// @param Ev the Mezzanine::ActorRigidPhysicsSettings to be serialized
00347 /// @return this returns the ostream, now with the serialized data
00348 std::ostream& MEZZ_LIB operator << (std::ostream& stream, const Mezzanine::ActorRigidPhysicsSettings& Ev);
00349 
00350 /// @brief Deserialize a Mezzanine::ActorRigidPhysicsSettings
00351 /// @param stream The istream to get the xml from to (re)make the Mezzanine::ActorRigidPhysicsSettings.
00352 /// @param Ev the Mezzanine::ActorRigidPhysicsSettings to be deserialized.
00353 /// @return this returns the ostream, advanced past the Mezzanine::ActorRigidPhysicsSettings that was recreated onto Ev.
00354 std::istream& MEZZ_LIB operator >> (std::istream& stream, Mezzanine::ActorRigidPhysicsSettings& Ev);
00355 
00356 /// @brief Set all values of a Mezzanine::ActorRigidPhysicsSettings from parsed xml.
00357 /// @param OneNode The istream to get the xml from to (re)make the Mezzanine::ActorRigidPhysicsSettings.
00358 /// @param Ev the Mezzanine::ActorRigidPhysicsSettings to be reset.
00359 void MEZZ_LIB operator >> (const Mezzanine::xml::Node& OneNode, Mezzanine::ActorRigidPhysicsSettings& Ev);
00360 
00361 #endif // \MEZZXML
00362 
00363 
00364 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines