PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: SCPhysicsWorld.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_PHYSICSWORLD_H__ 00024 #define __PLPHYSICS_SCENENODES_PHYSICSWORLD_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include <PLScene/Scene/SceneContainer.h> 00032 #include "PLPhysics/PLPhysics.h" 00033 00034 00035 //[-------------------------------------------------------] 00036 //[ Namespace ] 00037 //[-------------------------------------------------------] 00038 namespace PLPhysics { 00039 00040 00041 //[-------------------------------------------------------] 00042 //[ Forward declarations ] 00043 //[-------------------------------------------------------] 00044 class World; 00045 00046 00047 //[-------------------------------------------------------] 00048 //[ Classes ] 00049 //[-------------------------------------------------------] 00050 /** 00051 * @brief 00052 * Physics world scene node container 00053 * 00054 * @note 00055 * - If 'CacheDirectory' is set, the implementation tries to cache for instance 'physics meshes'. This 00056 * can speed up loading times, but may create 'up to date' problems during development when data 00057 * was changed, but the cache is still using the old one. So, be careful when using this feature. 00058 * - 'ThreadPriorityClass' and 'ThreadPriority' are only used if the physics API implementation 00059 * is using an own thread and allows the manipulation of this settings 00060 */ 00061 class SCPhysicsWorld : public PLScene::SceneContainer { 00062 00063 00064 //[-------------------------------------------------------] 00065 //[ RTTI interface ] 00066 //[-------------------------------------------------------] 00067 pl_class(PLPHYSICS_RTTI_EXPORT, SCPhysicsWorld, "PLPhysics", PLScene::SceneContainer, "Physics world scene node container") 00068 // Attributes 00069 pl_attribute(PhysicsAPI, PLCore::String, "PLPhysicsNewton::World", ReadWrite, DirectValue, "Name of the physics API this world is using", "") 00070 pl_attribute(SimulationActive, bool, true, ReadWrite, GetSet, "Is the physics simulation currently active?", "") 00071 pl_attribute(SimulationSpeed, float, 1.0f, ReadWrite, GetSet, "Physics simulation speed. A speed of <= 0 is NOT allowed! Do NOT make the factor 'too' (for example > 4) extreme.", "Min='0.0001'") 00072 pl_attribute(SimulationQuality, float, 1.0f, ReadWrite, GetSet, "Physics simulation quality. 1 means best realistic behavior, 0 for the fastest possible configuration.", "Min='0.0' Max='1.0'") 00073 pl_attribute(FrameRate, float, 60.0f, ReadWrite, GetSet, "Frame rate the simulation runs on: smaller=more performance, larger=more accurate simulation", "Min='60.0' Max='1000.0'") 00074 pl_attribute(CacheDirectory, PLCore::String, "", ReadWrite, DirectValue, "Physics cache directory, if empty, no caching is used (best to avoid cache problems during development)", "") 00075 00076 // [TODO] New RTTI usage 00077 // DEFINE_VAR(PL_VAR_ENUM, m_nThreadPriorityClass, "", "", , "Idle=0 BelowNormal=1 Normal=2 AboveNormal=3 High=4 Realtime=5 None=6") 00078 // DEFINE_VAR(PL_VAR_ENUM, m_nThreadPriority, "", "", , "Idle=0 Lowest=1 BelowNormal=2 Normal=3 AboveNormal=4 Highest=5 TimeCritical=6") 00079 // pl_attribute(ThreadPriorityClass, pl_enum_type(), None, ReadWrite, GetSet, "Physics thread priority class (use realtime priority class ONLY if you REALLY need it, 'None' = do not use a thread)", "") 00080 // pl_attribute(ThreadPriority, pl_enum_type(), Normal, ReadWrite, GetSet, "Physics thread priority within the priority class it is in", "") 00081 00082 pl_attribute(Gravity, PLMath::Vector3, PLMath::Vector3(0.0f, -9.81f, 0.0f), ReadWrite, GetSet, "Gravity vector", "") 00083 pl_attribute(BuoyancyActive, bool, false, ReadWrite, GetSet, "Is buoyancy force active?", "") 00084 pl_attribute(BuoyancyPlaneY, float, 0.0f, ReadWrite, GetSet, "Buoyancy plane y position", "") 00085 // Constructors 00086 pl_constructor_0(DefaultConstructor, "Default constructor", "") 00087 pl_class_end 00088 00089 00090 //[-------------------------------------------------------] 00091 //[ Public RTTI get/set functions ] 00092 //[-------------------------------------------------------] 00093 public: 00094 PLPHYSICS_API bool GetSimulationActive() const; 00095 PLPHYSICS_API void SetSimulationActive(bool bValue); 00096 PLPHYSICS_API float GetSimulationSpeed() const; 00097 PLPHYSICS_API void SetSimulationSpeed(float fValue); 00098 PLPHYSICS_API float GetSimulationQuality() const; 00099 PLPHYSICS_API void SetSimulationQuality(float fValue); 00100 PLPHYSICS_API float GetFrameRate() const; 00101 PLPHYSICS_API void SetFrameRate(float fValue); 00102 PLPHYSICS_API const PLMath::Vector3 &GetGravity() const; 00103 PLPHYSICS_API void SetGravity(const PLMath::Vector3 &vValue); 00104 PLPHYSICS_API bool GetBuoyancyActive() const; 00105 PLPHYSICS_API void SetBuoyancyActive(bool bValue); 00106 PLPHYSICS_API float GetBuoyancyPlaneY() const; 00107 PLPHYSICS_API void SetBuoyancyPlaneY(float fValue); 00108 00109 00110 //[-------------------------------------------------------] 00111 //[ Public functions ] 00112 //[-------------------------------------------------------] 00113 public: 00114 /** 00115 * @brief 00116 * Default constructor 00117 */ 00118 PLPHYSICS_API SCPhysicsWorld(); 00119 00120 /** 00121 * @brief 00122 * Destructor 00123 */ 00124 PLPHYSICS_API virtual ~SCPhysicsWorld(); 00125 00126 /** 00127 * @brief 00128 * Returns the PL physics world 00129 * 00130 * @return 00131 * The PL physics world, a null pointer on error (if that's the case, something went totally wrong :) 00132 */ 00133 PLPHYSICS_API World *GetWorld() const; 00134 00135 00136 //[-------------------------------------------------------] 00137 //[ Private functions ] 00138 //[-------------------------------------------------------] 00139 private: 00140 /** 00141 * @brief 00142 * Called when the scene node needs to be updated 00143 */ 00144 void OnUpdate(); 00145 00146 /** 00147 * @brief 00148 * Called when the scene node axis aligned bounding box changed 00149 */ 00150 void OnAABoundingBox(); 00151 00152 00153 //[-------------------------------------------------------] 00154 //[ Private event handlers ] 00155 //[-------------------------------------------------------] 00156 private: 00157 PLCore::EventHandler<> EventHandlerUpdate; 00158 PLCore::EventHandler<> EventHandlerAABoundingBox; 00159 00160 00161 //[-------------------------------------------------------] 00162 //[ Private data ] 00163 //[-------------------------------------------------------] 00164 private: 00165 bool m_bSimulationActive; /**< Is the physics simulation currently active? */ 00166 float m_fSimulationSpeed; /**< Physics simulation speed. A speed of <= 0 is NOT allowed! Do NOT make the factor 'too' (for example > 4) extreme. */ 00167 float m_fSimulationQuality; /**< Physics simulation quality. 1 means best realistic behavior, 0 for the fastest possible configuration. */ 00168 float m_fFrameRate; /**< Frame rate the simulation runs on: smaller=more performance, larger=more accurate simulation */ 00169 PLCore::uint32 m_nThreadPriorityClass; /**< Physics thread priority class (use realtime priority class ONLY if you REALLY need it, 'None' = do not use a thread) */ 00170 PLCore::uint32 m_nThreadPriority; /**< Physics thread priority within the priority class it is in */ 00171 PLMath::Vector3 m_vGravity; /**< Gravity vector */ 00172 bool m_bBuoyancyActive; /**< Is buoyancy force active? */ 00173 float m_fBuoyancyPlaneY; /**< Buoyancy plane y position */ 00174 World *m_pWorld; /**< The PL physics world, can be a null pointer */ 00175 00176 00177 //[-------------------------------------------------------] 00178 //[ Protected virtual PLScene::SceneNode functions ] 00179 //[-------------------------------------------------------] 00180 protected: 00181 PLPHYSICS_API virtual void InitFunction() override; 00182 PLPHYSICS_API virtual void DeInitFunction() override; 00183 PLPHYSICS_API virtual void OnActivate(bool bActivate) override; 00184 00185 00186 //[-------------------------------------------------------] 00187 //[ Public virtual PLCore::Loadable functions ] 00188 //[-------------------------------------------------------] 00189 public: 00190 PLPHYSICS_API virtual bool LoadByFilename(const PLCore::String &sFilename, const PLCore::String &sParams = "", const PLCore::String &sMethod = "") override; 00191 PLPHYSICS_API virtual bool LoadByFile(PLCore::File &cFile, const PLCore::String &sParams = "", const PLCore::String &sMethod = "") override; 00192 00193 00194 }; 00195 00196 00197 //[-------------------------------------------------------] 00198 //[ Namespace ] 00199 //[-------------------------------------------------------] 00200 } // PLPhysics 00201 00202 00203 #endif // __PLPHYSICS_SCENENODES_PHYSICSWORLD_H__
|