PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SNMPhysicsCharacter.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 __PLENGINE_CONTROLLER_SNMPHYSICSCHARACTER_H__ 00024 #define __PLENGINE_CONTROLLER_SNMPHYSICSCHARACTER_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLCore/Base/Event/EventHandler.h> 00032 #include <PLMath/Vector3.h> 00033 #include <PLPhysics/SceneNodeModifiers/SNMPhysics.h> 00034 #include "PLEngine/PLEngine.h" 00035 00036 00037 //[-------------------------------------------------------] 00038 //[ Forward declarations ] 00039 //[-------------------------------------------------------] 00040 namespace PLPhysics { 00041 class Body; 00042 } 00043 00044 00045 //[-------------------------------------------------------] 00046 //[ Namespace ] 00047 //[-------------------------------------------------------] 00048 namespace PLEngine { 00049 00050 00051 //[-------------------------------------------------------] 00052 //[ Classes ] 00053 //[-------------------------------------------------------] 00054 /** 00055 * @brief 00056 * Basic PL physics character scene node modifier class 00057 * 00058 * @remarks 00059 * This class will access the PLPhysics::SNMPhysicsBody scene node modifier and take over 00060 * control of the physics body. So, this modifier makes only sense if there's a 00061 * PLPhysics::SNMPhysicsBody, too. 00062 * 00063 * @note 00064 * - Primary intended for rapid prototyping 00065 */ 00066 class SNMPhysicsCharacter : public PLPhysics::SNMPhysics { 00067 00068 00069 //[-------------------------------------------------------] 00070 //[ Public definition ] 00071 //[-------------------------------------------------------] 00072 public: 00073 /** 00074 * @brief 00075 * Scene node modifier flags (PLScene::SceneNodeModifier flags extension) 00076 */ 00077 enum EFlags { 00078 YMovement = 1<<2 /**< Perform movement also on the y axis, else movement is just performed on the x/z plane */ 00079 }; 00080 pl_enum(EFlags) 00081 pl_enum_base(SNMPhysics::EFlags) 00082 pl_enum_value(YMovement, "Perform movement also on the y axis, else movement is just performed on the x/z plane") 00083 pl_enum_end 00084 00085 00086 //[-------------------------------------------------------] 00087 //[ RTTI interface ] 00088 //[-------------------------------------------------------] 00089 pl_class(PL_RTTI_EXPORT, SNMPhysicsCharacter, "PLEngine", PLPhysics::SNMPhysics, "Basic PL physics character scene node modifier class") 00090 // Attributes 00091 pl_attribute(Speed, float, 2.0f, ReadWrite, DirectValue, "Speed", "Min='0.0'") 00092 pl_attribute(Acceleration, float, 20.0f, ReadWrite, DirectValue, "Acceleration", "Min='0.0'") 00093 pl_attribute(MaxAcceleration, float, 30.0f, ReadWrite, DirectValue, "Maximum acceleration", "Min='0.0'") 00094 pl_attribute(JumpForce, float, 4.0f, ReadWrite, DirectValue, "Jump force, if 0, jumping is not allowed", "Min='0.0'") 00095 pl_attribute(JumpReadyTime, float, 0.5f, ReadWrite, DirectValue, "Time to past until we can jump again", "Min='0.0'") 00096 pl_attribute(JumpGroundDistance, float, 0.05f, ReadWrite, DirectValue, "Minimum ground distance required for jumping", "Min='0.001'") 00097 // Overwritten PLScene::SceneNodeModifier attributes 00098 pl_attribute(Flags, pl_flag_type(EFlags), 0, ReadWrite, GetSet, "Flags", "") 00099 // Constructors 00100 pl_constructor_1(ParameterConstructor, PLScene::SceneNode&, "Parameter constructor", "") 00101 pl_class_end 00102 00103 00104 //[-------------------------------------------------------] 00105 //[ Public functions ] 00106 //[-------------------------------------------------------] 00107 public: 00108 /** 00109 * @brief 00110 * Constructor 00111 * 00112 * @param[in] cSceneNode 00113 * Owner scene node 00114 */ 00115 PL_API SNMPhysicsCharacter(PLScene::SceneNode &cSceneNode); 00116 00117 /** 00118 * @brief 00119 * Destructor 00120 */ 00121 PL_API virtual ~SNMPhysicsCharacter(); 00122 00123 /** 00124 * @brief 00125 * Gets the running mode 00126 * 00127 * @return 00128 * 'true' if the character runs, else 'false' 00129 */ 00130 PL_API bool IsRunning() const; 00131 00132 /** 00133 * @brief 00134 * Sets the running mode 00135 * 00136 * @param[in] bRun 00137 * Did the character run? 00138 */ 00139 PL_API void SetRunning(bool bRun = false); 00140 00141 /** 00142 * @brief 00143 * Gets the creeping mode 00144 * 00145 * @return 00146 * 'true' if the character creeps, else 'false' 00147 */ 00148 PL_API bool IsCreeping() const; 00149 00150 /** 00151 * @brief 00152 * Sets the creeping mode 00153 * 00154 * @param[in] bCreep 00155 * Did the character creep? 00156 */ 00157 PL_API void SetCreeping(bool bCreep = false); 00158 00159 /** 00160 * @brief 00161 * Gets the movement vector 00162 * 00163 * @return 00164 * The movement vector 00165 * 00166 * @note 00167 * - The movement vector should be normalized 00168 */ 00169 PL_API const PLMath::Vector3 &GetMovement() const; 00170 00171 /** 00172 * @brief 00173 * Sets the movement vector 00174 * 00175 * @param[in] vMovement 00176 * The new movement vector, if the length is >1, the vector is used in a normalized form inside OnUpdate() 00177 * 00178 * @see 00179 * - GetMovement() 00180 */ 00181 PL_API void SetMovement(const PLMath::Vector3 &vMovement); 00182 00183 /** 00184 * @brief 00185 * Performs a jump 00186 * 00187 * @return 00188 * 'true' if all went fine an the jump is performed, else 'false' 00189 * (maybe the character does not stand on the ground) 00190 */ 00191 PL_API bool Jump(); 00192 00193 00194 //[-------------------------------------------------------] 00195 //[ Protected functions ] 00196 //[-------------------------------------------------------] 00197 protected: 00198 /** 00199 * @brief 00200 * Returns the PL physics body of the scene node 00201 * 00202 * @return 00203 * The PL physics body of the scene node, a null pointer if there's no such body 00204 */ 00205 PL_API PLPhysics::Body *GetPhysicsBody() const; 00206 00207 00208 //[-------------------------------------------------------] 00209 //[ Protected virtual PLScene::SceneNodeModifier functions ] 00210 //[-------------------------------------------------------] 00211 protected: 00212 PL_API virtual void OnActivate(bool bActivate) override; 00213 00214 00215 //[-------------------------------------------------------] 00216 //[ Private functions ] 00217 //[-------------------------------------------------------] 00218 private: 00219 /** 00220 * @brief 00221 * Called when the scene node modifier needs to be updated 00222 */ 00223 void OnUpdate(); 00224 00225 00226 //[-------------------------------------------------------] 00227 //[ Private event handlers ] 00228 //[-------------------------------------------------------] 00229 private: 00230 PLCore::EventHandler<> EventHandlerUpdate; 00231 00232 00233 //[-------------------------------------------------------] 00234 //[ Private data ] 00235 //[-------------------------------------------------------] 00236 private: 00237 bool m_bRun; /**< If true, velocity in the callback is scaled up */ 00238 bool m_bCreep; /**< If true, velocity in the callback is scaled down */ 00239 PLMath::Vector3 m_vMovement; /**< Current movement vector */ 00240 float m_fJumpReadyTimer; /**< If this timer is 0, we are allowed to jump */ 00241 bool m_bJump; /**< If true, let the character jump */ 00242 00243 00244 }; 00245 00246 00247 //[-------------------------------------------------------] 00248 //[ Namespace ] 00249 //[-------------------------------------------------------] 00250 } // PL 00251 00252 00253 #endif // __PLENGINE_CONTROLLER_SNMPHYSICSCHARACTER_H__
|