4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 #ifndef _IPHYSICSENVIRONMENT
31 #define _IPHYSICSENVIRONMENT
34 #include "PHY_DynamicTypes.h"
37 class PHY_IPhysicsController;
40 * pass back information from rayTest
42 struct PHY_RayCastResult
44 PHY_IPhysicsController* m_controller;
45 PHY__Vector3 m_hitPoint;
46 PHY__Vector3 m_hitNormal;
47 const RAS_MeshObject* m_meshObject; // !=NULL for mesh object (only for Bullet controllers)
48 int m_polygon; // index of the polygon hit by the ray,
49 // only if m_meshObject != NULL
53 * This class replaces the ignoreController parameter of rayTest function.
54 * It allows more sophisticated filtering on the physics controller before computing the ray intersection to save CPU.
55 * It is only used to its full extend by the Ccd physics environement (Bullet).
57 class PHY_IRayCastFilterCallback
60 PHY_IPhysicsController* m_ignoreController;
63 virtual ~PHY_IRayCastFilterCallback()
67 virtual bool needBroadphaseRayCast(PHY_IPhysicsController* controller)
72 virtual void reportHit(PHY_RayCastResult* result) = 0;
74 PHY_IRayCastFilterCallback(PHY_IPhysicsController* ignoreController, bool faceNormal=false)
75 :m_ignoreController(ignoreController),
76 m_faceNormal(faceNormal)
82 * Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.)
83 * A derived class may be able to 'construct' entities by loading and/or converting
85 class PHY_IPhysicsEnvironment
88 virtual ~PHY_IPhysicsEnvironment();
89 virtual void beginFrame() = 0;
90 virtual void endFrame() = 0;
91 /// Perform an integration step of duration 'timeStep'.
92 virtual bool proceedDeltaTime(double curTime,float timeStep)=0;
93 virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0;
94 //returns 0.f if no fixed timestep is used
95 virtual float getFixedTimeStep()=0;
97 ///setDebugMode is used to support several ways of debug lines, contact point visualization
98 virtual void setDebugMode(int debugMode) {}
99 ///setNumIterations set the number of iterations for iterative solvers
100 virtual void setNumIterations(int numIter) {}
101 ///setNumTimeSubSteps set the number of divisions of the timestep. Tradeoff quality versus performance.
102 virtual void setNumTimeSubSteps(int numTimeSubSteps){}
103 ///setDeactivationTime sets the minimum time that an objects has to stay within the velocity tresholds until it gets fully deactivated
104 virtual void setDeactivationTime(float dTime) {}
105 ///setDeactivationLinearTreshold sets the linear velocity treshold, see setDeactivationTime
106 virtual void setDeactivationLinearTreshold(float linTresh) {}
107 ///setDeactivationAngularTreshold sets the angular velocity treshold, see setDeactivationTime
108 virtual void setDeactivationAngularTreshold(float angTresh) {}
109 ///setContactBreakingTreshold sets tresholds to do with contact point management
110 virtual void setContactBreakingTreshold(float contactBreakingTreshold) {}
111 ///continuous collision detection mode, very experimental for Bullet
112 virtual void setCcdMode(int ccdMode) {}
113 ///successive overrelaxation constant, in case PSOR is used, values in between 1 and 2 guarantee converging behaviour
114 virtual void setSolverSorConstant(float sor) {}
115 ///setSolverType, internal setting, chooses solvertype, PSOR, Dantzig, impulse based, penalty based
116 virtual void setSolverType(int solverType) {}
117 ///setTau sets the spring constant of a penalty based solver
118 virtual void setSolverTau(float tau) {}
119 ///setDamping sets the damper constant of a penalty based solver
120 virtual void setSolverDamping(float damping) {}
121 ///linear air damping for rigidbodies
122 virtual void setLinearAirDamping(float damping) {}
123 /// penetrationdepth setting
124 virtual void setUseEpa(bool epa) {}
126 virtual void setGravity(float x,float y,float z)=0;
128 virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
129 float pivotX,float pivotY,float pivotZ,
130 float axis0X,float axis0Y,float axis0Z,
131 float axis1X=0,float axis1Y=0,float axis1Z=0,
132 float axis2X=0,float axis2Y=0,float axis2Z=0
134 virtual void removeConstraint(int constraintid)=0;
135 virtual float getAppliedImpulse(int constraintid){ return 0.f;}
138 //complex constraint for vehicles
139 virtual PHY_IVehicle* getVehicleConstraint(int constraintId) =0;
141 virtual PHY_IPhysicsController* rayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0;
144 //Methods for gamelogic collision/physics callbacks
146 virtual void addSensor(PHY_IPhysicsController* ctrl)=0;
147 virtual void removeSensor(PHY_IPhysicsController* ctrl)=0;
148 virtual void addTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0;
149 virtual void requestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
150 virtual void removeCollisionCallback(PHY_IPhysicsController* ctrl)=0;
151 //These two methods are *solely* used to create controllers for sensor! Don't use for anything else
152 virtual PHY_IPhysicsController* CreateSphereController(float radius,const PHY__Vector3& position) =0;
153 virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
155 virtual void setConstraintParam(int constraintId,int param,float value,float value1) = 0;
158 #endif //_IPHYSICSENVIRONMENT