Blender V2.61 - r43446

PHY_IPhysicsEnvironment.h

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