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:
@@ -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();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,29 +529,28 @@ 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());
|
||||
|
||||
//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];
|
||||
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)
|
||||
{
|
||||
@@ -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));
|
||||
|
||||
@@ -278,6 +278,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
|
||||
{
|
||||
m_vehicle->SetCoordinateSystem(rightIndex,upIndex,forwardIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user