|
Blender
V2.59
|
00001 /* 00002 * $Id: PHY_IPhysicsEnvironment.h 35500 2011-03-12 20:34:17Z erwin $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 #ifndef _IPHYSICSENVIRONMENT 00035 #define _IPHYSICSENVIRONMENT 00036 00037 #include <vector> 00038 #include "PHY_DynamicTypes.h" 00039 00040 #ifdef WITH_CXX_GUARDEDALLOC 00041 #include "MEM_guardedalloc.h" 00042 #endif 00043 00044 class PHY_IVehicle; 00045 class RAS_MeshObject; 00046 class PHY_IPhysicsController; 00047 00051 struct PHY_RayCastResult 00052 { 00053 PHY_IPhysicsController* m_controller; 00054 PHY__Vector3 m_hitPoint; 00055 PHY__Vector3 m_hitNormal; 00056 const RAS_MeshObject* m_meshObject; // !=NULL for mesh object (only for Bullet controllers) 00057 int m_polygon; // index of the polygon hit by the ray, 00058 // only if m_meshObject != NULL 00059 int m_hitUVOK; // !=0 if UV coordinate in m_hitUV is valid 00060 PHY__Vector2 m_hitUV; // UV coordinates of hit point 00061 }; 00062 00068 class PHY_IRayCastFilterCallback 00069 { 00070 public: 00071 PHY_IPhysicsController* m_ignoreController; 00072 bool m_faceNormal; 00073 bool m_faceUV; 00074 00075 virtual ~PHY_IRayCastFilterCallback() 00076 { 00077 } 00078 00079 virtual bool needBroadphaseRayCast(PHY_IPhysicsController* controller) 00080 { 00081 return true; 00082 } 00083 00084 virtual void reportHit(PHY_RayCastResult* result) = 0; 00085 00086 PHY_IRayCastFilterCallback(PHY_IPhysicsController* ignoreController, bool faceNormal=false, bool faceUV=false) 00087 :m_ignoreController(ignoreController), 00088 m_faceNormal(faceNormal), 00089 m_faceUV(faceUV) 00090 { 00091 } 00092 00093 #ifdef WITH_CXX_GUARDEDALLOC 00094 public: 00095 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:PHY_IRayCastFilterCallback"); } 00096 void operator delete( void *mem ) { MEM_freeN(mem); } 00097 #endif 00098 }; 00099 00104 class PHY_IPhysicsEnvironment 00105 { 00106 public: 00107 virtual ~PHY_IPhysicsEnvironment(); 00108 virtual void beginFrame() = 0; 00109 virtual void endFrame() = 0; 00111 virtual bool proceedDeltaTime(double curTime,float timeStep,float interval)=0; 00113 virtual void debugDrawWorld(){} 00114 virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0; 00115 //returns 0.f if no fixed timestep is used 00116 virtual float getFixedTimeStep()=0; 00117 00119 virtual void setDebugMode(int debugMode) {} 00121 virtual void setNumIterations(int numIter) {} 00123 virtual void setNumTimeSubSteps(int numTimeSubSteps){} 00125 virtual void setDeactivationTime(float dTime) {} 00127 virtual void setDeactivationLinearTreshold(float linTresh) {} 00129 virtual void setDeactivationAngularTreshold(float angTresh) {} 00131 virtual void setContactBreakingTreshold(float contactBreakingTreshold) {} 00133 virtual void setCcdMode(int ccdMode) {} 00135 virtual void setSolverSorConstant(float sor) {} 00137 virtual void setSolverType(int solverType) {} 00139 virtual void setSolverTau(float tau) {} 00141 virtual void setSolverDamping(float damping) {} 00143 virtual void setLinearAirDamping(float damping) {} 00145 virtual void setUseEpa(bool epa) {} 00146 00147 virtual void setGravity(float x,float y,float z)=0; 00148 00149 virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type, 00150 float pivotX,float pivotY,float pivotZ, 00151 float axis0X,float axis0Y,float axis0Z, 00152 float axis1X=0,float axis1Y=0,float axis1Z=0, 00153 float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0 00154 )=0; 00155 virtual void removeConstraint(int constraintid)=0; 00156 virtual float getAppliedImpulse(int constraintid){ return 0.f;} 00157 00158 00159 //complex constraint for vehicles 00160 virtual PHY_IVehicle* getVehicleConstraint(int constraintId) =0; 00161 00162 virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0; 00163 00164 //culling based on physical broad phase 00165 // the plane number must be set as follow: near, far, left, right, top, botton 00166 // the near plane must be the first one and must always be present, it is used to get the direction of the view 00167 virtual bool cullingTest(PHY_CullingCallback callback, void *userData, PHY__Vector4* planeNormals, int planeNumber, int occlusionRes) = 0; 00168 00169 //Methods for gamelogic collision/physics callbacks 00170 //todo: 00171 virtual void addSensor(PHY_IPhysicsController* ctrl)=0; 00172 virtual void removeSensor(PHY_IPhysicsController* ctrl)=0; 00173 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0; 00174 virtual bool requestCollisionCallback(PHY_IPhysicsController* ctrl)=0; 00175 virtual bool removeCollisionCallback(PHY_IPhysicsController* ctrl)=0; 00176 //These two methods are *solely* used to create controllers for sensor! Don't use for anything else 00177 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0; 00178 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0; 00179 00180 virtual void setConstraintParam(int constraintId,int param,float value,float value1) = 0; 00181 virtual float getConstraintParam(int constraintId,int param) = 0; 00182 00183 virtual void exportFile(const char* filename) {}; 00184 00185 #ifdef WITH_CXX_GUARDEDALLOC 00186 public: 00187 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:PHY_IPhysicsEnvironment"); } 00188 void operator delete( void *mem ) { MEM_freeN(mem); } 00189 #endif 00190 }; 00191 00192 #endif //_IPHYSICSENVIRONMENT 00193