PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SNMPhysicsBody.h * 00003 * 00004 * Copyright (C) 2002-2012 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_SCENENODEMODIFIERS_BODY_H__ 00024 #define __PLPHYSICS_SCENENODEMODIFIERS_BODY_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLMath/Vector3.h> 00032 #include "PLPhysics/SceneNodeModifiers/SNMPhysics.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLPhysics { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class Body; 00045 class ElementHandler; 00046 class SCPhysicsWorld; 00047 00048 00049 //[-------------------------------------------------------] 00050 //[ Classes ] 00051 //[-------------------------------------------------------] 00052 /** 00053 * @brief 00054 * Abstract physics body scene node modifier 00055 * 00056 * @note 00057 * - During runtime, do NOT change the scale of the body scene node itself! 00058 * - This scene container MUST be within a SCPhysicsWorld scene container - else 00059 * this physics body will have no physics behavior at all 00060 * - If there's no mass, the body is static 00061 */ 00062 class SNMPhysicsBody : public SNMPhysics { 00063 00064 00065 //[-------------------------------------------------------] 00066 //[ Public definition ] 00067 //[-------------------------------------------------------] 00068 public: 00069 /** 00070 * @brief 00071 * Scene node modifier flags (PLScene::SceneNodeModifier flags extension) 00072 */ 00073 enum EFlags { 00074 InitUnfrozen = 1<<2, /**< The body is not frozen on initialization */ 00075 NoAutoFreeze = 1<<3, /**< Do not freeze the body automatically */ 00076 NoGravity = 1<<4, /**< The body is not influenced by gravity */ 00077 NoRotation = 1<<5 /**< Rotation is not used */ 00078 }; 00079 pl_enum(EFlags) 00080 pl_enum_base(SNMPhysics::EFlags) 00081 pl_enum_value(InitUnfrozen, "The body is not frozen on initialization") 00082 pl_enum_value(NoAutoFreeze, "Do not freeze the body automatically") 00083 pl_enum_value(NoGravity, "The body is not influenced by gravity") 00084 pl_enum_value(NoRotation, "Rotation is not used") 00085 pl_enum_end 00086 00087 00088 //[-------------------------------------------------------] 00089 //[ RTTI interface ] 00090 //[-------------------------------------------------------] 00091 pl_class(PLPHYSICS_RTTI_EXPORT, SNMPhysicsBody, "PLPhysics", PLPhysics::SNMPhysics, "Abstract physics body scene node modifier") 00092 // Attributes 00093 pl_attribute(Mass, float, 0.0f, ReadWrite, GetSet, "Mass of the physics body, 0=static body", "Min='0.0'") 00094 pl_attribute(CenterOfMass, PLMath::Vector3, PLMath::Vector3::Zero, ReadWrite, GetSet, "Relative center of mass", "") 00095 pl_attribute(PositionOffset, PLMath::Vector3, PLMath::Vector3::Zero, ReadWrite, GetSet, "Position offset relative to the scene node (=origin)", "") 00096 pl_attribute(CollisionGroup, PLCore::uint8, 0, ReadWrite, GetSet, "The collision group the body is in (0-31)", "Min='0' Max='31'") 00097 // Overwritten PLScene::SceneNodeModifier attributes 00098 pl_attribute(Flags, pl_flag_type(EFlags), 0, ReadWrite, GetSet, "Flags", "") 00099 // Slots 00100 pl_slot_0(OnActive, "Called when the scene node active state changed", "") 00101 pl_slot_0(OnPosition, "Called when the scene node position changed", "") 00102 pl_slot_0(OnRotation, "Called when the scene node rotation changed", "") 00103 pl_slot_0(OnTransform, "Called when the transform was changed by the physics", "") 00104 pl_class_end 00105 00106 00107 //[-------------------------------------------------------] 00108 //[ Public RTTI get/set functions ] 00109 //[-------------------------------------------------------] 00110 public: 00111 PLPHYSICS_API float GetMass() const; 00112 PLPHYSICS_API void SetMass(float fValue); 00113 PLPHYSICS_API const PLMath::Vector3 &GetCenterOfMass() const; 00114 PLPHYSICS_API void SetCenterOfMass(const PLMath::Vector3 &vValue); 00115 PLPHYSICS_API const PLMath::Vector3 &GetPositionOffset() const; 00116 PLPHYSICS_API void SetPositionOffset(const PLMath::Vector3 &vValue); 00117 PLPHYSICS_API PLCore::uint8 GetCollisionGroup() const; 00118 PLPHYSICS_API void SetCollisionGroup(PLCore::uint8 nValue); 00119 PLPHYSICS_API virtual void SetFlags(PLCore::uint32 nValue) override; // From PLScene::SceneNodeModifier 00120 00121 00122 //[-------------------------------------------------------] 00123 //[ Public functions ] 00124 //[-------------------------------------------------------] 00125 public: 00126 /** 00127 * @brief 00128 * Returns the PL physics world scene node container the physics body is in 00129 * 00130 * @return 00131 * The PL physics world scene node container the physics body is in, a null pointer on error 00132 * (if that's the case, something went totally wrong :) 00133 * 00134 * @note 00135 * - This PL physics world scene node container can be another as the scene node container this scene node is in 00136 */ 00137 PLPHYSICS_API SCPhysicsWorld *GetWorldContainer() const; 00138 00139 /** 00140 * @brief 00141 * Returns the PL physics body 00142 * 00143 * @return 00144 * The PL physics body, a null pointer on error (if that's the case, something went totally wrong :) 00145 */ 00146 PLPHYSICS_API Body *GetBody() const; 00147 00148 00149 //[-------------------------------------------------------] 00150 //[ Protected functions ] 00151 //[-------------------------------------------------------] 00152 protected: 00153 /** 00154 * @brief 00155 * Constructor 00156 * 00157 * @param[in] cSceneNode 00158 * Owner scene node 00159 */ 00160 PLPHYSICS_API SNMPhysicsBody(PLScene::SceneNode &cSceneNode); 00161 00162 /** 00163 * @brief 00164 * Destructor 00165 */ 00166 PLPHYSICS_API virtual ~SNMPhysicsBody(); 00167 00168 /** 00169 * @brief 00170 * Recreates the PL physics body 00171 */ 00172 PLPHYSICS_API void RecreatePhysicsBody(); 00173 00174 00175 //[-------------------------------------------------------] 00176 //[ Protected virtual PLScene::SceneNodeModifier functions ] 00177 //[-------------------------------------------------------] 00178 protected: 00179 PLPHYSICS_API virtual void OnActivate(bool bActivate) override; 00180 00181 00182 //[-------------------------------------------------------] 00183 //[ Protected virtual SNMPhysicsBody functions ] 00184 //[-------------------------------------------------------] 00185 protected: 00186 /** 00187 * @brief 00188 * Creates the PL physics body 00189 */ 00190 PLPHYSICS_API virtual void CreatePhysicsBody(); 00191 00192 00193 //[-------------------------------------------------------] 00194 //[ Protected data ] 00195 //[-------------------------------------------------------] 00196 protected: 00197 float m_fMass; /**< Mass of the physics body, 0=static body */ 00198 PLMath::Vector3 m_vCenterOfMass; /**< Relative center of mass */ 00199 PLMath::Vector3 m_vPositionOffset; /**< Position offset relative to the scene node (=origin) */ 00200 PLCore::uint8 m_nCollisionGroup; /**< The collision group the body is in (0-31) */ 00201 SCPhysicsWorld *m_pWorldContainer; /**< The PL physics world scene node container the physics body is in, can be a null pointer */ 00202 ElementHandler *m_pBodyHandler; /**< Holds the PL physics body (ALWAYS valid!) */ 00203 bool m_bListening; /**< Listening scene node position changes etc.? */ 00204 00205 00206 //[-------------------------------------------------------] 00207 //[ Private functions ] 00208 //[-------------------------------------------------------] 00209 private: 00210 /** 00211 * @brief 00212 * Called when the scene node active state changed 00213 */ 00214 void OnActive(); 00215 00216 /** 00217 * @brief 00218 * Called when the scene node position changed 00219 */ 00220 void OnPosition(); 00221 00222 /** 00223 * @brief 00224 * Called when the scene node rotation changed 00225 */ 00226 void OnRotation(); 00227 00228 /** 00229 * @brief 00230 * Called when the transform was changed by the physics 00231 */ 00232 void OnTransform(); 00233 00234 00235 //[-------------------------------------------------------] 00236 //[ Protected virtual PLScene::SceneNodeModifier functions ] 00237 //[-------------------------------------------------------] 00238 protected: 00239 PLPHYSICS_API virtual void InformedOnInit(); 00240 00241 00242 }; 00243 00244 00245 //[-------------------------------------------------------] 00246 //[ Namespace ] 00247 //[-------------------------------------------------------] 00248 } // PLPhysics 00249 00250 00251 #endif // __PLPHYSICS_SCENENODEMODIFIERS_BODY_H__
|