PixelLightAPI  .
RagdollJoint.h
Go to the documentation of this file.
00001 /*********************************************************\
00002  *  File: RagdollJoint.h                                 *
00003  *
00004  *  Copyright (C) 2002-2011 The PixelLight Team (http://www.pixellight.org/)
00005  *
00006  *  This file is part of PixelLight.
00007  *
00008  *  PixelLight is free software: you can redistribute it and/or modify
00009  *  it under the terms of the GNU Lesser General Public License as published by
00010  *  the Free Software Foundation, either version 3 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  PixelLight is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  *  GNU Lesser General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU Lesser General Public License
00019  *  along with PixelLight. If not, see <http://www.gnu.org/licenses/>.
00020 \*********************************************************/
00021 
00022 
00023 #ifndef __PLPHYSICS_SCENENODES_RAGDOLLJOINT_H__
00024 #define __PLPHYSICS_SCENENODES_RAGDOLLJOINT_H__
00025 #pragma once
00026 
00027 
00028 //[-------------------------------------------------------]
00029 //[ Includes                                              ]
00030 //[-------------------------------------------------------]
00031 #include <PLMath/Vector3.h>
00032 #include "PLPhysics/PLPhysics.h"
00033 
00034 
00035 //[-------------------------------------------------------]
00036 //[ Namespace                                             ]
00037 //[-------------------------------------------------------]
00038 namespace PLPhysics {
00039 
00040 
00041 //[-------------------------------------------------------]
00042 //[ Forward declarations                                  ]
00043 //[-------------------------------------------------------]
00044 class Joint;
00045 class SNRagdoll;
00046 class ElementHandler;
00047 struct JointController;
00048 
00049 
00050 //[-------------------------------------------------------]
00051 //[ Classes                                               ]
00052 //[-------------------------------------------------------]
00053 /**
00054 *  @brief
00055 *    Ragdoll joint
00056 *
00057 *  @note
00058 *    - If you changed some of the initial settings you have to recreate
00059 *      the physics object in order to see the changes.
00060 */
00061 class RagdollJoint {
00062 
00063 
00064     //[-------------------------------------------------------]
00065     //[ Public definitions                                    ]
00066     //[-------------------------------------------------------]
00067     public:
00068         /**
00069         *  @brief
00070         *    Simulated joints will be either hinge (1-DOF) or universal (2-DOF)
00071         */
00072         enum EType {
00073             Hinge     = 0,
00074             Universal = 1
00075         };
00076 
00077 
00078     //[-------------------------------------------------------]
00079     //[ Public functions                                      ]
00080     //[-------------------------------------------------------]
00081     public:
00082         /**
00083         *  @brief
00084         *    Constructor
00085         *
00086         *  @param[in] pParent
00087         *    Parent ragdoll
00088         */
00089         PLPHYSICS_API RagdollJoint(SNRagdoll *pParent);
00090 
00091         /**
00092         *  @brief
00093         *    Destructor
00094         */
00095         PLPHYSICS_API virtual ~RagdollJoint();
00096 
00097         /**
00098         *  @brief
00099         *    Returns the PL physics joint
00100         *
00101         *  @return
00102         *    The PL physics joint, a null pointer on error (if that's the case, something went totally wrong :)
00103         */
00104         PLPHYSICS_API Joint *GetJoint() const;
00105 
00106         /**
00107         *  @brief
00108         *    Sets the name of the joint
00109         *
00110         *  @param[in] sName
00111         *    New joint name
00112         *
00113         *  @return
00114         *    'true' if all went fine, else 'false'
00115         *    (maybe this name is already used within the ragdoll?)
00116         */
00117         PLPHYSICS_API bool SetName(const PLCore::String &sName);
00118 
00119         /**
00120         *  @brief
00121         *    Creates the physics joint
00122         *
00123         *  @note
00124         *    - After this function the physics joint is in it's initial pose
00125         */
00126         PLPHYSICS_API void CreatePhysicsJoint();
00127 
00128         /**
00129         *  @brief
00130         *    Destroys the physics joint
00131         */
00132         PLPHYSICS_API void DestroyPhysicsJoint();
00133 
00134         /**
00135         *  @brief
00136         *    Returns the current joint anchor position
00137         *
00138         *  @param[out] vPosition
00139         *    Will receive the current joint anchor position
00140         */
00141         PLPHYSICS_API void GetCurrentAnchor(PLMath::Vector3 &vPosition) const;
00142 
00143         /**
00144         *  @brief
00145         *    Computes and applies PD-controller torques to each body part assigned with this joint
00146         *
00147         *  @param[in] pController
00148         *    Joint controller
00149         *  @param[in] fMaxTorque
00150         *    Maximum torque
00151         */
00152         PLPHYSICS_API void ApplyControlTorques(JointController *pController, float fMaxTorque);
00153 
00154 
00155     //[-------------------------------------------------------]
00156     //[ Public data                                           ]
00157     //[-------------------------------------------------------]
00158     public:
00159         SNRagdoll *m_pParentRagdoll;
00160         ElementHandler *m_pJointHandler;    /**< Holds the PL physics joint */
00161 
00162         PLCore::uint32 nIndex;
00163 
00164         PLCore::String sName;       /**< Name of this ragdoll joint */
00165         PLCore::String sAttached;   /**< Name of the attached ragdoll body */
00166         PLCore::String sParent;     /**< Name of the attached parent ragdoll body */
00167 
00168         PLCore::String sThisJointName; /**< Name of the original skeleton joint */
00169         PLCore::String sNextJointName; /**< Name of the next original skeleton joint which 'created' this joint */
00170 
00171         // Specifies whether attachedBody is connected to the world instead of another body part
00172         bool bAttachToWorld;
00173 
00174         EType nJointType;
00175 
00176         // Joint range of motion constraints for each axis (hinge joint only defined one range)
00177         float fLowJointRange1, fHighJointRange1;
00178         float fLowJointRange2, fHighJointRange2;
00179 
00180         // Anchor position of the joint
00181         PLMath::Vector3 vJointAnchor;
00182 
00183         // Axis that the joint rotates about (hinge joint only defines one axis)
00184         PLMath::Vector3 vRotAxis1;
00185         PLMath::Vector3 vRotAxis2;
00186 
00187 
00188     //[-------------------------------------------------------]
00189     //[ Protected functions                                   ]
00190     //[-------------------------------------------------------]
00191     protected:
00192         /**
00193         *  @brief
00194         *    Cap the torque generated by the controller to a reasonable value
00195         *
00196         *  @param[in, out] fTorque
00197         *    Torque to cap
00198         *  @param[in]      fMaxTorque
00199         *    Maximum torque
00200         */
00201         PLPHYSICS_API void ClampTorque(float &fTorque, float fMaxTorque);
00202 
00203 
00204 };
00205 
00206 
00207 //[-------------------------------------------------------]
00208 //[ Namespace                                             ]
00209 //[-------------------------------------------------------]
00210 } // PLPhysics
00211 
00212 
00213 #endif // __PLPHYSICS_SCENENODES_RAGDOLLJOINT_H__


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:00
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported