diff options
author | Erwin Coumans <blender@erwincoumans.com> | 2005-07-27 13:30:53 +0400 |
---|---|---|
committer | Erwin Coumans <blender@erwincoumans.com> | 2005-07-27 13:30:53 +0400 |
commit | 411123b2502388c9082886be48db93836ceacea8 (patch) | |
tree | 2d37fe8fc95b71b603a9e2fdf76580768a134313 /source | |
parent | b8142515ce762107a186fac501d73a2dbe42047a (diff) |
- added debug line drawing in gameengine (handy for debugging physics problems)
- added #ifdef for a visual studio 8 crashing problems
- added scaling and tolerances to triangle meshes
Diffstat (limited to 'source')
13 files changed, 137 insertions, 5 deletions
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index f8a628bd0c7..298a909150f 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -170,7 +170,22 @@ static struct Scene *GetSceneForName2(struct Main *maggie, const STR_String& sce return (Scene*) maggie->scene.first; } +#include "KX_PythonInit.h" +#ifdef USE_BULLET +struct BlenderDebugDraw : public PHY_IPhysicsDebugDraw +{ + 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]); + + KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor); + } +}; + +#endif void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, class KX_Scene* destinationscene, @@ -226,7 +241,9 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, #ifdef USE_BULLET case UseBullet: { - destinationscene->SetPhysicsEnvironment(new CcdPhysicsEnvironment()); + CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(); + ccdPhysEnv->setDebugDrawer(new BlenderDebugDraw()); + destinationscene->SetPhysicsEnvironment(ccdPhysEnv); break; } #endif diff --git a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp index 8c3a17f58f3..3d81046e8e9 100644 --- a/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp +++ b/source/gameengine/GamePlayer/common/GPC_RenderTools.cpp @@ -173,6 +173,7 @@ void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, int lines; char* s = tmpstr.Ptr(); char* p; + // Save and change OpenGL settings int texture2D; @@ -182,6 +183,11 @@ void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, glGetIntegerv(GL_FOG, (GLint*)&fog); glDisable(GL_FOG); + int light; + glGetIntegerv(GL_LIGHTING, (GLint*)&light); + glDisable(GL_LIGHTING); + + // Set up viewing settings glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -228,6 +234,10 @@ void GPC_RenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, glEnable(GL_TEXTURE_2D); else glDisable(GL_TEXTURE_2D); + if (light) + glEnable(GL_LIGHTING); + else + glDisable(GL_LIGHTING); } /** diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h index 60a9d560a06..b8cf5491d41 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObject.h @@ -35,7 +35,13 @@ /* These are defined by the build system... */ //#define USE_SUMO_SOLID //#define USE_ODE -//#define USE_BULLET + +//on visual studio 8, always enable BULLET. +//you can have multiple physics engines running anyway, and +//the build system doesn't really support this at the moment. +#if 1400 > _MSC_VER +#define USE_BULLET +#endif class RAS_MeshObject; class KX_Scene; diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 38e55ee6723..04b08575364 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -854,6 +854,7 @@ static CollisionShape* CreateBulletShapeFromMesh(RAS_MeshObject* meshobj, bool p + void KX_ConvertBulletObject( class KX_GameObject* gameobj, class RAS_MeshObject* meshobj, class KX_Scene* kxscene, @@ -864,6 +865,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment(); assert(env); + + bool dyna = false; @@ -954,6 +957,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, if (bm) { bm->CalculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); + bm->SetMargin(0.f); } break; } diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp index 37d85816314..b4b3cea8c8a 100644 --- a/source/gameengine/Ketsji/KX_MeshProxy.cpp +++ b/source/gameengine/Ketsji/KX_MeshProxy.cpp @@ -213,5 +213,6 @@ PyObject* KX_MeshProxy::PyGetVertex(PyObject* self, KX_PYMETHODDEF_DOC(KX_MeshProxy, reinstancePhysicsMesh, "Reinstance the physics mesh.") { - return Py_Success(KX_ReInstanceShapeFromMesh(m_meshobj)); + //this needs to be reviewed, it is dependend on Sumo/Solid. Who is using this ? + return Py_None;//Py_Success(KX_ReInstanceShapeFromMesh(m_meshobj)); } diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp index 6f2fced3bd1..fedd45c65e8 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.cpp +++ b/source/gameengine/Ketsji/KX_PythonInit.cpp @@ -78,6 +78,12 @@ static RAS_ICanvas* gp_Canvas = NULL; static KX_Scene* gp_KetsjiScene = NULL; static RAS_IRasterizer* gp_Rasterizer = NULL; +void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color) +{ + if (gp_Rasterizer) + gp_Rasterizer->DrawDebugLine(from,to,color); +} + /* Macro for building the keyboard translation */ //#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(SCA_IInputDevice::KX_##name)) #define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyInt_FromLong(name)) diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h index dc4bad05efb..85616e26b6c 100644 --- a/source/gameengine/Ketsji/KX_PythonInit.h +++ b/source/gameengine/Ketsji/KX_PythonInit.h @@ -51,6 +51,9 @@ void exitGamePlayerPythonScripting(); PyObject* initGamePythonScripting(const STR_String& progname, TPythonSecurityLevel level); void exitGamePythonScripting(); void PHY_SetActiveScene(class KX_Scene* scene); +#include "MT_Vector3.h" + +void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color); #endif //__KX_PYTHON_INIT diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index 609f0fc0e0b..a062a348b02 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -1,3 +1,6 @@ +#include "KX_ConvertPhysicsObject.h" + +#ifdef USE_SUMO_SOLID #ifdef WIN32 #pragma warning (disable : 4786) @@ -216,3 +219,4 @@ KX_SumoPhysicsController::~KX_SumoPhysicsController() } +#endif//USE_SUMO_SOLID diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index 376a75f40d3..8b423204bec 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -7,7 +7,7 @@ class BP_Proxy; -bool gEnableSleeping = true;//false;//true; +bool gEnableSleeping = false;//false;//true; #include "Dynamics/MassProps.h" SimdVector3 startVel(0,0,0);//-10000); diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index 2a89cd0cf4a..a4c9df51466 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -47,6 +47,43 @@ 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) +{ + SimdVector3 halfExtents = (to-from)* 0.5f; + SimdVector3 center = (to+from) *0.5f; + int i,j; + + SimdVector3 edgecoord(1.f,1.f,1.f),pa,pb; + for (i=0;i<4;i++) + { + for (j=0;j<3;j++) + { + pa = SimdVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1], + edgecoord[2]*halfExtents[2]); + pa+=center; + + int othercoord = j%3; + edgecoord[othercoord]*=-1.f; + pb = SimdVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1], + edgecoord[2]*halfExtents[2]); + pb+=center; + + debugDrawer->DrawLine(pa,pb,color); + } + edgecoord = SimdVector3(-1.f,-1.f,-1.f); + if (i<3) + edgecoord[i]*=-1.f; + } + + +} + + + + + + CcdPhysicsEnvironment::CcdPhysicsEnvironment(ToiContactDispatcher* dispatcher,BroadphaseInterface* bp) :m_dispatcher(dispatcher), m_broadphase(bp), @@ -402,10 +439,16 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) SimdPoint3 minAabb,maxAabb; CollisionShape* shapeinterface = ctrl->GetCollisionShape(); + + + shapeinterface->CalculateTemporalAabb(body->getCenterOfMassTransform(), body->getLinearVelocity(),body->getAngularVelocity(), timeStep,minAabb,maxAabb); + shapeinterface->GetAabb(body->getCenterOfMassTransform(), + minAabb,maxAabb); + BroadphaseProxy* bp = (BroadphaseProxy*) ctrl->m_broadphaseHandle; if (bp) @@ -414,7 +457,11 @@ bool CcdPhysicsEnvironment::proceedDeltaTime(double curTime,float timeStep) #ifdef WIN32 SimdVector3 color (1,0,0); if (m_debugDrawer) - m_debugDrawer->DrawLine(minAabb,maxAabb,color); + { + //draw aabb + + DrawAabb(m_debugDrawer,minAabb,maxAabb,color); + } #endif scene->SetAabb(bp,minAabb,maxAabb); } diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 48991566fa5..03c7e1d5116 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -333,6 +333,7 @@ public: */ virtual void SetPolygonOffset(float mult, float add) = 0; + virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0; }; #endif //__RAS_IRASTERIZER diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index 95688580fa3..f9d70f1d23f 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -401,6 +401,21 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void) void RAS_OpenGLRasterizer::EndFrame() { + //DrawDebugLines + glBegin(GL_LINES); + for (unsigned int i=0;i<m_debugLines.size();i++) + { + glColor4f(m_debugLines[i].m_color[0],m_debugLines[i].m_color[1],m_debugLines[i].m_color[2],1.f); + const MT_Scalar* fromPtr = &m_debugLines[i].m_from.x(); + const MT_Scalar* toPtr= &m_debugLines[i].m_to.x(); + + glVertex3dv(fromPtr); + glVertex3dv(toPtr); + } + glEnd(); + + m_debugLines.clear(); + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); m_2DCanvas->EndFrame(); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h index 2571cee1333..ad6bdf8c1d1 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h @@ -44,6 +44,13 @@ using namespace std; #include "RAS_MaterialBucket.h" #include "RAS_ICanvas.h" +struct OglDebugLine +{ + MT_Vector3 m_from; + MT_Vector3 m_to; + MT_Vector3 m_color; +}; + /** * 3D rendering device context. */ @@ -226,6 +233,17 @@ public: ); virtual void SetPolygonOffset(float mult, float add); + virtual void DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color) + { + OglDebugLine line; + line.m_from = from; + line.m_to = to; + line.m_color = color; + m_debugLines.push_back(line); + } + + std::vector <OglDebugLine> m_debugLines; + }; #endif //__RAS_OPENGLRASTERIZER |