Exposed another glut method (the demos really require cleanup soon!)

First steps for a raycast-vehicle demo (far from finished)
This commit is contained in:
ejcoumans
2006-09-05 07:36:55 +00:00
parent e84716482d
commit fa96109cd9
22 changed files with 319 additions and 63 deletions

View File

@@ -71,6 +71,11 @@ public:
return 1; return 1;
} }
virtual float GetRadius() const
{
return GetHalfExtents().getX();
}
//debugging //debugging
virtual char* GetName()const virtual char* GetName()const
{ {
@@ -98,6 +103,11 @@ public:
return "CylinderX"; return "CylinderX";
} }
virtual float GetRadius() const
{
return GetHalfExtents().getY();
}
}; };
class CylinderShapeZ : public CylinderShape class CylinderShapeZ : public CylinderShape
@@ -118,6 +128,11 @@ public:
return "CylinderZ"; return "CylinderZ";
} }
virtual float GetRadius() const
{
return GetHalfExtents().getX();
}
}; };

View File

@@ -76,6 +76,7 @@ WheelInfo& RaycastVehicle::AddWheel( const SimdVector3& connectionPointCS, const
WheelInfo& wheel = m_wheelInfo[GetNumWheels()-1]; WheelInfo& wheel = m_wheelInfo[GetNumWheels()-1];
UpdateWheelTransformsWS( wheel ); UpdateWheelTransformsWS( wheel );
UpdateWheelTransform(GetNumWheels()-1);
return wheel; return wheel;
} }
@@ -344,17 +345,9 @@ SimdScalar RaycastVehicle::GetSteeringValue(int wheel) const
void RaycastVehicle::ApplyEngineForce(SimdScalar force, int wheel) void RaycastVehicle::ApplyEngineForce(SimdScalar force, int wheel)
{ {
for (int i=0;i<GetNumWheels();i++) assert(wheel>=0 && wheel < GetNumWheels());
{ WheelInfo& wheelInfo = GetWheelInfo(wheel);
WheelInfo& wheelInfo = GetWheelInfo(i);
bool applyOnFrontWheel = !wheel;
if (applyOnFrontWheel == wheelInfo.m_bIsFrontWheel)
{
wheelInfo.m_engineForce = force; wheelInfo.m_engineForce = force;
}
}
} }

View File

@@ -143,6 +143,13 @@ public:
return m_indexForwardAxis; return m_indexForwardAxis;
} }
virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
{
m_indexRightAxis = rightIndex;
m_indexUpAxis = upIndex;
m_indexForwardAxis = forwardIndex;
}
virtual void BuildJacobian() virtual void BuildJacobian()
{ {
//not yet //not yet

View File

@@ -668,6 +668,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false); 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) void clientKeyboard(unsigned char key, int x, int y)
{ {

View File

@@ -851,6 +851,13 @@ void clientKeyboard(unsigned char key, int x, int y)
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);
} }
void clientSpecialKeyboard(int key, int x, int y)
{
defaultSpecialKeyboard(key,x,y);
}
int gPickingConstraintId = 0; int gPickingConstraintId = 0;
SimdVector3 gOldPickingPos; SimdVector3 gOldPickingPos;
float gOldPickingDist = 0.f; float gOldPickingDist = 0.f;

View File

@@ -1399,6 +1399,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false); 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) void clientKeyboard(unsigned char key, int x, int y)
{ {

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -193,6 +193,11 @@ void clientResetScene()
objects[1].m_worldTransform.setOrigin(SimdVector3(0.0f,9.f,0.f)); 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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -918,6 +918,11 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false); 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) void clientKeyboard(unsigned char key, int x, int y)
{ {

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -192,21 +192,23 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
int upAxis = cylinder->GetUpAxis(); int upAxis = cylinder->GetUpAxis();
GLUquadricObj *quadObj = gluNewQuadric(); GLUquadricObj *quadObj = gluNewQuadric();
float radius = cylinder->GetRadius();
float halfHeight = cylinder->GetHalfExtents()[upAxis];
glPushMatrix(); glPushMatrix();
switch (upAxis) switch (upAxis)
{ {
case 0: case 0:
glRotatef(-90.0, 0.0, 1.0, 0.0); glRotatef(-90.0, 0.0, 1.0, 0.0);
glTranslatef(0.0, 0.0, -1.0); glTranslatef(0.0, 0.0, -halfHeight);
break; break;
case 1: case 1:
glRotatef(-90.0, 1.0, 0.0, 0.0); glRotatef(-90.0, 1.0, 0.0, 0.0);
glTranslatef(0.0, 0.0, -1.0); glTranslatef(0.0, 0.0, -halfHeight);
break; break;
case 2: case 2:
glTranslatef(0.0, 0.0, -1.0); glTranslatef(0.0, 0.0, -halfHeight);
break; break;
default: default:
{ {
@@ -221,9 +223,9 @@ void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const Sim
gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL); gluQuadricDrawStyle(quadObj, (GLenum)GLU_FILL);
gluQuadricNormals(quadObj, (GLenum)GLU_SMOOTH); 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(); glPopMatrix();
glEndList(); glEndList();

View File

@@ -136,6 +136,10 @@ void setCamera() {
eyePos[gForwardAxis] = -DISTANCE; eyePos[gForwardAxis] = -DISTANCE;
SimdVector3 forward(eyePos[0],eyePos[1],eyePos[2]); 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); SimdVector3 right = gCameraUp.cross(forward);
SimdQuaternion roll(right,-rele); 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) switch (key)
{ {
@@ -372,7 +377,7 @@ int glutmain(int argc, char **argv,int width,int height,const char* title) {
myinit(); myinit();
glutKeyboardFunc(clientKeyboard); glutKeyboardFunc(clientKeyboard);
glutSpecialFunc(mySpecial); glutSpecialFunc(clientSpecialKeyboard);
glutReshapeFunc(myReshape); glutReshapeFunc(myReshape);
//createMenu(); //createMenu();
glutIdleFunc(clientMoveAndDisplay); glutIdleFunc(clientMoveAndDisplay);

View File

@@ -30,6 +30,9 @@ void setDebugMode(int mode);
void defaultKeyboard(unsigned char key, int x, int y); void defaultKeyboard(unsigned char key, int x, int y);
void clientKeyboard(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 clientMouseFunc(int button, int state, int x, int y);
void clientMotionFunc(int x,int y); void clientMotionFunc(int x,int y);
#endif //GLUT_STUFF_H #endif //GLUT_STUFF_H

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -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) void clientKeyboard(unsigned char key, int x, int y)
{ {
defaultKeyboard(key, x, y); defaultKeyboard(key, x, y);

View File

@@ -13,14 +13,19 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 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 //#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 "CcdPhysicsEnvironment.h"
#include "ParallelPhysicsEnvironment.h" #include "ParallelPhysicsEnvironment.h"
#include "CcdPhysicsController.h" #include "CcdPhysicsController.h"
#include "MyMotionState.h"
//#include "GL_LineSegmentShape.h" //#include "GL_LineSegmentShape.h"
#include "CollisionShapes/BoxShape.h" #include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/SphereShape.h" #include "CollisionShapes/SphereShape.h"
@@ -29,12 +34,17 @@ subject to the following restrictions:
#include "CollisionShapes/CompoundShape.h" #include "CollisionShapes/CompoundShape.h"
#include "CollisionShapes/Simplex1to4Shape.h" #include "CollisionShapes/Simplex1to4Shape.h"
#include "CollisionShapes/EmptyShape.h" #include "CollisionShapes/EmptyShape.h"
#include "CollisionShapes/CylinderShape.h"
#include "CollisionShapes/TriangleMeshShape.h" #include "CollisionShapes/TriangleMeshShape.h"
#include "CollisionShapes/TriangleIndexVertexArray.h" #include "CollisionShapes/TriangleIndexVertexArray.h"
#include "CollisionShapes/BvhTriangleMeshShape.h" #include "CollisionShapes/BvhTriangleMeshShape.h"
#include "CollisionShapes/TriangleMesh.h" #include "CollisionShapes/TriangleMesh.h"
#include "Dynamics/RigidBody.h" #include "Dynamics/RigidBody.h"
#include "Vehicle/RaycastVehicle.h"
#include "PHY_IVehicle.h"
#include "CollisionDispatch/CollisionDispatcher.h" #include "CollisionDispatch/CollisionDispatcher.h"
#include "ParallelIslandDispatcher.h" #include "ParallelIslandDispatcher.h"
@@ -94,21 +104,45 @@ const int maxProxies = 32766;
const int maxOverlap = 65535; const int maxOverlap = 65535;
bool createConstraint = true;//false; bool createConstraint = true;//false;
bool useCompound = true;//false; bool useCompound = false;//true;//false;
#ifdef _DEBUG #ifdef _DEBUG
const int numObjects = 50; const int numObjects = 2;
#else #else
const int numObjects = 120; const int numObjects = 2;
#endif #endif
const int maxNumObjects = 32760; const int maxNumObjects = 32760;
DefaultMotionState ms[maxNumObjects];
MyMotionState ms[maxNumObjects];
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0}; CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
int shapeIndex[maxNumObjects]; 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 #ifdef USE_PARALLEL_DISPATCHER
ParallelPhysicsEnvironment* physicsEnvironmentPtr = 0; ParallelPhysicsEnvironment* physicsEnvironmentPtr = 0;
#else #else
@@ -134,7 +168,7 @@ CollisionShape* shapePtr[numShapes] =
new BoxShape (SimdVector3(50,10,50)), new BoxShape (SimdVector3(50,10,50)),
#endif #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 SphereShape (CUBE_HALF_EXTENTS- 0.05f),
//new ConeShape(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS), //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); physicsEnvironmentPtr->setGravity(0,-10,0);//0,0);//-10,0);
int i; int i;
//#define USE_TRIMESH_GROUND 1 #define USE_TRIMESH_GROUND 1
#ifdef USE_TRIMESH_GROUND #ifdef USE_TRIMESH_GROUND
@@ -205,7 +239,7 @@ const float TRIANGLE_SIZE=20.f;
{ {
for (int j=0;j<NUM_VERTS_Y;j++) 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_inertia = 1.f;
shapeProps.m_lin_drag = 0.2f; shapeProps.m_lin_drag = 0.2f;
shapeProps.m_ang_drag = 0.1f; shapeProps.m_ang_drag = 0.1f;
shapeProps.m_mass = 10.0f; shapeProps.m_mass = 800.0f;
PHY_MaterialProps materialProps; PHY_MaterialProps materialProps;
materialProps.m_friction = 10.5f; materialProps.m_friction = 10.5f;
@@ -281,7 +315,7 @@ const float TRIANGLE_SIZE=20.f;
ident.setIdentity(); ident.setIdentity();
ident.setOrigin(SimdVector3(0,0,0)); ident.setOrigin(SimdVector3(0,0,0));
compoundShape->AddChildShape(ident,oldShape);// compoundShape->AddChildShape(ident,oldShape);//
ident.setOrigin(SimdVector3(0,0,2)); ident.setOrigin(SimdVector3(0,1,-1));
compoundShape->AddChildShape(ident,new SphereShape(0.9));// compoundShape->AddChildShape(ident,new SphereShape(0.9));//
} }
@@ -422,15 +456,70 @@ const float TRIANGLE_SIZE=20.f;
constraintId =physicsEnvironmentPtr->createConstraint( constraintId =physicsEnvironmentPtr->createConstraint(
physObjects[1], physObjects[1],0,
//0, PHY_VEHICLE_CONSTRAINT,
physObjects[2], 0,0,0,
////PHY_POINT2POINT_CONSTRAINT, 0,0,0);
PHY_GENERIC_6DOF_CONSTRAINT,//can leave any of the 6 degree of freedom 'free' or 'locked'
//PHY_LINEHINGE_CONSTRAINT, ///never deactivate the vehicle
pivotX,pivotY,pivotZ, physObjects[1]->GetRigidBody()->SetActivationState(DISABLE_DEACTIVATION);
axisX,axisY,axisZ
); 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,29 +529,28 @@ const float TRIANGLE_SIZE=20.f;
return glutmain(argc, argv,640,480,"Bullet Vehicle Demo. http://www.continuousphysics.com/Bullet/phpBB2/"); return glutmain(argc, argv,640,480,"Bullet Vehicle Demo. http://www.continuousphysics.com/Bullet/phpBB2/");
} }
//to be implemented by the demo //to be implemented by the demo
void renderme() void renderme()
{ {
debugDrawer.SetDebugMode(getDebugMode()); debugDrawer.SetDebugMode(getDebugMode());
//render the hinge axis
if (createConstraint)
{
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);
}
float m[16]; float m[16];
int i; int i;
CylinderShapeX wheelShape(SimdVector3(wheelWidth,wheelRadius,wheelRadius));
SimdVector3 wheelColor(1,0,0);
for (i=0;i<4;i++)
{
//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);
}
if (getDebugMode() & IDebugDraw::DBG_DisableBulletLCP) if (getDebugMode() & IDebugDraw::DBG_DisableBulletLCP)
{ {
@@ -581,13 +669,13 @@ void renderme()
SimdTransform ident; SimdTransform ident;
ident.setIdentity(); ident.setIdentity();
ident.getOpenGLMatrix(vec); ident.getOpenGLMatrix(vec);
glPushMatrix(); //glPushMatrix();
glLoadMatrixf(vec); //glLoadMatrixf(vec);
GL_ShapeDrawer::DrawOpenGL(m,physObjects[i]->GetRigidBody()->GetCollisionShape(),wireColor,getDebugMode()); 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. ///this block is just experimental code to show some internal issues with replacing shapes on the fly.
if (getDebugMode()!=0 && (i>0)) if (getDebugMode()!=0 && (i>0))
@@ -725,13 +813,29 @@ void clientMoveAndDisplay()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 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); physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
#ifdef USE_QUICKPROF #ifdef USE_QUICKPROF
Profiler::beginBlock("render"); Profiler::beginBlock("render");
#endif //USE_QUICKPROF #endif //USE_QUICKPROF
renderme(); renderme();
#ifdef USE_QUICKPROF #ifdef USE_QUICKPROF
@@ -769,6 +873,9 @@ void clientDisplay(void) {
void clientResetScene() void clientResetScene()
{ {
gEngineForce = 0.f;
gVehicleSteering = 0.f;
int i; int i;
for (i=0;i<numObjects;i++) for (i=0;i<numObjects;i++)
{ {
@@ -828,9 +935,51 @@ void shootBox(const SimdVector3& destination)
physObjects[i]->SetAngularVelocity(0,0,0,false); 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) void clientKeyboard(unsigned char key, int x, int y)
{ {
if (key == '.') if (key == '.')
{ {
shootBox(SimdVector3(0,0,0)); shootBox(SimdVector3(0,0,0));

View File

@@ -278,6 +278,11 @@ public:
} }
} }
virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
{
m_vehicle->SetCoordinateSystem(rightIndex,upIndex,forwardIndex);
}
}; };

View File

@@ -43,7 +43,7 @@ class OverlappingPairCache;
class IDebugDraw; class IDebugDraw;
class PHY_IVehicle; 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. /// Physics Environment takes care of stepping the simulation and is a container for physics entities.
/// It stores rigidbodies,constraints, materials etc. /// It stores rigidbodies,constraints, materials etc.
/// A derived class may be able to 'construct' entities by loading and/or converting /// A derived class may be able to 'construct' entities by loading and/or converting

View File

@@ -13,7 +13,6 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
#ifndef PHY_IVEHICLE_H #ifndef PHY_IVEHICLE_H
#define PHY_IVEHICLE_H #define PHY_IVEHICLE_H
@@ -56,6 +55,18 @@ public:
virtual void ApplyBraking(float braking,int wheelIndex) = 0; 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 #endif //PHY_IVEHICLE_H