From f9b8120e5d184912412b9d2a74b99b87ea728315 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Wed, 29 Apr 2015 14:02:50 -0700 Subject: [PATCH] set upaxis for all demos (either Y/1 or Z/2) --- .../CommonInterfaces/CommonExampleInterface.h | 1 + examples/Constraints/ConstraintDemo.cpp | 2 + examples/Constraints/Dof6Spring2Setup.cpp | 2 + examples/ForkLift/ForkLiftDemo.cpp | 123 ++----------- .../Importers/ImportBsp/ImportBspExample.cpp | 1 + examples/MultiBody/MultiDofDemo.cpp | 2 +- examples/MultiBody/TestJointTorqueSetup.cpp | 3 +- examples/SoftDemo/SoftDemo.cpp | 2 +- examples/Vehicles/Hinge2Vehicle.cpp | 165 +----------------- .../VoronoiFracture/VoronoiFractureDemo.cpp | 4 + 10 files changed, 33 insertions(+), 272 deletions(-) diff --git a/examples/CommonInterfaces/CommonExampleInterface.h b/examples/CommonInterfaces/CommonExampleInterface.h index 7197be72c..a9ccda4ba 100644 --- a/examples/CommonInterfaces/CommonExampleInterface.h +++ b/examples/CommonInterfaces/CommonExampleInterface.h @@ -14,6 +14,7 @@ public: { } + virtual void initPhysics()=0; virtual void exitPhysics()=0; virtual void stepSimulation(float deltaTime)=0; diff --git a/examples/Constraints/ConstraintDemo.cpp b/examples/Constraints/ConstraintDemo.cpp index c18a43710..14bc2504c 100644 --- a/examples/Constraints/ConstraintDemo.cpp +++ b/examples/Constraints/ConstraintDemo.cpp @@ -100,6 +100,8 @@ void AllConstraintDemo::setupEmptyDynamicsWorld() void AllConstraintDemo::initPhysics() { + m_guiHelper->setUpAxis(1); + m_Time = 0; setupEmptyDynamicsWorld(); diff --git a/examples/Constraints/Dof6Spring2Setup.cpp b/examples/Constraints/Dof6Spring2Setup.cpp index c78e76220..1860bd173 100644 --- a/examples/Constraints/Dof6Spring2Setup.cpp +++ b/examples/Constraints/Dof6Spring2Setup.cpp @@ -94,6 +94,8 @@ void Dof6Spring2Setup::initPhysics() { // Setup the basic world + m_guiHelper->setUpAxis(1); + m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); btVector3 worldAabbMin(-10000,-10000,-10000); diff --git a/examples/ForkLift/ForkLiftDemo.cpp b/examples/ForkLift/ForkLiftDemo.cpp index faa1e2971..c606c492e 100644 --- a/examples/ForkLift/ForkLiftDemo.cpp +++ b/examples/ForkLift/ForkLiftDemo.cpp @@ -117,9 +117,6 @@ class ForkLiftDemo : public CommonExampleInterface virtual void displayCallback(); - ///a very basic camera following the vehicle - virtual void updateCamera(); - virtual void specialKeyboard(int key, int x, int y); virtual void specialKeyboardUp(int key, int x, int y); @@ -174,26 +171,11 @@ btScalar loadMass = 350.f;// #define M_PI_4 0.785398163397448309616 #endif -//#define LIFT_EPS 0.0000001f -// -// By default, Bullet Vehicle uses Y as up axis. -// You can override the up axis, for example Z-axis up. Enable this define to see how to: -//#define FORCE_ZAXIS_UP 1 -// - -#ifdef FORCE_ZAXIS_UP - int rightIndex = 0; - int upIndex = 2; - int forwardIndex = 1; - btVector3 wheelDirectionCS0(0,0,-1); - btVector3 wheelAxleCS(1,0,0); -#else int rightIndex = 0; int upIndex = 1; int forwardIndex = 2; btVector3 wheelDirectionCS0(0,-1,0); btVector3 wheelAxleCS(-1,0,0); -#endif bool useMCLPSolver = true; @@ -340,13 +322,16 @@ ForkLiftDemo::~ForkLiftDemo() void ForkLiftDemo::initPhysics() { - -#ifdef FORCE_ZAXIS_UP - m_cameraUp = btVector3(0,0,1); - m_forwardAxis = 1; -#endif - btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50)); + + + int upAxis = 1; + + m_guiHelper->setUpAxis(upAxis); + + btVector3 groundExtents(50,50,50); + groundExtents[upAxis]=3; + btCollisionShape* groundShape = new btBoxShape(groundExtents); m_collisionShapes.push_back(groundShape); m_collisionConfiguration = new btDefaultCollisionConfiguration(); m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration); @@ -374,9 +359,6 @@ void ForkLiftDemo::initPhysics() m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); -#ifdef FORCE_ZAXIS_UP - m_dynamicsWorld->setGravity(btVector3(0,0,-10)); -#endif //m_dynamicsWorld->setGravity(btVector3(0,0,0)); btTransform tr; @@ -389,17 +371,6 @@ tr.setOrigin(btVector3(0,-3,0)); //create ground object localCreateRigidBody(0,tr,groundShape); -#ifdef FORCE_ZAXIS_UP -// indexRightAxis = 0; -// indexUpAxis = 2; -// indexForwardAxis = 1; - btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,2.f, 0.5f)); - btCompoundShape* compound = new btCompoundShape(); - btTransform localTrans; - localTrans.setIdentity(); - //localTrans effectively shifts the center of mass with respect to the chassis - localTrans.setOrigin(btVector3(0,0,1)); -#else btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,0.5f,2.f)); m_collisionShapes.push_back(chassisShape); @@ -409,7 +380,6 @@ tr.setOrigin(btVector3(0,-3,0)); localTrans.setIdentity(); //localTrans effectively shifts the center of mass with respect to the chassis localTrans.setOrigin(btVector3(0,1,0)); -#endif compound->addChildShape(localTrans,chassisShape); @@ -553,32 +523,16 @@ tr.setOrigin(btVector3(0,-3,0)); //choose coordinate system m_vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex); -#ifdef FORCE_ZAXIS_UP - btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),2*CUBE_HALF_EXTENTS-wheelRadius, connectionHeight); -#else btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius); -#endif m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),2*CUBE_HALF_EXTENTS-wheelRadius, connectionHeight); -#else connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius); -#endif m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),-2*CUBE_HALF_EXTENTS+wheelRadius, connectionHeight); -#else connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius); -#endif //FORCE_ZAXIS_UP isFrontWheel = false; m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),-2*CUBE_HALF_EXTENTS+wheelRadius, connectionHeight); -#else connectionPointCS0 = btVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius); -#endif m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); for (int i=0;igetNumWheels();i++) @@ -628,8 +582,7 @@ void ForkLiftDemo::renderScene() } } - updateCamera(); - + m_guiHelper->render(m_dynamicsWorld); @@ -1167,62 +1120,6 @@ void ForkLiftDemo::specialKeyboard(int key, int x, int y) #endif } -void ForkLiftDemo::updateCamera() -{ - -#if 0 -//#define DISABLE_CAMERA 1 - if(m_useDefaultCamera) - { - DemoApplication::updateCamera(); - return; - } - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - btTransform chassisWorldTrans; - - //look at the vehicle - m_carChassis->getMotionState()->getWorldTransform(chassisWorldTrans); - m_cameraTargetPosition = chassisWorldTrans.getOrigin(); - - //interpolate the camera height -#ifdef FORCE_ZAXIS_UP - m_cameraPosition[2] = (15.0*m_cameraPosition[2] + m_cameraTargetPosition[2] + m_cameraHeight)/16.0; -#else - m_cameraPosition[1] = (15.0*m_cameraPosition[1] + m_cameraTargetPosition[1] + m_cameraHeight)/16.0; -#endif - - btVector3 camToObject = m_cameraTargetPosition - m_cameraPosition; - - //keep distance between min and max distance - float cameraDistance = camToObject.length(); - float correctionFactor = 0.f; - if (cameraDistance < m_minCameraDistance) - { - correctionFactor = 0.15*(m_minCameraDistance-cameraDistance)/cameraDistance; - } - if (cameraDistance > m_maxCameraDistance) - { - correctionFactor = 0.15*(m_maxCameraDistance-cameraDistance)/cameraDistance; - } - m_cameraPosition -= correctionFactor*camToObject; - - //update OpenGL camera settings - btScalar aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; - glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2], - m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2], - m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ()); - - -#endif -} void ForkLiftDemo::lockLiftHinge(void) { diff --git a/examples/Importers/ImportBsp/ImportBspExample.cpp b/examples/Importers/ImportBsp/ImportBspExample.cpp index 02384f66b..7045d2bf4 100644 --- a/examples/Importers/ImportBsp/ImportBspExample.cpp +++ b/examples/Importers/ImportBsp/ImportBspExample.cpp @@ -139,6 +139,7 @@ void BspDemo::initPhysics(const char* bspfilename) { int cameraUpAxis =2; + m_guiHelper->setUpAxis(cameraUpAxis); btVector3 grav(0,0,0); grav[cameraUpAxis] = -10; m_guiHelper->setUpAxis(cameraUpAxis); diff --git a/examples/MultiBody/MultiDofDemo.cpp b/examples/MultiBody/MultiDofDemo.cpp index b324ff20e..e7a4fa585 100644 --- a/examples/MultiBody/MultiDofDemo.cpp +++ b/examples/MultiBody/MultiDofDemo.cpp @@ -76,7 +76,7 @@ void MultiDofDemo::stepSimulation(float deltaTime) void MultiDofDemo::initPhysics() { - + m_guiHelper->setUpAxis(1); if(g_firstInit) { diff --git a/examples/MultiBody/TestJointTorqueSetup.cpp b/examples/MultiBody/TestJointTorqueSetup.cpp index 5e6aef65a..95bbc4db2 100644 --- a/examples/MultiBody/TestJointTorqueSetup.cpp +++ b/examples/MultiBody/TestJointTorqueSetup.cpp @@ -33,6 +33,7 @@ TestJointTorqueSetup::~TestJointTorqueSetup() void TestJointTorqueSetup::initPhysics() { int upAxis = 2; + m_guiHelper->setUpAxis(upAxis); btVector4 colors[4] = { @@ -45,7 +46,7 @@ void TestJointTorqueSetup::initPhysics() - m_guiHelper->setUpAxis(upAxis); + this->createEmptyDynamicsWorld(); m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); diff --git a/examples/SoftDemo/SoftDemo.cpp b/examples/SoftDemo/SoftDemo.cpp index f779627f2..67ee63d6e 100644 --- a/examples/SoftDemo/SoftDemo.cpp +++ b/examples/SoftDemo/SoftDemo.cpp @@ -2063,7 +2063,7 @@ void SoftDemo::initPhysics() { ///create concave ground mesh - + m_guiHelper->setUpAxis(1); // m_azi = 0; //reset and disable motorcontrol at the start diff --git a/examples/Vehicles/Hinge2Vehicle.cpp b/examples/Vehicles/Hinge2Vehicle.cpp index b831ca674..ec4f7fcbd 100644 --- a/examples/Vehicles/Hinge2Vehicle.cpp +++ b/examples/Vehicles/Hinge2Vehicle.cpp @@ -102,9 +102,7 @@ class Hinge2Vehicle : public CommonRigidBodyBase virtual void displayCallback(); - ///a very basic camera following the vehicle - virtual void updateCamera(); - + virtual void specialKeyboard(int key, int x, int y); virtual void specialKeyboardUp(int key, int x, int y); @@ -150,26 +148,12 @@ static btScalar loadMass = 350.f;// #define M_PI_4 0.785398163397448309616 #endif -//#define LIFT_EPS 0.0000001f -// -// By default, Bullet Vehicle uses Y as up axis. -// You can override the up axis, for example Z-axis up. Enable this define to see how to: -//#define FORCE_ZAXIS_UP 1 -// -#ifdef FORCE_ZAXIS_UP - static int rightIndex = 0; - static int upIndex = 2; - static int forwardIndex = 1; - static btVector3 wheelDirectionCS0(0,0,-1); - static btVector3 wheelAxleCS(1,0,0); -#else - static int rightIndex = 0; - static int upIndex = 1; - static int forwardIndex = 2; - static btVector3 wheelDirectionCS0(0,-1,0); - static btVector3 wheelAxleCS(-1,0,0); -#endif +static int rightIndex = 0; +static int upIndex = 1; +static int forwardIndex = 2; +static btVector3 wheelDirectionCS0(0,-1,0); +static btVector3 wheelAxleCS(-1,0,0); static bool useMCLPSolver = false;//true; @@ -312,12 +296,9 @@ extern float shadowMapWorldSize; void Hinge2Vehicle::initPhysics() { - + m_guiHelper->setUpAxis(1); + shadowMapWorldSize = 10; -#ifdef FORCE_ZAXIS_UP - m_cameraUp = btVector3(0,0,1); - m_forwardAxis = 1; -#endif btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50)); m_collisionShapes.push_back(groundShape); @@ -347,9 +328,6 @@ void Hinge2Vehicle::initPhysics() m_dynamicsWorld->getSolverInfo().m_numIterations = 100; m_guiHelper->createPhysicsDebugDrawer(m_dynamicsWorld); -#ifdef FORCE_ZAXIS_UP - m_dynamicsWorld->setGravity(btVector3(0,0,-10)); -#endif //m_dynamicsWorld->setGravity(btVector3(0,0,0)); btTransform tr; @@ -362,17 +340,6 @@ tr.setOrigin(btVector3(0,-3,0)); //create ground object localCreateRigidBody(0,tr,groundShape); -#ifdef FORCE_ZAXIS_UP -// indexRightAxis = 0; -// indexUpAxis = 2; -// indexForwardAxis = 1; - btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,2.f, 0.5f)); - btCompoundShape* compound = new btCompoundShape(); - btTransform localTrans; - localTrans.setIdentity(); - //localTrans effectively shifts the center of mass with respect to the chassis - localTrans.setOrigin(btVector3(0,0,1)); -#else btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,0.5f,2.f)); m_collisionShapes.push_back(chassisShape); @@ -382,7 +349,6 @@ tr.setOrigin(btVector3(0,-3,0)); localTrans.setIdentity(); //localTrans effectively shifts the center of mass with respect to the chassis localTrans.setOrigin(btVector3(0,1,0)); -#endif compound->addChildShape(localTrans,chassisShape); @@ -555,63 +521,7 @@ tr.setOrigin(btVector3(0,-3,0)); - #if 0 - /// create vehicle - { - - - ///never deactivate the vehicle - m_carChassis->setActivationState(DISABLE_DEACTIVATION); - - - float connectionHeight = 1.2f; - - - bool isFrontWheel=true; - - - -#ifdef FORCE_ZAXIS_UP - btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),2*CUBE_HALF_EXTENTS-wheelRadius, connectionHeight); -#else - btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius); -#endif - - m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),2*CUBE_HALF_EXTENTS-wheelRadius, connectionHeight); -#else - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius); -#endif - - m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),-2*CUBE_HALF_EXTENTS+wheelRadius, connectionHeight); -#else - connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius); -#endif //FORCE_ZAXIS_UP - isFrontWheel = false; - m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); -#ifdef FORCE_ZAXIS_UP - connectionPointCS0 = btVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),-2*CUBE_HALF_EXTENTS+wheelRadius, connectionHeight); -#else - connectionPointCS0 = btVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius); -#endif - m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel); - - for (int i=0;igetNumWheels();i++) - { - btWheelInfo& wheel = m_vehicle->getWheelInfo(i); - wheel.m_suspensionStiffness = suspensionStiffness; - wheel.m_wheelsDampingRelaxation = suspensionDamping; - wheel.m_wheelsDampingCompression = suspensionCompression; - wheel.m_frictionSlip = wheelFriction; - wheel.m_rollInfluence = rollInfluence; - } - - } - #endif resetForklift(); // setCameraDistance(26.f); @@ -648,8 +558,7 @@ void Hinge2Vehicle::renderScene() } } #endif - updateCamera(); - + m_guiHelper->render(m_dynamicsWorld); @@ -1181,62 +1090,6 @@ void Hinge2Vehicle::specialKeyboard(int key, int x, int y) #endif } -void Hinge2Vehicle::updateCamera() -{ - -#if 0 -//#define DISABLE_CAMERA 1 - if(m_useDefaultCamera) - { - DemoApplication::updateCamera(); - return; - } - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - btTransform chassisWorldTrans; - - //look at the vehicle - m_carChassis->getMotionState()->getWorldTransform(chassisWorldTrans); - m_cameraTargetPosition = chassisWorldTrans.getOrigin(); - - //interpolate the camera height -#ifdef FORCE_ZAXIS_UP - m_cameraPosition[2] = (15.0*m_cameraPosition[2] + m_cameraTargetPosition[2] + m_cameraHeight)/16.0; -#else - m_cameraPosition[1] = (15.0*m_cameraPosition[1] + m_cameraTargetPosition[1] + m_cameraHeight)/16.0; -#endif - - btVector3 camToObject = m_cameraTargetPosition - m_cameraPosition; - - //keep distance between min and max distance - float cameraDistance = camToObject.length(); - float correctionFactor = 0.f; - if (cameraDistance < m_minCameraDistance) - { - correctionFactor = 0.15*(m_minCameraDistance-cameraDistance)/cameraDistance; - } - if (cameraDistance > m_maxCameraDistance) - { - correctionFactor = 0.15*(m_maxCameraDistance-cameraDistance)/cameraDistance; - } - m_cameraPosition -= correctionFactor*camToObject; - - //update OpenGL camera settings - btScalar aspect = m_glutScreenWidth / (btScalar)m_glutScreenHeight; - glFrustum (-aspect, aspect, -1.0, 1.0, 1.0, 10000.0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - gluLookAt(m_cameraPosition[0],m_cameraPosition[1],m_cameraPosition[2], - m_cameraTargetPosition[0],m_cameraTargetPosition[1], m_cameraTargetPosition[2], - m_cameraUp.getX(),m_cameraUp.getY(),m_cameraUp.getZ()); - - -#endif -} void Hinge2Vehicle::lockLiftHinge(void) { diff --git a/examples/VoronoiFracture/VoronoiFractureDemo.cpp b/examples/VoronoiFracture/VoronoiFractureDemo.cpp index f82bc43f7..c3926b2ad 100644 --- a/examples/VoronoiFracture/VoronoiFractureDemo.cpp +++ b/examples/VoronoiFracture/VoronoiFractureDemo.cpp @@ -84,6 +84,8 @@ class VoronoiFractureDemo : public CommonRigidBodyBase { btAssert(m_dynamicsWorld==0); } + + void initPhysics(); void exitPhysics(); @@ -613,6 +615,8 @@ void VoronoiFractureDemo::renderme() void VoronoiFractureDemo::initPhysics() { + m_guiHelper->setUpAxis(1); + srand(13); useGenericConstraint = !useGenericConstraint; printf("useGenericConstraint = %d\n", useGenericConstraint);