summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorejcoumans <ejcoumans@08e121b0-ae19-0410-a57b-3be3395fd4fd>2006-09-05 07:36:55 +0000
committerejcoumans <ejcoumans@08e121b0-ae19-0410-a57b-3be3395fd4fd>2006-09-05 07:36:55 +0000
commitfa96109cd995bfe8cbdcf068d1829136d76e8762 (patch)
tree8bbac162c5699b1b3e17fc9fa4c1e91ef08dbdf6
parente84716482d4e0c79f42d80dc7bb240e22e8af9b5 (diff)
downloadbullet3-fa96109cd995bfe8cbdcf068d1829136d76e8762.tar.gz
Exposed another glut method (the demos really require cleanup soon!)
First steps for a raycast-vehicle demo (far from finished)
-rw-r--r--Bullet/CollisionShapes/CylinderShape.h15
-rw-r--r--BulletDynamics/Vehicle/RaycastVehicle.cpp15
-rw-r--r--BulletDynamics/Vehicle/RaycastVehicle.h7
-rw-r--r--Demos/BspDemo/BspDemo.cpp5
-rw-r--r--Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp7
-rw-r--r--Demos/ColladaDemo/ColladaDemo.cpp5
-rw-r--r--Demos/CollisionDemo/CollisionDemo.cpp6
-rw-r--r--Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp5
-rw-r--r--Demos/ConcaveDemo/ConcavePhysicsDemo.cpp6
-rw-r--r--Demos/ConstraintDemo/ConstraintDemo.cpp6
-rw-r--r--Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp6
-rw-r--r--Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp5
-rw-r--r--Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp5
-rw-r--r--Demos/OpenGL/GL_ShapeDrawer.cpp16
-rw-r--r--Demos/OpenGL/GlutStuff.cpp9
-rw-r--r--Demos/OpenGL/GlutStuff.h3
-rw-r--r--Demos/Raytracer/Raytracer.cpp5
-rw-r--r--Demos/SimplexDemo/SimplexDemo.cpp5
-rw-r--r--Demos/VehicleDemo/VehicleDemo.cpp227
-rw-r--r--Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp5
-rw-r--r--Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h2
-rw-r--r--Extras/PhysicsInterface/Common/PHY_IVehicle.h13
22 files changed, 317 insertions, 61 deletions
diff --git a/Bullet/CollisionShapes/CylinderShape.h b/Bullet/CollisionShapes/CylinderShape.h
index 217ce7036..b99e3fa8c 100644
--- a/Bullet/CollisionShapes/CylinderShape.h
+++ b/Bullet/CollisionShapes/CylinderShape.h
@@ -71,6 +71,11 @@ public:
return 1;
}
+ virtual float GetRadius() const
+ {
+ return GetHalfExtents().getX();
+ }
+
//debugging
virtual char* GetName()const
{
@@ -98,6 +103,11 @@ public:
return "CylinderX";
}
+ virtual float GetRadius() const
+ {
+ return GetHalfExtents().getY();
+ }
+
};
class CylinderShapeZ : public CylinderShape
@@ -118,6 +128,11 @@ public:
return "CylinderZ";
}
+ virtual float GetRadius() const
+ {
+ return GetHalfExtents().getX();
+ }
+
};
diff --git a/BulletDynamics/Vehicle/RaycastVehicle.cpp b/BulletDynamics/Vehicle/RaycastVehicle.cpp
index c2a6f4d5d..2d31c104e 100644
--- a/BulletDynamics/Vehicle/RaycastVehicle.cpp
+++ b/BulletDynamics/Vehicle/RaycastVehicle.cpp
@@ -76,6 +76,7 @@ WheelInfo& RaycastVehicle::AddWheel( const SimdVector3& connectionPointCS, const
WheelInfo& wheel = m_wheelInfo[GetNumWheels()-1];
UpdateWheelTransformsWS( wheel );
+ UpdateWheelTransform(GetNumWheels()-1);
return wheel;
}
@@ -344,17 +345,9 @@ SimdScalar RaycastVehicle::GetSteeringValue(int wheel) const
void RaycastVehicle::ApplyEngineForce(SimdScalar force, int wheel)
{
- for (int i=0;i<GetNumWheels();i++)
- {
- WheelInfo& wheelInfo = GetWheelInfo(i);
-
- bool applyOnFrontWheel = !wheel;
-
- if (applyOnFrontWheel == wheelInfo.m_bIsFrontWheel)
- {
- wheelInfo.m_engineForce = force;
- }
- }
+ assert(wheel>=0 && wheel < GetNumWheels());
+ WheelInfo& wheelInfo = GetWheelInfo(wheel);
+ wheelInfo.m_engineForce = force;
}
diff --git a/BulletDynamics/Vehicle/RaycastVehicle.h b/BulletDynamics/Vehicle/RaycastVehicle.h
index 13993b87d..3410f03d7 100644
--- a/BulletDynamics/Vehicle/RaycastVehicle.h
+++ b/BulletDynamics/Vehicle/RaycastVehicle.h
@@ -143,6 +143,13 @@ public:
return m_indexForwardAxis;
}
+ virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
+ {
+ m_indexRightAxis = rightIndex;
+ m_indexUpAxis = upIndex;
+ m_indexForwardAxis = forwardIndex;
+ }
+
virtual void BuildJacobian()
{
//not yet
diff --git a/Demos/BspDemo/BspDemo.cpp b/Demos/BspDemo/BspDemo.cpp
index 60990b6a5..4acbb9d5b 100644
--- a/Demos/BspDemo/BspDemo.cpp
+++ b/Demos/BspDemo/BspDemo.cpp
@@ -668,6 +668,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false);
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
diff --git a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp
index 271963ee1..13f418f41 100644
--- a/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp
+++ b/Demos/CcdPhysicsDemo/CcdPhysicsDemo.cpp
@@ -851,6 +851,13 @@ void clientKeyboard(unsigned char key, int x, int y)
defaultKeyboard(key, x, y);
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
+
+
int gPickingConstraintId = 0;
SimdVector3 gOldPickingPos;
float gOldPickingDist = 0.f;
diff --git a/Demos/ColladaDemo/ColladaDemo.cpp b/Demos/ColladaDemo/ColladaDemo.cpp
index 1aa4760a6..f461a44b2 100644
--- a/Demos/ColladaDemo/ColladaDemo.cpp
+++ b/Demos/ColladaDemo/ColladaDemo.cpp
@@ -1399,6 +1399,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false);
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
diff --git a/Demos/CollisionDemo/CollisionDemo.cpp b/Demos/CollisionDemo/CollisionDemo.cpp
index caf66dabb..9c39dd2c4 100644
--- a/Demos/CollisionDemo/CollisionDemo.cpp
+++ b/Demos/CollisionDemo/CollisionDemo.cpp
@@ -197,6 +197,12 @@ void clientResetScene()
{
}
+
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp
index 5a85e4619..716ea1b48 100644
--- a/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp
+++ b/Demos/CollisionInterfaceDemo/CollisionInterfaceDemo.cpp
@@ -193,6 +193,11 @@ void clientResetScene()
objects[1].m_worldTransform.setOrigin(SimdVector3(0.0f,9.f,0.f));
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp
index 27b54fb96..429eb56fc 100644
--- a/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp
+++ b/Demos/ConcaveDemo/ConcavePhysicsDemo.cpp
@@ -484,6 +484,12 @@ void clientResetScene()
{
}
+
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/ConstraintDemo/ConstraintDemo.cpp b/Demos/ConstraintDemo/ConstraintDemo.cpp
index 7fa48d85c..d9d38acc3 100644
--- a/Demos/ConstraintDemo/ConstraintDemo.cpp
+++ b/Demos/ConstraintDemo/ConstraintDemo.cpp
@@ -381,6 +381,12 @@ void clientResetScene()
}
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp b/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp
index 09475e671..0c1808c2c 100644
--- a/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp
+++ b/Demos/ContinuousConvexCollision/ContinuousConvexCollisionDemo.cpp
@@ -303,6 +303,12 @@ void clientResetScene()
{
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
index d31de53a9..4e625ace9 100644
--- a/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
+++ b/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
@@ -918,6 +918,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false);
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
diff --git a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp
index 7f035c569..49e060ee0 100644
--- a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp
+++ b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp
@@ -243,6 +243,11 @@ void clientResetScene()
{
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/OpenGL/GL_ShapeDrawer.cpp b/Demos/OpenGL/GL_ShapeDrawer.cpp
index 91d5b4c5c..b81e286e1 100644
--- a/Demos/OpenGL/GL_ShapeDrawer.cpp
+++ b/Demos/OpenGL/GL_ShapeDrawer.cpp
@@ -192,21 +192,23 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
int upAxis = cylinder->GetUpAxis();
GLUquadricObj *quadObj = gluNewQuadric();
-
+ float radius = cylinder->GetRadius();
+ float halfHeight = cylinder->GetHalfExtents()[upAxis];
+
glPushMatrix();
switch (upAxis)
{
case 0:
glRotatef(-90.0, 0.0, 1.0, 0.0);
- glTranslatef(0.0, 0.0, -1.0);
+ glTranslatef(0.0, 0.0, -halfHeight);
break;
case 1:
glRotatef(-90.0, 1.0, 0.0, 0.0);
- glTranslatef(0.0, 0.0, -1.0);
+ glTranslatef(0.0, 0.0, -halfHeight);
break;
case 2:
- glTranslatef(0.0, 0.0, -1.0);
+ glTranslatef(0.0, 0.0, -halfHeight);
break;
default:
{
@@ -221,9 +223,9 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH);
- float radius = cylinder->GetHalfExtents().getX();
- float height = 2.f*cylinder->GetHalfExtents().getY();
- gluCylinder(quadObj, radius, radius, height, 15, 10);
+
+
+ gluCylinder(quadObj, radius, radius, 2.f*halfHeight, 15, 10);
glPopMatrix();
glEndList();
diff --git a/Demos/OpenGL/GlutStuff.cpp b/Demos/OpenGL/GlutStuff.cpp
index 71fcd570a..88ea4c204 100644
--- a/Demos/OpenGL/GlutStuff.cpp
+++ b/Demos/OpenGL/GlutStuff.cpp
@@ -136,6 +136,10 @@ void setCamera() {
eyePos[gForwardAxis] = -DISTANCE;
SimdVector3 forward(eyePos[0],eyePos[1],eyePos[2]);
+ if (forward.length2() < SIMD_EPSILON)
+ {
+ forward.setValue(1.f,0.f,0.f);
+ }
SimdVector3 right = gCameraUp.cross(forward);
SimdQuaternion roll(right,-rele);
@@ -289,7 +293,8 @@ void defaultKeyboard(unsigned char key, int x, int y)
}
-void mySpecial(int key, int x, int y)
+
+void defaultSpecialKeyboard(int key, int x, int y)
{
switch (key)
{
@@ -372,7 +377,7 @@ int glutmain(int argc, char **argv,int width,int height,const char* title) {
myinit();
glutKeyboardFunc(clientKeyboard);
- glutSpecialFunc(mySpecial);
+ glutSpecialFunc(clientSpecialKeyboard);
glutReshapeFunc(myReshape);
//createMenu();
glutIdleFunc(clientMoveAndDisplay);
diff --git a/Demos/OpenGL/GlutStuff.h b/Demos/OpenGL/GlutStuff.h
index 7a139a82a..d18d3dd0e 100644
--- a/Demos/OpenGL/GlutStuff.h
+++ b/Demos/OpenGL/GlutStuff.h
@@ -30,6 +30,9 @@ void setDebugMode(int mode);
void defaultKeyboard(unsigned char key, int x, int y);
void clientKeyboard(unsigned char key, int x, int y);
+void defaultSpecialKeyboard(int key, int x, int y);
+void clientSpecialKeyboard(int key, int x, int y);
+
void clientMouseFunc(int button, int state, int x, int y);
void clientMotionFunc(int x,int y);
#endif //GLUT_STUFF_H
diff --git a/Demos/Raytracer/Raytracer.cpp b/Demos/Raytracer/Raytracer.cpp
index d2194706a..4179c637e 100644
--- a/Demos/Raytracer/Raytracer.cpp
+++ b/Demos/Raytracer/Raytracer.cpp
@@ -405,6 +405,11 @@ void clientResetScene()
{
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/SimplexDemo/SimplexDemo.cpp b/Demos/SimplexDemo/SimplexDemo.cpp
index a5805e0e1..21a6c4acc 100644
--- a/Demos/SimplexDemo/SimplexDemo.cpp
+++ b/Demos/SimplexDemo/SimplexDemo.cpp
@@ -126,6 +126,11 @@ void clientResetScene()
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ defaultSpecialKeyboard(key,x,y);
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
diff --git a/Demos/VehicleDemo/VehicleDemo.cpp b/Demos/VehicleDemo/VehicleDemo.cpp
index 27d055361..c5cf0146c 100644
--- a/Demos/VehicleDemo/VehicleDemo.cpp
+++ b/Demos/VehicleDemo/VehicleDemo.cpp
@@ -13,14 +13,19 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
+//Ignore this USE_PARALLEL_DISPATCHER define, it is for future optimizations
//#define USE_PARALLEL_DISPATCHER 1
+/// September 2006: VehicleDemo is work in progress, this file is mostly just a placeholder
+/// This VehicleDemo file is very early in development, please check it later
+
+
+
#include "CcdPhysicsEnvironment.h"
#include "ParallelPhysicsEnvironment.h"
#include "CcdPhysicsController.h"
-#include "MyMotionState.h"
//#include "GL_LineSegmentShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/SphereShape.h"
@@ -29,12 +34,17 @@ subject to the following restrictions:
#include "CollisionShapes/CompoundShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "CollisionShapes/EmptyShape.h"
+#include "CollisionShapes/CylinderShape.h"
+
#include "CollisionShapes/TriangleMeshShape.h"
#include "CollisionShapes/TriangleIndexVertexArray.h"
#include "CollisionShapes/BvhTriangleMeshShape.h"
#include "CollisionShapes/TriangleMesh.h"
#include "Dynamics/RigidBody.h"
+#include "Vehicle/RaycastVehicle.h"
+#include "PHY_IVehicle.h"
+
#include "CollisionDispatch/CollisionDispatcher.h"
#include "ParallelIslandDispatcher.h"
@@ -94,21 +104,45 @@ const int maxProxies = 32766;
const int maxOverlap = 65535;
bool createConstraint = true;//false;
-bool useCompound = true;//false;
+bool useCompound = false;//true;//false;
#ifdef _DEBUG
-const int numObjects = 50;
+const int numObjects = 2;
#else
-const int numObjects = 120;
+const int numObjects = 2;
#endif
-
const int maxNumObjects = 32760;
-
-MyMotionState ms[maxNumObjects];
+DefaultMotionState ms[maxNumObjects];
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
int shapeIndex[maxNumObjects];
+
+
+DefaultMotionState wheelMotionState[4];
+
+///PHY_IVehicle is the interface behind the constraint that implements the raycast vehicle (WrapperVehicle which holds a RaycastVehicle)
+///notice that for higher-quality slow-moving vehicles, another approach might be better
+///implementing explicit hinged-wheel constraints with cylinder collision, rather then raycasts
+PHY_IVehicle* gVehicleConstraint=0;
+float gEngineForce = 0.f;
+float maxEngineForce = 1.f;
+float gVehicleSteering = 0.f;
+float steeringIncrement = 0.1f;
+float steeringClamp = 0.3f;
+float wheelRadius = 0.5f;
+float wheelWidth = 0.2f;
+float wheelFriction = 100.f;
+float suspensionStiffness = 10.f;
+float suspensionDamping = 1.3f;
+float suspensionCompression = 2.4f;
+float rollInfluence = 0.1f;
+SimdVector3 wheelDirectionCS0(0,-1,0);
+SimdVector3 wheelAxleCS(1,0,0);
+SimdScalar suspensionRestLength(0.6);
+
+
+
#ifdef USE_PARALLEL_DISPATCHER
ParallelPhysicsEnvironment* physicsEnvironmentPtr = 0;
#else
@@ -134,7 +168,7 @@ CollisionShape* shapePtr[numShapes] =
new BoxShape (SimdVector3(50,10,50)),
#endif
- new BoxShape (SimdVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
+ new BoxShape (SimdVector3(CUBE_HALF_EXTENTS,0.5f*CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS)),
new SphereShape (CUBE_HALF_EXTENTS- 0.05f),
//new ConeShape(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS),
@@ -180,7 +214,7 @@ int main(int argc,char** argv)
physicsEnvironmentPtr->setGravity(0,-10,0);//0,0);//-10,0);
int i;
-//#define USE_TRIMESH_GROUND 1
+#define USE_TRIMESH_GROUND 1
#ifdef USE_TRIMESH_GROUND
@@ -205,7 +239,7 @@ const float TRIANGLE_SIZE=20.f;
{
for (int j=0;j<NUM_VERTS_Y;j++)
{
- gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,2.f*sinf((float)i)*cosf((float)j),(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
+ gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*TRIANGLE_SIZE,2.f*sinf((float)i)*cosf((float)j)+10.f,(j-NUM_VERTS_Y*0.5f)*TRIANGLE_SIZE);
}
}
@@ -249,7 +283,7 @@ const float TRIANGLE_SIZE=20.f;
shapeProps.m_inertia = 1.f;
shapeProps.m_lin_drag = 0.2f;
shapeProps.m_ang_drag = 0.1f;
- shapeProps.m_mass = 10.0f;
+ shapeProps.m_mass = 800.0f;
PHY_MaterialProps materialProps;
materialProps.m_friction = 10.5f;
@@ -281,7 +315,7 @@ const float TRIANGLE_SIZE=20.f;
ident.setIdentity();
ident.setOrigin(SimdVector3(0,0,0));
compoundShape->AddChildShape(ident,oldShape);//
- ident.setOrigin(SimdVector3(0,0,2));
+ ident.setOrigin(SimdVector3(0,1,-1));
compoundShape->AddChildShape(ident,new SphereShape(0.9));//
}
@@ -422,15 +456,70 @@ const float TRIANGLE_SIZE=20.f;
constraintId =physicsEnvironmentPtr->createConstraint(
- physObjects[1],
- //0,
- physObjects[2],
- ////PHY_POINT2POINT_CONSTRAINT,
- PHY_GENERIC_6DOF_CONSTRAINT,//can leave any of the 6 degree of freedom 'free' or 'locked'
- //PHY_LINEHINGE_CONSTRAINT,
- pivotX,pivotY,pivotZ,
- axisX,axisY,axisZ
- );
+ physObjects[1],0,
+ PHY_VEHICLE_CONSTRAINT,
+ 0,0,0,
+ 0,0,0);
+
+ ///never deactivate the vehicle
+ physObjects[1]->GetRigidBody()->SetActivationState(DISABLE_DEACTIVATION);
+
+ gVehicleConstraint = physicsEnvironmentPtr->getVehicleConstraint(constraintId);
+
+ SimdVector3 connectionPointCS0(CUBE_HALF_EXTENTS-(0.3*wheelWidth),0,2*CUBE_HALF_EXTENTS-wheelRadius);
+ RaycastVehicle::VehicleTuning tuning;
+ bool isFrontWheel=true;
+ int rightIndex = 0;
+ int upIndex = 1;
+ int forwardIndex = 2;
+
+ gVehicleConstraint->SetCoordinateSystem(rightIndex,upIndex,forwardIndex);
+
+ gVehicleConstraint->AddWheel(&wheelMotionState[0],
+ (PHY__Vector3&)connectionPointCS0,
+ (PHY__Vector3&)wheelDirectionCS0,(PHY__Vector3&)wheelAxleCS,suspensionRestLength,wheelRadius,isFrontWheel);
+
+ connectionPointCS0 = SimdVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),0,2*CUBE_HALF_EXTENTS-wheelRadius);
+ gVehicleConstraint->AddWheel(&wheelMotionState[1],
+ (PHY__Vector3&)connectionPointCS0,
+ (PHY__Vector3&)wheelDirectionCS0,(PHY__Vector3&)wheelAxleCS,suspensionRestLength,wheelRadius,isFrontWheel);
+
+ connectionPointCS0 = SimdVector3(-CUBE_HALF_EXTENTS+(0.3*wheelWidth),0,-2*CUBE_HALF_EXTENTS+wheelRadius);
+ isFrontWheel = false;
+ gVehicleConstraint->AddWheel(&wheelMotionState[2],
+ (PHY__Vector3&)connectionPointCS0,
+ (PHY__Vector3&)wheelDirectionCS0,(PHY__Vector3&)wheelAxleCS,suspensionRestLength,wheelRadius,isFrontWheel);
+
+ connectionPointCS0 = SimdVector3(CUBE_HALF_EXTENTS-(0.3*wheelWidth),0,-2*CUBE_HALF_EXTENTS+wheelRadius);
+ gVehicleConstraint->AddWheel(&wheelMotionState[3],
+ (PHY__Vector3&)connectionPointCS0,
+ (PHY__Vector3&)wheelDirectionCS0,(PHY__Vector3&)wheelAxleCS,suspensionRestLength,wheelRadius,isFrontWheel);
+
+
+
+ gVehicleConstraint->SetSuspensionStiffness(suspensionStiffness,0);
+ gVehicleConstraint->SetSuspensionStiffness(suspensionStiffness,1);
+ gVehicleConstraint->SetSuspensionStiffness(suspensionStiffness,2);
+ gVehicleConstraint->SetSuspensionStiffness(suspensionStiffness,3);
+
+ gVehicleConstraint->SetSuspensionDamping(suspensionDamping,0);
+ gVehicleConstraint->SetSuspensionDamping(suspensionDamping,1);
+ gVehicleConstraint->SetSuspensionDamping(suspensionDamping,2);
+ gVehicleConstraint->SetSuspensionDamping(suspensionDamping,3);
+
+ gVehicleConstraint->SetSuspensionCompression(suspensionCompression,0);
+ gVehicleConstraint->SetSuspensionCompression(suspensionCompression,1);
+ gVehicleConstraint->SetSuspensionCompression(suspensionCompression,2);
+ gVehicleConstraint->SetSuspensionCompression(suspensionCompression,3);
+
+ gVehicleConstraint->SetWheelFriction(wheelFriction,0);
+ gVehicleConstraint->SetWheelFriction(wheelFriction,1);
+ gVehicleConstraint->SetWheelFriction(wheelFriction,2);
+ gVehicleConstraint->SetWheelFriction(wheelFriction,3);
+
+
+
+
}
@@ -440,28 +529,27 @@ const float TRIANGLE_SIZE=20.f;
return glutmain(argc, argv,640,480,"Bullet Vehicle Demo. http://www.continuousphysics.com/Bullet/phpBB2/");
}
+
//to be implemented by the demo
void renderme()
{
debugDrawer.SetDebugMode(getDebugMode());
+ float m[16];
+ int i;
- //render the hinge axis
- if (createConstraint)
+ CylinderShapeX wheelShape(SimdVector3(wheelWidth,wheelRadius,wheelRadius));
+ SimdVector3 wheelColor(1,0,0);
+
+ for (i=0;i<4;i++)
{
- SimdVector3 color(1,0,0);
- SimdVector3 dirLocal(0,1,0);
- SimdVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS);
- SimdVector3 pivotInB(-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS);
- SimdVector3 from = physObjects[1]->GetRigidBody()->getCenterOfMassTransform()(pivotInA);
- SimdVector3 fromB = physObjects[2]->GetRigidBody()->getCenterOfMassTransform()(pivotInB);
- SimdVector3 dirWorldA = physObjects[1]->GetRigidBody()->getCenterOfMassTransform().getBasis() * dirLocal ;
- SimdVector3 dirWorldB = physObjects[2]->GetRigidBody()->getCenterOfMassTransform().getBasis() * dirLocal ;
- debugDrawer.DrawLine(from,from+dirWorldA,color);
- debugDrawer.DrawLine(fromB,fromB+dirWorldB,color);
+ //draw wheels (cylinders)
+ wheelMotionState[i].m_worldTransform.getOpenGLMatrix(m);
+ GL_ShapeDrawer::DrawOpenGL(m,&wheelShape,wheelColor,getDebugMode());
+ // debugDrawer.DrawLine(from,from+dirWorldA,color);
+ // debugDrawer.DrawLine(fromB,fromB+dirWorldB,color);
}
- float m[16];
- int i;
+
if (getDebugMode() & IDebugDraw::DBG_DisableBulletLCP)
@@ -581,13 +669,13 @@ void renderme()
SimdTransform ident;
ident.setIdentity();
ident.getOpenGLMatrix(vec);
- glPushMatrix();
+ //glPushMatrix();
- glLoadMatrixf(vec);
+ //glLoadMatrixf(vec);
GL_ShapeDrawer::DrawOpenGL(m,physObjects[i]->GetRigidBody()->GetCollisionShape(),wireColor,getDebugMode());
- glPopMatrix();
+ //glPopMatrix();
///this block is just experimental code to show some internal issues with replacing shapes on the fly.
if (getDebugMode()!=0 && (i>0))
@@ -725,13 +813,29 @@ void clientMoveAndDisplay()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+{
+ int steerWheelIndex = 2;
+ gVehicleConstraint->ApplyEngineForce(gEngineForce,steerWheelIndex);
+ steerWheelIndex = 3;
+ gVehicleConstraint->ApplyEngineForce(gEngineForce,steerWheelIndex);
+
+ steerWheelIndex = 0;
+ gVehicleConstraint->SetSteeringValue(gVehicleSteering,steerWheelIndex);
+ steerWheelIndex = 1;
+ gVehicleConstraint->SetSteeringValue(gVehicleSteering,steerWheelIndex);
+
+ }
physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
+
+
+
#ifdef USE_QUICKPROF
Profiler::beginBlock("render");
#endif //USE_QUICKPROF
-
+
+
renderme();
#ifdef USE_QUICKPROF
@@ -769,6 +873,9 @@ void clientDisplay(void) {
void clientResetScene()
{
+ gEngineForce = 0.f;
+ gVehicleSteering = 0.f;
+
int i;
for (i=0;i<numObjects;i++)
{
@@ -828,9 +935,51 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false);
}
+void clientSpecialKeyboard(int key, int x, int y)
+{
+ printf("key = %i x=%i y=%i\n",key,x,y);
+
+ switch (key)
+ {
+ case GLUT_KEY_LEFT :
+ {
+ gVehicleSteering += steeringIncrement;
+ if ( gVehicleSteering > steeringClamp)
+ gVehicleSteering = steeringClamp;
+
+ break;
+ }
+ case GLUT_KEY_RIGHT :
+ {
+ gVehicleSteering -= steeringIncrement;
+ if ( gVehicleSteering < -steeringClamp)
+ gVehicleSteering = -steeringClamp;
+
+ break;
+ }
+ case GLUT_KEY_UP :
+ {
+ gEngineForce = -maxEngineForce;
+ break;
+ }
+ case GLUT_KEY_DOWN :
+ {
+ gEngineForce = maxEngineForce;
+ break;
+ }
+ default:
+ defaultSpecialKeyboard(key,x,y);
+ break;
+ }
+
+// glutPostRedisplay();
+
+}
+
void clientKeyboard(unsigned char key, int x, int y)
{
+
if (key == '.')
{
shootBox(SimdVector3(0,0,0));
diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp
index 936259517..ba068ee79 100644
--- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp
+++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp
@@ -278,6 +278,11 @@ public:
}
}
+ virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
+ {
+ m_vehicle->SetCoordinateSystem(rightIndex,upIndex,forwardIndex);
+ }
+
};
diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h
index 053abcbd3..3f03371cc 100644
--- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h
+++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.h
@@ -43,7 +43,7 @@ class OverlappingPairCache;
class IDebugDraw;
class PHY_IVehicle;
-/// CcdPhysicsEnvironment is experimental mainloop for physics simulation using optional continuous collision detection.
+/// CcdPhysicsEnvironment is an experimental mainloop for physics simulation using optional continuous collision detection.
/// Physics Environment takes care of stepping the simulation and is a container for physics entities.
/// It stores rigidbodies,constraints, materials etc.
/// A derived class may be able to 'construct' entities by loading and/or converting
diff --git a/Extras/PhysicsInterface/Common/PHY_IVehicle.h b/Extras/PhysicsInterface/Common/PHY_IVehicle.h
index 6d2cb6684..58694b77b 100644
--- a/Extras/PhysicsInterface/Common/PHY_IVehicle.h
+++ b/Extras/PhysicsInterface/Common/PHY_IVehicle.h
@@ -13,7 +13,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
-
#ifndef PHY_IVEHICLE_H
#define PHY_IVEHICLE_H
@@ -56,6 +55,18 @@ public:
virtual void ApplyBraking(float braking,int wheelIndex) = 0;
+ virtual void SetWheelFriction(float friction,int wheelIndex) = 0;
+
+ virtual void SetSuspensionStiffness(float suspensionStiffness,int wheelIndex) = 0;
+
+ virtual void SetSuspensionDamping(float suspensionStiffness,int wheelIndex) = 0;
+
+ virtual void SetSuspensionCompression(float suspensionStiffness,int wheelIndex) = 0;
+
+ virtual void SetRollInfluence(float rollInfluence,int wheelIndex) = 0;
+
+ virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex) =0;
+
};
#endif //PHY_IVEHICLE_H