updated VehicleDemo to show Z as up-axis, rather then Y.
proper gravity for BspDemo
This commit is contained in:
@@ -134,7 +134,7 @@ void BspDemo::initPhysics(char* bspfilename)
|
|||||||
|
|
||||||
///Setup a Physics Simulation Environment
|
///Setup a Physics Simulation Environment
|
||||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||||
m_dynamicsWorld->setGravity(-m_cameraUp);
|
m_dynamicsWorld->setGravity(-m_cameraUp * 10);
|
||||||
|
|
||||||
|
|
||||||
#ifdef QUAKE_BSP_IMPORTING
|
#ifdef QUAKE_BSP_IMPORTING
|
||||||
|
|||||||
@@ -20,6 +20,25 @@ subject to the following restrictions:
|
|||||||
/// with gears etc.
|
/// with gears etc.
|
||||||
#include "btBulletDynamicsCommon.h"
|
#include "btBulletDynamicsCommon.h"
|
||||||
|
|
||||||
|
//
|
||||||
|
// 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
|
||||||
|
|
||||||
#include "GLDebugDrawer.h"
|
#include "GLDebugDrawer.h"
|
||||||
#include <stdio.h> //printf debugging
|
#include <stdio.h> //printf debugging
|
||||||
@@ -47,8 +66,8 @@ float suspensionStiffness = 20.f;
|
|||||||
float suspensionDamping = 2.3f;
|
float suspensionDamping = 2.3f;
|
||||||
float suspensionCompression = 4.4f;
|
float suspensionCompression = 4.4f;
|
||||||
float rollInfluence = 0.1f;//1.0f;
|
float rollInfluence = 0.1f;//1.0f;
|
||||||
btVector3 wheelDirectionCS0(0,-1,0);
|
|
||||||
btVector3 wheelAxleCS(1,0,0);
|
|
||||||
btScalar suspensionRestLength(0.6);
|
btScalar suspensionRestLength(0.6);
|
||||||
|
|
||||||
#define CUBE_HALF_EXTENTS 1
|
#define CUBE_HALF_EXTENTS 1
|
||||||
@@ -84,11 +103,16 @@ m_maxCameraDistance(10.f)
|
|||||||
|
|
||||||
void VehicleDemo::setupPhysics()
|
void VehicleDemo::setupPhysics()
|
||||||
{
|
{
|
||||||
|
#ifdef FORCE_ZAXIS_UP
|
||||||
|
m_cameraUp = btVector3(0,0,1);
|
||||||
|
m_forwardAxis = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
btCollisionShape* groundShape = new btBoxShape(btVector3(50,3,50));
|
||||||
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
||||||
|
#ifdef FORCE_ZAXIS_UP
|
||||||
|
m_dynamicsWorld->setGravity(btVector3(0,0,-10));
|
||||||
|
#endif
|
||||||
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
m_dynamicsWorld->setDebugDrawer(&debugDrawer);
|
||||||
|
|
||||||
|
|
||||||
@@ -119,7 +143,20 @@ const float TRIANGLE_SIZE=20.f;
|
|||||||
{
|
{
|
||||||
float wl = .2f;
|
float wl = .2f;
|
||||||
float height = 20.f*sinf(float(i)*wl)*cosf(float(j)*wl);
|
float height = 20.f*sinf(float(i)*wl)*cosf(float(j)*wl);
|
||||||
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,height,(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
#ifdef FORCE_ZAXIS_UP
|
||||||
|
gVertices[i+j*NUM_VERTS_X].setValue(
|
||||||
|
(i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||||
|
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE,
|
||||||
|
height
|
||||||
|
);
|
||||||
|
|
||||||
|
#else
|
||||||
|
gVertices[i+j*NUM_VERTS_X].setValue(
|
||||||
|
(i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,
|
||||||
|
height,
|
||||||
|
(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,12 +192,25 @@ const float TRIANGLE_SIZE=20.f;
|
|||||||
//create ground object
|
//create ground object
|
||||||
localCreateRigidBody(0,tr,groundShape);
|
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));
|
btCollisionShape* chassisShape = new btBoxShape(btVector3(1.f,0.5f,2.f));
|
||||||
btCompoundShape* compound = new btCompoundShape();
|
btCompoundShape* compound = new btCompoundShape();
|
||||||
btTransform localTrans;
|
btTransform localTrans;
|
||||||
localTrans.setIdentity();
|
localTrans.setIdentity();
|
||||||
//localTrans effectively shifts the center of mass with respect to the chassis
|
//localTrans effectively shifts the center of mass with respect to the chassis
|
||||||
localTrans.setOrigin(btVector3(0,1,0));
|
localTrans.setOrigin(btVector3(0,1,0));
|
||||||
|
#endif
|
||||||
|
|
||||||
compound->addChildShape(localTrans,chassisShape);
|
compound->addChildShape(localTrans,chassisShape);
|
||||||
|
|
||||||
tr.setOrigin(btVector3(0,0.f,0));
|
tr.setOrigin(btVector3(0,0.f,0));
|
||||||
@@ -185,20 +235,37 @@ const float TRIANGLE_SIZE=20.f;
|
|||||||
float connectionHeight = 1.2f;
|
float connectionHeight = 1.2f;
|
||||||
|
|
||||||
|
|
||||||
btVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),connectionHeight,2*CUBE_HALF_EXTENTS-wheelRadius);
|
|
||||||
bool isFrontWheel=true;
|
bool isFrontWheel=true;
|
||||||
int rightIndex = 0;
|
|
||||||
int upIndex = 1;
|
|
||||||
int forwardIndex = 2;
|
|
||||||
|
|
||||||
|
//choose coordinate system
|
||||||
m_vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
|
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);
|
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);
|
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);
|
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);
|
connectionPointCS0 = btVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),connectionHeight,-2*CUBE_HALF_EXTENTS+wheelRadius);
|
||||||
|
#endif //FORCE_ZAXIS_UP
|
||||||
isFrontWheel = false;
|
isFrontWheel = false;
|
||||||
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
|
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);
|
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);
|
m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxleCS,suspensionRestLength,wheelRadius,m_tuning,isFrontWheel);
|
||||||
|
|
||||||
for (int i=0;i<m_vehicle->getNumWheels();i++)
|
for (int i=0;i<m_vehicle->getNumWheels();i++)
|
||||||
@@ -281,15 +348,14 @@ void VehicleDemo::clientMoveAndDisplay()
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int steerWheelIndex = 2;
|
int wheelIndex = 2;
|
||||||
m_vehicle->applyEngineForce(gEngineForce,steerWheelIndex);
|
m_vehicle->applyEngineForce(gEngineForce,wheelIndex);
|
||||||
steerWheelIndex = 3;
|
wheelIndex = 3;
|
||||||
m_vehicle->applyEngineForce(gEngineForce,steerWheelIndex);
|
m_vehicle->applyEngineForce(gEngineForce,wheelIndex);
|
||||||
|
wheelIndex = 0;
|
||||||
steerWheelIndex = 0;
|
m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex);
|
||||||
m_vehicle->setSteeringValue(gVehicleSteering,steerWheelIndex);
|
wheelIndex = 1;
|
||||||
steerWheelIndex = 1;
|
m_vehicle->setSteeringValue(gVehicleSteering,wheelIndex);
|
||||||
m_vehicle->setSteeringValue(gVehicleSteering,steerWheelIndex);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,12 +449,12 @@ void VehicleDemo::specialKeyboard(int key, int x, int y)
|
|||||||
}
|
}
|
||||||
case GLUT_KEY_UP :
|
case GLUT_KEY_UP :
|
||||||
{
|
{
|
||||||
gEngineForce = -maxEngineForce;
|
gEngineForce = maxEngineForce;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case GLUT_KEY_DOWN :
|
case GLUT_KEY_DOWN :
|
||||||
{
|
{
|
||||||
gEngineForce = maxEngineForce;
|
gEngineForce = -maxEngineForce;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -416,7 +482,11 @@ void VehicleDemo::updateCamera()
|
|||||||
m_cameraTargetPosition = chassisWorldTrans.getOrigin();
|
m_cameraTargetPosition = chassisWorldTrans.getOrigin();
|
||||||
|
|
||||||
//interpolate the camera height
|
//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;
|
m_cameraPosition[1] = (15.0*m_cameraPosition[1] + m_cameraTargetPosition[1] + m_cameraHeight)/16.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
btVector3 camToObject = m_cameraTargetPosition - m_cameraPosition;
|
btVector3 camToObject = m_cameraTargetPosition - m_cameraPosition;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user