Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorErwin Coumans <blender@erwincoumans.com>2005-07-29 22:14:41 +0400
committerErwin Coumans <blender@erwincoumans.com>2005-07-29 22:14:41 +0400
commitdad6ef9045526b6b26f845151d3ea3b26edaf4a8 (patch)
tree16625df210f25bcf20efcc251722f28934161d38 /source
parent7d797797c8f6e3eb8fd91bd42cf8e488d14b1d40 (diff)
added physics-debugging
didn't check every single file, so might have broken some gameengine stuff, will fix it this weekend!
Diffstat (limited to 'source')
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp27
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp13
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp18
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp8
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h6
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp50
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h13
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h2
8 files changed, 85 insertions, 52 deletions
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index 298a909150f..4db080e02db 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -173,15 +173,32 @@ static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& sce
#include "KX_PythonInit.h"
#ifdef USE_BULLET
-struct BlenderDebugDraw : public PHY_IPhysicsDebugDraw
+#include "IDebugDraw.h"
+
+
+struct BlenderDebugDraw : public IDebugDraw
{
+ BlenderDebugDraw () :
+ m_debugMode(0)
+ {
+ }
+
+ int m_debugMode;
+
virtual void DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)
{
- MT_Vector3 kxfrom(from[0],from[1],from[2]);
- MT_Vector3 kxto(to[0],to[1],to[2]);
- MT_Vector3 kxcolor(color[0],color[1],color[2]);
+ if (m_debugMode == 1)
+ {
+ MT_Vector3 kxfrom(from[0],from[1],from[2]);
+ MT_Vector3 kxto(to[0],to[1],to[2]);
+ MT_Vector3 kxcolor(color[0],color[1],color[2]);
- KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor);
+ KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor);
+ }
+ }
+ virtual void SetDebugMode(int debugMode)
+ {
+ m_debugMode = debugMode;
}
};
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index 04b08575364..db5d6fa1347 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -133,7 +133,7 @@ void KX_ConvertSumoObject( KX_GameObject* gameobj,
smmaterial->m_fh_normal = kxmaterial->m_fh_normal;
smmaterial->m_fh_spring = kxmaterial->m_fh_spring;
smmaterial->m_friction = kxmaterial->m_friction;
- smmaterial->m_restitution = kxmaterial->m_restitution;
+ smmaterial->m_restitution = 0.f;//kxmaterial->m_restitution;
SumoPhysicsEnvironment* sumoEnv =
(SumoPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
@@ -911,9 +911,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
halfExtents /= 2.f;
- SimdVector3 he (halfExtents[0]-CONVEX_DISTANCE_MARGIN ,halfExtents[1]-CONVEX_DISTANCE_MARGIN ,halfExtents[2]-CONVEX_DISTANCE_MARGIN );
- he = he.absolute();
-
+ //todo: do this conversion internally !
+ SimdVector3 he (halfExtents[0],halfExtents[1],halfExtents[2]);
bm = new BoxShape(he);
bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
@@ -957,7 +956,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
if (bm)
{
bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
- bm->SetMargin(0.f);
+ bm->SetMargin(0.05f);
}
break;
}
@@ -1005,8 +1004,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_restitution = smmaterial->m_restitution;
- ci.m_linearDamping = shapeprops->m_lin_drag;
- ci.m_angularDamping = shapeprops->m_ang_drag;
+ ci.m_linearDamping = 0.5;//shapeprops->m_lin_drag;
+ ci.m_angularDamping = 0.5f;//shapeprops->m_ang_drag;
KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,dyna);
env->addCcdPhysicsController( physicscontroller);
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
index fedd45c65e8..63896b063ee 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -62,7 +62,7 @@
#include "KX_PyMath.h"
-#include "SumoPhysicsEnvironment.h"
+#include "PHY_IPhysicsEnvironment.h"
// FIXME: Enable for access to blender python modules. This is disabled because
// python has dependencies on a lot of other modules and is a pain to link.
//#define USE_BLENDER_PYTHON
@@ -227,6 +227,22 @@ static PyObject* gPySetPhysicsTicRate(PyObject*,
return NULL;
}
+static PyObject* gPySetPhysicsDebug(PyObject*,
+ PyObject* args,
+ PyObject*)
+{
+ int debugMode;
+ if (PyArg_ParseTuple(args, "i", &debugMode))
+ {
+ PHY_GetActiveEnvironment()->setDebugMode(debugMode);
+ Py_Return;
+ }
+
+ return NULL;
+}
+
+
+
static PyObject* gPyGetPhysicsTicRate(PyObject*, PyObject*, PyObject*)
{
return PyFloat_FromDouble(PHY_GetActiveEnvironment()->getFixedTimeStep());
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
index 8b423204bec..19c4632820c 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
@@ -31,7 +31,7 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
MassProps mp(ci.m_mass, ci.m_localInertiaTensor);
- m_body = new RigidBody(mp,0,0);
+ m_body = new RigidBody(mp,0,0,ci.m_friction,ci.m_restitution);
m_broadphaseHandle = ci.m_broadphaseHandle;
@@ -44,12 +44,10 @@ CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
m_body->setMassProps(ci.m_mass, ci.m_localInertiaTensor);
m_body->setGravity( ci.m_gravity);
- m_friction = ci.m_friction;
- m_restitution = ci.m_restitution;
-
+
m_body->setDamping(ci.m_linearDamping, ci.m_angularDamping);
-
+
m_body->setCenterOfMassTransform( trans );
#ifdef WIN32
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
index 3a8590e261c..235931ebab4 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
@@ -15,7 +15,6 @@ struct CcdConstructionInfo
CcdConstructionInfo()
: m_gravity(0,0,0),
m_mass(0.f),
- m_friction(0.1f),
m_restitution(0.1f),
m_linearDamping(0.1f),
m_angularDamping(0.1f),
@@ -27,9 +26,8 @@ struct CcdConstructionInfo
SimdVector3 m_localInertiaTensor;
SimdVector3 m_gravity;
SimdScalar m_mass;
- SimdScalar m_friction;
SimdScalar m_restitution;
-
+ SimdScalar m_friction;
SimdScalar m_linearDamping;
SimdScalar m_angularDamping;
void* m_broadphaseHandle;
@@ -54,8 +52,6 @@ class CcdPhysicsController : public PHY_IPhysicsController
int m_collisionDelay;
- SimdScalar m_friction;
- SimdScalar m_restitution;
void* m_broadphaseHandle;
CcdPhysicsController (const CcdConstructionInfo& ci);
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
index a4c9df51466..fa4f45cab43 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
@@ -14,6 +14,7 @@
#include "ConstraintSolver/OdeConstraintSolver.h"
#include "ConstraintSolver/SimpleConstraintSolver.h"
+#include "IDebugDraw.h"
#include "CollisionDispatch/ToiContactDispatcher.h"
@@ -32,7 +33,7 @@ bool useIslands = true;
//#include "BroadphaseCollision/QueryBox.h"
//todo: change this to allow dynamic registration of types!
-unsigned long gNumIterations = 10;
+unsigned long gNumIterations = 20;
#ifdef WIN32
void DrawRasterizerLine(const float* from,const float* to,int color);
@@ -48,7 +49,7 @@ void DrawRasterizerLine(const float* from,const float* to,int color);
-static void DrawAabb(PHY_IPhysicsDebugDraw* debugDrawer,const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)
+static void DrawAabb(IDebugDraw* debugDrawer,const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)
{
SimdVector3 halfExtents = (to-from)* 0.5f;
SimdVector3 center = (to+from) *0.5f;
@@ -313,10 +314,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
//m_scalingPropagated = true;
}
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.begin("integrate force");
-#endif //EXTRA_PHYSICS_PROFILE
-
{
@@ -338,9 +335,6 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
}
}
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.end("integrate force");
-#endif //EXTRA_PHYSICS_PROFILE
BroadphaseInterface* scene = m_broadphase;
@@ -358,33 +352,22 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
DispatcherInfo dispatchInfo;
dispatchInfo.m_timeStep = timeStep;
dispatchInfo.m_stepCount = 0;
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.begin("cd");
-#endif //EXTRA_PHYSICS_PROFILE
scene->DispatchAllCollisionPairs(*m_dispatcher,dispatchInfo);///numsubstep,g);
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.end("cd");
-#endif //EXTRA_PHYSICS_PROFILE
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.begin("solver");
-#endif //EXTRA_PHYSICS_PROFILE
int numRigidBodies = m_controllers.size();
UpdateActivationState();
//contacts
- m_dispatcher->SolveConstraints(timeStep, gNumIterations ,numRigidBodies);
+
-#ifdef EXTRA_PHYSICS_PROFILE
- cpuProfile.end("solver");
-#endif //EXTRA_PHYSICS_PROFILE
+ m_dispatcher->SolveConstraints(timeStep, gNumIterations ,numRigidBodies,m_debugDrawer);
for (int g=0;g<numsubstep;g++)
{
@@ -558,6 +541,29 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep)
return true;
}
+void CcdPhysicsEnvironment::setDebugMode(int debugMode)
+{
+ if (debugMode > 10)
+ {
+ if (m_dispatcher)
+ delete m_dispatcher;
+
+ if (debugMode == 11)
+ {
+ SimpleConstraintSolver* solver= new SimpleConstraintSolver();
+ m_dispatcher = new ToiContactDispatcher(solver);
+ } else
+ {
+ OdeConstraintSolver* solver = new OdeConstraintSolver();
+ m_dispatcher = new ToiContactDispatcher(solver);
+ }
+ }
+ if (m_debugDrawer){
+ m_debugDrawer->SetDebugMode(debugMode);
+ }
+}
+
+
void CcdPhysicsEnvironment::SyncMotionStates(float timeStep)
{
std::vector<CcdPhysicsController*>::iterator i;
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
index 88cf4b495cf..be6f6c648c7 100644
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
@@ -6,10 +6,6 @@
class CcdPhysicsController;
#include "SimdVector3.h"
-struct PHY_IPhysicsDebugDraw
-{
- virtual void DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)=0;
-};
class Point2PointConstraint;
@@ -20,6 +16,7 @@ class Dispatcher;
class Vehicle;
class PersistentManifold;
class BroadphaseInterface;
+class IDebugDraw;
/// Physics Environment takes care of stepping the simulation and is a container for physics entities.
/// It stores rigidbodies,constraints, materials etc.
@@ -28,7 +25,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
{
SimdVector3 m_gravity;
BroadphaseInterface* m_broadphase;
- PHY_IPhysicsDebugDraw* m_debugDrawer;
+ IDebugDraw* m_debugDrawer;
public:
CcdPhysicsEnvironment(ToiContactDispatcher* dispatcher=0, BroadphaseInterface* broadphase=0);
@@ -41,7 +38,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
/// Perform an integration step of duration 'timeStep'.
- virtual void setDebugDrawer(PHY_IPhysicsDebugDraw* debugDrawer)
+ virtual void setDebugDrawer(IDebugDraw* debugDrawer)
{
m_debugDrawer = debugDrawer;
}
@@ -53,8 +50,11 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
virtual bool proceedDeltaTime(double curTime,float timeStep);
virtual void setFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep){};
//returns 0.f if no fixed timestep is used
+
virtual float getFixedTimeStep(){ return 0.f;};
+ virtual void setDebugMode(int debugMode);
+
virtual void setGravity(float x,float y,float z);
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
@@ -116,6 +116,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
bool m_scalingPropagated;
+
};
#endif //CCDPHYSICSENVIRONMENT
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
index 2ffcf80a62b..ca856598772 100644
--- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
+++ b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
@@ -51,7 +51,7 @@ class PHY_IPhysicsEnvironment
//returns 0.f if no fixed timestep is used
virtual float getFixedTimeStep()=0;
-
+ virtual void setDebugMode(int debugMode) {}
virtual void setGravity(float x,float y,float z)=0;
virtual int createConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,