From d605cc1cd7809e4c50ac871527a59375ecc6053e Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Sat, 28 Mar 2015 12:36:57 -0700 Subject: [PATCH] render the wheels of the ForkLiftDemo --- Demos/ForkLiftDemo/ForkLiftPhysicsSetup.cpp | 40 +++++++++++++++++-- .../Bullet2RigidBodyDemo.cpp | 6 +++ btgui/Bullet3AppSupport/CommonPhysicsSetup.h | 4 ++ btgui/OpenGLWindow/SimpleOpenGL3App.cpp | 4 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/Demos/ForkLiftDemo/ForkLiftPhysicsSetup.cpp b/Demos/ForkLiftDemo/ForkLiftPhysicsSetup.cpp index 2a01bebaa..edb556828 100644 --- a/Demos/ForkLiftDemo/ForkLiftPhysicsSetup.cpp +++ b/Demos/ForkLiftDemo/ForkLiftPhysicsSetup.cpp @@ -2,7 +2,7 @@ #include "BulletDynamics/MLCPSolvers/btDantzigSolver.h" #include "BulletDynamics/MLCPSolvers/btSolveProjectedGaussSeidel.h" #include "BulletDynamics/MLCPSolvers/btMLCPSolver.h" - +#include "OpenGLWindow/CommonRenderInterface.h" btScalar maxMotorImpulse = 1400.f; btScalar loadMass = 350.f;// @@ -66,7 +66,9 @@ struct ForkLiftInternalData class btConstraintSolver* m_constraintSolver; class btDefaultCollisionConfiguration* m_collisionConfiguration; class btDiscreteDynamicsWorld* m_dynamicsWorld; - + + int m_wheelInstances[4]; + bool useMCLPSolver; ForkLiftInternalData() @@ -191,6 +193,19 @@ tr.setOrigin(btVector3(0,-3,0)); //m_carChassis->setDamping(0.2,0.2); m_data->m_wheelShape = new btCylinderShapeX(btVector3(wheelWidth,wheelRadius,wheelRadius)); + gfxBridge.createCollisionShapeGraphicsObject(m_data->m_wheelShape); + int wheelGraphicsIndex = m_data->m_wheelShape->getUserIndex(); + + const float position[4]={0,10,10,0}; + const float quaternion[4]={0,0,0,1}; + const float color[4]={0,1,0,1}; + const float scaling[4] = {1,1,1,1}; + + for (int i=0;i<4;i++) + { + m_data->m_wheelInstances[i] = gfxBridge.registerGraphicsInstance(wheelGraphicsIndex, position, quaternion, color, scaling); + } + { btCollisionShape* liftShape = new btBoxShape(btVector3(0.5f,2.0f,0.05f)); @@ -436,6 +451,7 @@ void ForkLiftPhysicsSetup::exitPhysics() } void ForkLiftPhysicsSetup::stepSimulation(float deltaTime) { + m_data->m_dynamicsWorld->stepSimulation(deltaTime); } void ForkLiftPhysicsSetup::debugDraw(int debugDrawFlags) { @@ -453,11 +469,29 @@ void ForkLiftPhysicsSetup::removePickingConstraint() } void ForkLiftPhysicsSetup::syncPhysicsToGraphics(GraphicsPhysicsBridge& gfxBridge) { + gfxBridge.syncPhysicsToGraphics(m_data->m_dynamicsWorld); + //sync wheels + + for (int i=0;im_vehicle->getNumWheels();i++) + { + //synchronize the wheels with the (interpolated) chassis worldtransform + m_data->m_vehicle->updateWheelTransform(i,true); + + CommonRenderInterface* renderer = gfxBridge.getRenderInterface(); + if (renderer) + { + btTransform tr = m_data->m_vehicle->getWheelInfo(i).m_worldTransform; + btVector3 pos=tr.getOrigin(); + btQuaternion orn = tr.getRotation(); + renderer->writeSingleInstanceTransformToCPU(pos,orn,m_data->m_wheelInstances[i]); + } + } + } void ForkLiftPhysicsSetup::renderScene(GraphicsPhysicsBridge& gfxBridge) { - + gfxBridge.drawText3D("hi!",0,10,10,2); } void ForkLiftPhysicsSetup::lockLiftHinge() diff --git a/btgui/Bullet3AppSupport/Bullet2RigidBodyDemo.cpp b/btgui/Bullet3AppSupport/Bullet2RigidBodyDemo.cpp index ac0acf95c..33d25ed03 100644 --- a/btgui/Bullet3AppSupport/Bullet2RigidBodyDemo.cpp +++ b/btgui/Bullet3AppSupport/Bullet2RigidBodyDemo.cpp @@ -30,6 +30,12 @@ struct MyGraphicsPhysicsBridge : public GraphicsPhysicsBridge :m_glApp(glApp), m_debugDraw(0), m_curColor(0) { } + + virtual struct CommonRenderInterface* getRenderInterface() + { + return m_glApp->m_renderer; + } + virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color) { createCollisionObjectGraphicsObject(body,color); diff --git a/btgui/Bullet3AppSupport/CommonPhysicsSetup.h b/btgui/Bullet3AppSupport/CommonPhysicsSetup.h index ef1838d33..616e352de 100644 --- a/btgui/Bullet3AppSupport/CommonPhysicsSetup.h +++ b/btgui/Bullet3AppSupport/CommonPhysicsSetup.h @@ -48,6 +48,10 @@ struct GraphicsPhysicsBridge return 0; } + virtual struct CommonRenderInterface* getRenderInterface() + { + return 0; + } virtual void setUpAxis(int axis) { } diff --git a/btgui/OpenGLWindow/SimpleOpenGL3App.cpp b/btgui/OpenGLWindow/SimpleOpenGL3App.cpp index 814e65196..e8df27f5e 100644 --- a/btgui/OpenGLWindow/SimpleOpenGL3App.cpp +++ b/btgui/OpenGLWindow/SimpleOpenGL3App.cpp @@ -255,7 +255,7 @@ void SimpleOpenGL3App::drawText3D( const char* txt, float worldPosX, float world //float extraSpacing = 0.; float startX = posX; - float startY = posY-g_DefaultLargeFont->m_CharHeight; + float startY = posY-g_DefaultLargeFont->m_CharHeight*size1; while (txt[pos]) @@ -263,7 +263,7 @@ void SimpleOpenGL3App::drawText3D( const char* txt, float worldPosX, float world int c = txt[pos]; //r.h = g_DefaultNormalFont->m_CharHeight; //r.w = g_DefaultNormalFont->m_CharWidth[c]+extraSpacing; - float endX = startX+g_DefaultLargeFont->m_CharWidth[c]; + float endX = startX+g_DefaultLargeFont->m_CharWidth[c]*size1; float endY = posY;