set upaxis for all demos (either Y/1 or Z/2)

This commit is contained in:
erwin coumans 2015-04-29 14:02:50 -07:00
parent 40375983d6
commit f9b8120e5d
10 changed files with 33 additions and 272 deletions

View File

@ -14,6 +14,7 @@ public:
{
}
virtual void initPhysics()=0;
virtual void exitPhysics()=0;
virtual void stepSimulation(float deltaTime)=0;

View File

@ -100,6 +100,8 @@ void AllConstraintDemo::setupEmptyDynamicsWorld()
void AllConstraintDemo::initPhysics()
{
m_guiHelper->setUpAxis(1);
m_Time = 0;
setupEmptyDynamicsWorld();

View File

@ -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);

View File

@ -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;i<m_vehicle->getNumWheels();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)
{

View File

@ -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);

View File

@ -76,7 +76,7 @@ void MultiDofDemo::stepSimulation(float deltaTime)
void MultiDofDemo::initPhysics()
{
m_guiHelper->setUpAxis(1);
if(g_firstInit)
{

View File

@ -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);

View File

@ -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

View File

@ -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;i<m_vehicle->getNumWheels();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)
{

View File

@ -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);