moved files around

This commit is contained in:
ejcoumans
2006-05-25 19:18:29 +00:00
commit e061ec1ebf
1024 changed files with 349445 additions and 0 deletions

View File

@@ -0,0 +1,793 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "CcdPhysicsEnvironment.h"
#include "CcdPhysicsController.h"
#include "MyMotionState.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/SphereShape.h"
#include "CollisionShapes/ConeShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "CollisionShapes/EmptyShape.h"
#include "Dynamics/RigidBody.h"
#include "CollisionDispatch/CollisionDispatcher.h"
#include "BroadphaseCollision/SimpleBroadphase.h"
#include "BroadphaseCollision/AxisSweep3.h"
#include "ConstraintSolver/Point2PointConstraint.h"
#include "ConstraintSolver/HingeConstraint.h"
#include "quickprof.h"
#include "PrintfDebugDrawer.h"
#include "PHY_Pro.h"
#include <stdio.h> //printf debugging
int getDebugMode()
{
return IDebugDraw::DBG_ProfileTimings;
}
//make up for lack of glut and camera
float eye[3]={10.f,0.f,0.f};
int glutScreenWidth=640;
int glutScreenHeight=480;
#ifdef _DEBUG
const int numObjects = 22;
#else
const int numObjects = 120;
#endif
const int maxNumObjects = 450;
MyMotionState ms[maxNumObjects];
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
int shapeIndex[maxNumObjects];
CcdPhysicsEnvironment* physicsEnvironmentPtr = 0;
#define CUBE_HALF_EXTENTS 1
#define EXTRA_HEIGHT -20.f
static const int numShapes = 4;
CollisionShape* shapePtr[numShapes] =
{
new BoxShape (SimdVector3(50,10,50)),
new BoxShape (SimdVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
new SphereShape (CUBE_HALF_EXTENTS- 0.05f),
//new ConeShape(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS),
//new BU_Simplex1to4(SimdPoint3(-1,-1,-1),SimdPoint3(1,-1,-1),SimdPoint3(-1,1,-1),SimdPoint3(0,0,1)),
//new EmptyShape(),
new BoxShape (SimdVector3(0.4f,1.f,0.8f))
};
void clientResetScene();
void simulateMe();
void clientDisplay()
{
}
void clientMoveAndDisplay()
{
}
PrintfDebugDrawer debugDrawer;
int main(int argc,char** argv)
{
CollisionDispatcher* dispatcher = new CollisionDispatcher();
SimdVector3 worldAabbMin(-10000,-10000,-10000);
SimdVector3 worldAabbMax(10000,10000,10000);
BroadphaseInterface* broadphase = new AxisSweep3(worldAabbMin,worldAabbMax);
//BroadphaseInterface* broadphase = new SimpleBroadphase();
physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
physicsEnvironmentPtr->setDeactivationTime(2.f);
physicsEnvironmentPtr->setGravity(0,-10,0);
PHY_ShapeProps shapeProps;
shapeProps.m_do_anisotropic = false;
shapeProps.m_do_fh = false;
shapeProps.m_do_rot_fh = false;
shapeProps.m_friction_scaling[0] = 1.;
shapeProps.m_friction_scaling[1] = 1.;
shapeProps.m_friction_scaling[2] = 1.;
shapeProps.m_inertia = 1.f;
shapeProps.m_lin_drag = 0.2f;
shapeProps.m_ang_drag = 0.1f;
shapeProps.m_mass = 10.0f;
PHY_MaterialProps materialProps;
materialProps.m_friction = 10.5f;
materialProps.m_restitution = 0.0f;
CcdConstructionInfo ccdObjectCi;
ccdObjectCi.m_friction = 0.5f;
ccdObjectCi.m_linearDamping = shapeProps.m_lin_drag;
ccdObjectCi.m_angularDamping = shapeProps.m_ang_drag;
SimdTransform tr;
tr.setIdentity();
int i;
for (i=0;i<numObjects;i++)
{
if (i>0)
{
shapeIndex[i] = 1;//sphere
}
else
shapeIndex[i] = 0;
}
for (i=0;i<numObjects;i++)
{
shapeProps.m_shape = shapePtr[shapeIndex[i]];
shapeProps.m_shape->SetMargin(0.05f);
bool isDyna = i>0;
//if (i==1)
// isDyna=false;
if (0)//i==1)
{
SimdQuaternion orn(0,0,0.1*SIMD_HALF_PI);
ms[i].setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
}
if (i>0)
{
switch (i)
{
case 1:
{
ms[i].setWorldPosition(0,10,0);
//for testing, rotate the ground cube so the stack has to recover a bit
break;
}
case 2:
{
ms[i].setWorldPosition(0,8,2);
break;
}
default:
ms[i].setWorldPosition(0,i*CUBE_HALF_EXTENTS*2 - CUBE_HALF_EXTENTS,0);
}
SimdQuaternion quat;
SimdVector3 axis(0.f,0.f,1.f);
SimdScalar angle=0.5f;
quat.setRotation(axis,angle);
ms[i].setWorldOrientation(quat.getX(),quat.getY(),quat.getZ(),quat[3]);
} else
{
ms[i].setWorldPosition(0,-100+EXTRA_HEIGHT,0);
}
ccdObjectCi.m_MotionState = &ms[i];
ccdObjectCi.m_gravity = SimdVector3(0,0,0);
ccdObjectCi.m_localInertiaTensor =SimdVector3(0,0,0);
if (!isDyna)
{
shapeProps.m_mass = 0.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
else
{
shapeProps.m_mass = 1.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
SimdVector3 localInertia;
if (shapePtr[shapeIndex[i]]->GetShapeType() == EMPTY_SHAPE_PROXYTYPE)
{
//take inertia from first shape
shapePtr[1]->CalculateLocalInertia(shapeProps.m_mass,localInertia);
} else
{
shapePtr[shapeIndex[i]]->CalculateLocalInertia(shapeProps.m_mass,localInertia);
}
ccdObjectCi.m_localInertiaTensor = localInertia;
ccdObjectCi.m_collisionShape = shapePtr[shapeIndex[i]];
physObjects[i]= new CcdPhysicsController( ccdObjectCi);
physicsEnvironmentPtr->addCcdPhysicsController( physObjects[i]);
if (i==1)
{
//physObjects[i]->SetAngularVelocity(0,0,-2,true);
}
physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
}
//create a constraint
{
//physObjects[i]->SetAngularVelocity(0,0,-2,true);
int constraintId;
//0.0f, -1.0f, 1.0f
float pivotX=CUBE_HALF_EXTENTS,
pivotY=-CUBE_HALF_EXTENTS,
pivotZ=CUBE_HALF_EXTENTS;
float axisX=1,axisY=0,axisZ=0;
/*constraintId =physicsEnvironmentPtr->createConstraint(
physObjects[1],
//0,
physObjects[2],
//PHY_POINT2POINT_CONSTRAINT,
PHY_LINEHINGE_CONSTRAINT,
pivotX,pivotY,pivotZ,
axisX,axisY,axisZ
);
*/
HingeConstraint* hinge = 0;
SimdVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS);
SimdVector3 pivotInB(-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS);
SimdVector3 axisInA(0,1,0);
SimdVector3 axisInB(0,-1,0);
RigidBody* rb0 = physObjects[1]->GetRigidBody();
RigidBody* rb1 = physObjects[2]->GetRigidBody();
hinge = new HingeConstraint(
*rb0,
*rb1,pivotInA,pivotInB,axisInA,axisInB);
physicsEnvironmentPtr->m_constraints.push_back(hinge);
hinge->SetUserConstraintId(100);
hinge->SetUserConstraintType(PHY_LINEHINGE_CONSTRAINT);
}
clientResetScene();
while (1)
{
simulateMe();
}
}
//to be implemented by the demo
void simulateMe()
{
float deltaTime = 1.f/60.f;
physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
debugDrawer.SetDebugMode(getDebugMode());
//render the hinge axis
{
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;
if (getDebugMode() & IDebugDraw::DBG_DisableBulletLCP)
{
//don't use Bullet, use quickstep
physicsEnvironmentPtr->setSolverType(0);
} else
{
//Bullet LCP solver
physicsEnvironmentPtr->setSolverType(1);
}
bool isSatEnabled = (getDebugMode() & IDebugDraw::DBG_EnableSatComparison);
physicsEnvironmentPtr->EnableSatCollisionDetection(isSatEnabled);
for (i=0;i<numObjects;i++)
{
SimdTransform transA;
transA.setIdentity();
float pos[3];
float rot[4];
ms[i].getWorldPosition(pos[0],pos[1],pos[2]);
ms[i].getWorldOrientation(rot[0],rot[1],rot[2],rot[3]);
SimdQuaternion q(rot[0],rot[1],rot[2],rot[3]);
transA.setRotation(q);
SimdPoint3 dpos;
dpos.setValue(pos[0],pos[1],pos[2]);
transA.setOrigin( dpos );
transA.getOpenGLMatrix( m );
SimdVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
if (i & 1)
{
wireColor = SimdVector3(0.f,0.0f,1.f);
}
///color differently for active, sleeping, wantsdeactivation states
if (physObjects[i]->GetRigidBody()->GetActivationState() == 1) //active
{
if (i & 1)
{
wireColor += SimdVector3 (1.f,0.f,0.f);
} else
{
wireColor += SimdVector3 (.5f,0.f,0.f);
}
}
if (physObjects[i]->GetRigidBody()->GetActivationState() == 2) //ISLAND_SLEEPING
{
if (i & 1)
{
wireColor += SimdVector3 (0.f,1.f, 0.f);
} else
{
wireColor += SimdVector3 (0.f,0.5f,0.f);
}
}
char extraDebug[125];
sprintf(extraDebug,"islId, Body=%i , %i",physObjects[i]->GetRigidBody()->m_islandTag1,physObjects[i]->GetRigidBody()->m_debugBodyId);
physObjects[i]->GetRigidBody()->GetCollisionShape()->SetExtraDebugInfo(extraDebug);
//GL_ShapeDrawer::DrawOpenGL(m,physObjects[i]->GetRigidBody()->GetCollisionShape(),wireColor,getDebugMode());
}
if (!(getDebugMode() & IDebugDraw::DBG_NoHelpText))
{
float xOffset = 10.f;
float yStart = 20.f;
float yIncr = -2.f;
char buf[124];
//glColor3f(0, 0, 0);
#ifdef USE_QUICKPROF
if ( getDebugMode() & IDebugDraw::DBG_ProfileTimings)
{
static int counter = 0;
counter++;
std::map<std::string, hidden::ProfileBlock*>::iterator iter;
for (iter = Profiler::mProfileBlocks.begin(); iter != Profiler::mProfileBlocks.end(); ++iter)
{
char blockTime[128];
sprintf(blockTime, "%s: %lf",&((*iter).first[0]),Profiler::getBlockTime((*iter).first, Profiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT));
printf(blockTime);
}
}
#endif //USE_QUICKPROF
/*
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"mouse to interact");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"space to reset");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"c to show contact points");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"cursor keys and z,x to navigate");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"i to toggle simulation, s single step");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"q to quit");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"d to toggle deactivation");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,". to shoot primitive");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"h to toggle help text");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
bool useBulletLCP = !(getDebugMode() & IDebugDraw::DBG_DisableBulletLCP);
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"m Bullet GJK = %i",!isSatEnabled);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"n Bullet LCP = %i",useBulletLCP);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
*/
}
}
///make this positive to show stack falling from a distance
///this shows the penalty tresholds in action, springy/spungy look
void clientResetScene()
{
int i;
for (i=0;i<numObjects;i++)
{
if (i>0)
{
if ((getDebugMode() & IDebugDraw::DBG_NoHelpText))
{
if (physObjects[i]->GetRigidBody()->GetCollisionShape()->GetShapeType() == BOX_SHAPE_PROXYTYPE)
{
physObjects[i]->GetRigidBody()->SetCollisionShape(shapePtr[2]);
} else
{
physObjects[i]->GetRigidBody()->SetCollisionShape(shapePtr[1]);
}
BroadphaseProxy* bpproxy = physObjects[i]->GetRigidBody()->m_broadphaseHandle;
physicsEnvironmentPtr->GetBroadphase()->CleanProxyFromPairs(bpproxy);
}
//stack them
int colsize = 10;
int row = (i*CUBE_HALF_EXTENTS*2)/(colsize*2*CUBE_HALF_EXTENTS);
int row2 = row;
int col = (i)%(colsize)-colsize/2;
if (col>3)
{
col=11;
row2 |=1;
}
physObjects[i]->setPosition(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,0);
physObjects[i]->setOrientation(0,0,0,1);
physObjects[i]->SetLinearVelocity(0,0,0,false);
physObjects[i]->SetAngularVelocity(0,0,0,false);
} else
{
ms[i].setWorldPosition(0,-10-EXTRA_HEIGHT,0);
}
}
}
void shootBox(const SimdVector3& destination)
{
int i = numObjects-1;
float speed = 40.f;
SimdVector3 linVel(destination[0]-eye[0],destination[1]-eye[1],destination[2]-eye[2]);
linVel.normalize();
linVel*=speed;
physObjects[i]->setPosition(eye[0],eye[1],eye[2]);
physObjects[i]->setOrientation(0,0,0,1);
physObjects[i]->SetLinearVelocity(linVel[0],linVel[1],linVel[2],false);
physObjects[i]->SetAngularVelocity(0,0,0,false);
}
void clientKeyboard(unsigned char key, int x, int y)
{
if (key == '.')
{
shootBox(SimdVector3(0,0,0));
}
//defaultKeyboard(key, x, y);
}
int gPickingConstraintId = 0;
SimdVector3 gOldPickingPos;
float gOldPickingDist = 0.f;
RigidBody* pickedBody = 0;//for deactivation state
SimdVector3 GetRayTo(int x,int y)
{
float top = 1.f;
float bottom = -1.f;
float nearPlane = 1.f;
float tanFov = (top-bottom)*0.5f / nearPlane;
float fov = 2.0 * atanf (tanFov);
SimdVector3 rayFrom(eye[0],eye[1],eye[2]);
SimdVector3 rayForward = -rayFrom;
rayForward.normalize();
float farPlane = 600.f;
rayForward*= farPlane;
SimdVector3 rightOffset;
SimdVector3 vertical(0.f,1.f,0.f);
SimdVector3 hor;
hor = rayForward.cross(vertical);
hor.normalize();
vertical = hor.cross(rayForward);
vertical.normalize();
float tanfov = tanf(0.5f*fov);
hor *= 2.f * farPlane * tanfov;
vertical *= 2.f * farPlane * tanfov;
SimdVector3 rayToCenter = rayFrom + rayForward;
SimdVector3 dHor = hor * 1.f/float(glutScreenWidth);
SimdVector3 dVert = vertical * 1.f/float(glutScreenHeight);
SimdVector3 rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
rayTo += x * dHor;
rayTo -= y * dVert;
return rayTo;
}
void clientMouseFunc(int button, int state, int x, int y)
{
//printf("button %i, state %i, x=%i,y=%i\n",button,state,x,y);
//button 0, state 0 means left mouse down
SimdVector3 rayTo = GetRayTo(x,y);
switch (button)
{
case 2:
{
if (state==0)
{
shootBox(rayTo);
}
break;
};
case 1:
{
if (state==0)
{
//apply an impulse
if (physicsEnvironmentPtr)
{
float hit[3];
float normal[3];
PHY_IPhysicsController* hitObj = physicsEnvironmentPtr->rayTest(0,eye[0],eye[1],eye[2],rayTo.getX(),rayTo.getY(),rayTo.getZ(),hit[0],hit[1],hit[2],normal[0],normal[1],normal[2]);
if (hitObj)
{
CcdPhysicsController* physCtrl = static_cast<CcdPhysicsController*>(hitObj);
RigidBody* body = physCtrl->GetRigidBody();
if (body)
{
body->SetActivationState(ACTIVE_TAG);
SimdVector3 impulse = rayTo;
impulse.normalize();
float impulseStrength = 10.f;
impulse *= impulseStrength;
SimdVector3 relPos(
hit[0] - body->getCenterOfMassPosition().getX(),
hit[1] - body->getCenterOfMassPosition().getY(),
hit[2] - body->getCenterOfMassPosition().getZ());
body->applyImpulse(impulse,relPos);
}
}
}
} else
{
}
break;
}
case 0:
{
if (state==0)
{
//add a point to point constraint for picking
if (physicsEnvironmentPtr)
{
float hit[3];
float normal[3];
PHY_IPhysicsController* hitObj = physicsEnvironmentPtr->rayTest(0,eye[0],eye[1],eye[2],rayTo.getX(),rayTo.getY(),rayTo.getZ(),hit[0],hit[1],hit[2],normal[0],normal[1],normal[2]);
if (hitObj)
{
CcdPhysicsController* physCtrl = static_cast<CcdPhysicsController*>(hitObj);
RigidBody* body = physCtrl->GetRigidBody();
if (body)
{
pickedBody = body;
pickedBody->SetActivationState(DISABLE_DEACTIVATION);
SimdVector3 pickPos(hit[0],hit[1],hit[2]);
SimdVector3 localPivot = body->getCenterOfMassTransform().inverse() * pickPos;
gPickingConstraintId = physicsEnvironmentPtr->createConstraint(physCtrl,0,PHY_POINT2POINT_CONSTRAINT,
localPivot.getX(),
localPivot.getY(),
localPivot.getZ(),
0,0,0);
//printf("created constraint %i",gPickingConstraintId);
//save mouse position for dragging
gOldPickingPos = rayTo;
SimdVector3 eyePos(eye[0],eye[1],eye[2]);
gOldPickingDist = (pickPos-eyePos).length();
Point2PointConstraint* p2p = static_cast<Point2PointConstraint*>(physicsEnvironmentPtr->getConstraintById(gPickingConstraintId));
if (p2p)
{
//very weak constraint for picking
p2p->m_setting.m_tau = 0.1f;
}
}
}
}
} else
{
if (gPickingConstraintId && physicsEnvironmentPtr)
{
physicsEnvironmentPtr->removeConstraint(gPickingConstraintId);
//printf("removed constraint %i",gPickingConstraintId);
gPickingConstraintId = 0;
pickedBody->ForceActivationState(ACTIVE_TAG);
pickedBody->m_deactivationTime = 0.f;
pickedBody = 0;
}
}
break;
}
default:
{
}
}
}
void clientMotionFunc(int x,int y)
{
if (gPickingConstraintId && physicsEnvironmentPtr)
{
//move the constraint pivot
Point2PointConstraint* p2p = static_cast<Point2PointConstraint*>(physicsEnvironmentPtr->getConstraintById(gPickingConstraintId));
if (p2p)
{
//keep it at the same picking distance
SimdVector3 newRayTo = GetRayTo(x,y);
SimdVector3 eyePos(eye[0],eye[1],eye[2]);
SimdVector3 dir = newRayTo-eyePos;
dir.normalize();
dir *= gOldPickingDist;
SimdVector3 newPos = eyePos + dir;
p2p->SetPivotB(newPos);
}
}
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos BasicSample ;
BulletBasicDemo BasicSample : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,67 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "MyMotionState.h"
#include "SimdPoint3.h"
MyMotionState::MyMotionState()
{
m_worldTransform.setIdentity();
}
MyMotionState::~MyMotionState()
{
}
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
{
posX = m_worldTransform.getOrigin().x();
posY = m_worldTransform.getOrigin().y();
posZ = m_worldTransform.getOrigin().z();
}
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
{
scaleX = 1.;
scaleY = 1.;
scaleZ = 1.;
}
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{
quatIma0 = m_worldTransform.getRotation().x();
quatIma1 = m_worldTransform.getRotation().y();
quatIma2 = m_worldTransform.getRotation().z();
quatReal = m_worldTransform.getRotation()[3];
}
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
{
SimdPoint3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
{
SimdQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
m_worldTransform.setRotation( orn );
}
void MyMotionState::calculateWorldTransformations()
{
}

View File

@@ -0,0 +1,44 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MY_MOTIONSTATE_H
#define MY_MOTIONSTATE_H
#include "PHY_IMotionState.h"
#include <SimdTransform.h>
class MyMotionState : public PHY_IMotionState
{
public:
MyMotionState();
virtual ~MyMotionState();
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void calculateWorldTransformations();
SimdTransform m_worldTransform;
};
#endif //MY_MOTIONSTATE_H

View File

@@ -0,0 +1,31 @@
#include "PrintfDebugDrawer.h"
#include <stdio.h> //printf debugging
PrintfDebugDrawer::PrintfDebugDrawer()
{
}
void PrintfDebugDrawer::DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)
{
if (m_debugMode > 0)
{
printf("DrawLine: from(%f , %f . %f) , to(%f , %f . %f)\n",from.getX(),from.getY(),from.getZ(),to.getX(),to.getY(),to.getZ());
}
}
void PrintfDebugDrawer::DrawContactPoint(const SimdVector3& pointOnB,const SimdVector3& normalOnB,float distance,int lifeTime,const SimdVector3& color)
{
if (m_debugMode & IDebugDraw::DBG_DrawContactPoints)
{
SimdVector3 to=pointOnB+normalOnB*distance;
const SimdVector3&from = pointOnB;
printf("DrawContactPoint (%d) from(%f , %f . %f) , to(%f , %f . %f)\n",lifeTime, from.getX(),from.getY(),from.getZ(),to.getX(),to.getY(),to.getZ());
}
}
void PrintfDebugDrawer::SetDebugMode(int debugMode)
{
m_debugMode = debugMode;
}

View File

@@ -0,0 +1,27 @@
#ifndef PRINTF_DEBUG_DRAWER_H
#define PRINTF_DEBUG_DRAWER_H
#include "IDebugDraw.h"
class PrintfDebugDrawer : public IDebugDraw
{
int m_debugMode;
public:
PrintfDebugDrawer();
virtual void DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color);
virtual void DrawContactPoint(const SimdVector3& PointOnB,const SimdVector3& normalOnB,float distance,int lifeTime,const SimdVector3& color);
virtual void SetDebugMode(int debugMode);
virtual int GetDebugMode() const { return m_debugMode;}
};
#endif//PRINTF_DEBUG_DRAWER_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos CcdPhysicsDemo ;
BulletDemo CcdPhysicsDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,67 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "MyMotionState.h"
#include "SimdPoint3.h"
MyMotionState::MyMotionState()
{
m_worldTransform.setIdentity();
}
MyMotionState::~MyMotionState()
{
}
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
{
posX = m_worldTransform.getOrigin().x();
posY = m_worldTransform.getOrigin().y();
posZ = m_worldTransform.getOrigin().z();
}
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
{
scaleX = 1.;
scaleY = 1.;
scaleZ = 1.;
}
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{
quatIma0 = m_worldTransform.getRotation().x();
quatIma1 = m_worldTransform.getRotation().y();
quatIma2 = m_worldTransform.getRotation().z();
quatReal = m_worldTransform.getRotation()[3];
}
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
{
SimdPoint3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
{
SimdQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
m_worldTransform.setRotation( orn );
}
void MyMotionState::calculateWorldTransformations()
{
}

View File

@@ -0,0 +1,44 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MY_MOTIONSTATE_H
#define MY_MOTIONSTATE_H
#include "PHY_IMotionState.h"
#include <SimdTransform.h>
class MyMotionState : public PHY_IMotionState
{
public:
MyMotionState();
virtual ~MyMotionState();
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void calculateWorldTransformations();
SimdTransform m_worldTransform;
};
#endif //MY_MOTIONSTATE_H

View File

@@ -0,0 +1,205 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
///
/// Collision Demo shows a degenerate case, where the Simplex solver has to deal with near-affine dependent cases
/// See the define CATCH_DEGENERATE_TETRAHEDRON in Bullet's VoronoiSimplexSolver.cpp
///
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "CollisionShapes/BoxShape.h"
#include "NarrowPhaseCollision/GjkPairDetector.h"
#include "NarrowPhaseCollision/PointCollector.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 2;
GL_Simplex1to4 simplex;
PolyhedralConvexShape* shapePtr[maxNumObjects];
SimdTransform tr[numObjects];
int screenWidth = 640.f;
int screenHeight = 480.f;
void DrawRasterizerLine(float const* , float const*, int)
{
}
int main(int argc,char** argv)
{
setCameraDistance(20.f);
tr[0].setOrigin(SimdVector3(0.0013328250f,8.1363249f,7.0390840f));
tr[1].setOrigin(SimdVector3(0.00000000f,9.1262732f,2.0343180f));
//tr[0].setOrigin(SimdVector3(0,0,0));
//tr[1].setOrigin(SimdVector3(0,10,0));
SimdMatrix3x3 basisA;
basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
-0.00029313788f,0.99753088f,0.070228584f,
-0.00089153741f,-0.070228823f,0.99753052f);
SimdMatrix3x3 basisB;
basisB.setValue(1.0000000f,4.4865553e-018f,-4.4410586e-017f,
4.4865495e-018f,0.97979438f,0.20000751f,
4.4410586e-017f,-0.20000751f,0.97979438f);
tr[0].setBasis(basisA);
tr[1].setBasis(basisB);
SimdVector3 boxHalfExtentsA(1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
SimdVector3 boxHalfExtentsB(3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
BoxShape boxA(boxHalfExtentsA);
BoxShape boxB(boxHalfExtentsB);
shapePtr[0] = &boxA;
shapePtr[1] = &boxB;
SimdTransform tr;
tr.setIdentity();
return glutmain(argc, argv,screenWidth,screenHeight,"Collision Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
static VoronoiSimplexSolver sGjkSimplexSolver;
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
//GL_ShapeDrawer::DrawCoordSystem();
float m[16];
int i;
GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
convexConvex.SetCachedSeperatingAxis(seperatingAxis);
PointCollector gjkOutput;
GjkPairDetector::ClosestPointInput input;
input.m_transformA = tr[0];
input.m_transformB = tr[1];
convexConvex.GetClosestPoints(input ,gjkOutput,0);
if (gjkOutput.m_hasResult)
{
SimdVector3 endPt = gjkOutput.m_pointInWorld +
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
glVertex3d(endPt.x(),endPt.y(),endPt.z());
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
glEnd();
}
for (i=0;i<numObjects;i++)
{
tr[i].getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
}
simplex.SetSimplexSolver(&sGjkSimplexSolver);
SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
simplex.Reset();
for (i=0;i<numpoints;i++)
simplex.AddVertex(ybuf[i]);
SimdTransform ident;
ident.setIdentity();
ident.getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
SimdQuaternion orn;
orn.setEuler(yaw,pitch,roll);
tr[0].setRotation(orn);
// pitch += 0.005f;
// yaw += 0.01f;
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos CollisionDemo ;
BulletDemo CollisionDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,199 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
///
/// CollisionInterfaceDemo shows high level usage of the Collision Detection.
///
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "CollisionShapes/ConvexHullShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionDispatch/CollisionWorld.h"
#include "CollisionDispatch/CollisionObject.h"
#include "CollisionDispatch/CollisionDispatcher.h"
#include "BroadphaseCollision/SimpleBroadphase.h"
#include "BroadphaseCollision/AxisSweep3.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 2;
GL_Simplex1to4 simplex;
CollisionObject objects[maxNumObjects];
CollisionWorld* collisionWorld = 0;
int screenWidth = 640.f;
int screenHeight = 480.f;
int main(int argc,char** argv)
{
clientResetScene();
SimdMatrix3x3 basisA;
basisA.setIdentity();
SimdMatrix3x3 basisB;
basisB.setIdentity();
objects[0].m_worldTransform.setBasis(basisA);
objects[1].m_worldTransform.setBasis(basisB);
SimdPoint3 points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)};
SimdPoint3 points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)};
BoxShape boxA(SimdVector3(1,1,1));
BoxShape boxB(SimdVector3(0.5,0.5,0.5));
//ConvexHullShape hullA(points0,3);
//hullA.setLocalScaling(SimdVector3(3,3,3));
//ConvexHullShape hullB(points1,4);
//hullB.setLocalScaling(SimdVector3(4,4,4));
objects[0].m_collisionShape = &boxA;//&hullA;
objects[1].m_collisionShape = &boxB;//&hullB;
CollisionDispatcher dispatcher;
//SimpleBroadphase broadphase;
SimdVector3 worldAabbMin(-1000,-1000,-1000);
SimdVector3 worldAabbMax(1000,1000,1000);
AxisSweep3 broadphase(worldAabbMin,worldAabbMax);
collisionWorld = new CollisionWorld(&dispatcher,&broadphase);
collisionWorld->AddCollisionObject(&objects[0]);
collisionWorld->AddCollisionObject(&objects[1]);
return glutmain(argc, argv,screenWidth,screenHeight,"Collision Interface Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
static VoronoiSimplexSolver sGjkSimplexSolver;
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
if (collisionWorld)
collisionWorld->PerformDiscreteCollisionDetection();
///one way to draw all the contact points is iterating over contact manifolds / points:
int i;
int numManifolds = collisionWorld->GetDispatcher()->GetNumManifolds();
for (i=0;i<numManifolds;i++)
{
PersistentManifold* contactManifold = collisionWorld->GetDispatcher()->GetManifoldByIndexInternal(i);
CollisionObject* obA = static_cast<CollisionObject*>(contactManifold->GetBody0());
CollisionObject* obB = static_cast<CollisionObject*>(contactManifold->GetBody1());
contactManifold->RefreshContactPoints(obA->m_worldTransform,obB->m_worldTransform);
int numContacts = contactManifold->GetNumContacts();
for (int j=0;j<numContacts;j++)
{
ManifoldPoint& pt = contactManifold->GetContactPoint(j);
glBegin(GL_LINES);
glColor3f(1, 0, 1);
SimdVector3 ptA = pt.GetPositionWorldOnA();
SimdVector3 ptB = pt.GetPositionWorldOnB();
glVertex3d(ptA.x(),ptA.y(),ptA.z());
glVertex3d(ptB.x(),ptB.y(),ptB.z());
glEnd();
}
}
//GL_ShapeDrawer::DrawCoordSystem();
float m[16];
for (i=0;i<numObjects;i++)
{
objects[i].m_worldTransform.getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,objects[i].m_collisionShape,SimdVector3(1,1,1),getDebugMode());
}
SimdQuaternion orn;
orn.setEuler(yaw,pitch,roll);
objects[1].m_worldTransform.setOrigin(objects[1].m_worldTransform.getOrigin()+SimdVector3(0,-0.01,0));
//objects[0].m_worldTransform.setRotation(orn);
pitch += 0.005f;
yaw += 0.01f;
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
objects[0].m_worldTransform.setOrigin(SimdVector3(0.0f,3.f,0.f));
objects[1].m_worldTransform.setOrigin(SimdVector3(0.0f,9.f,0.f));
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos CollisionInterfaceDemo ;
BulletDemo CollisionInterfaceDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,408 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "CcdPhysicsEnvironment.h"
#include "CcdPhysicsController.h"
#include "MyMotionState.h"
//#include "GL_LineSegmentShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "Dynamics/RigidBody.h"
#include "ConstraintSolver/SimpleConstraintSolver.h"
#include "ConstraintSolver/OdeConstraintSolver.h"
#include "CollisionDispatch/CollisionDispatcher.h"
#include "BroadphaseCollision/SimpleBroadphase.h"
#include "CollisionShapes/TriangleMeshShape.h"
#include "CollisionShapes/TriangleIndexVertexArray.h"
#include "CollisionShapes/BvhTriangleMeshShape.h"
#include "CollisionShapes/TriangleMesh.h"
#include "IDebugDraw.h"
//#include "GLDebugDrawer.h"
#include "PHY_Pro.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GL_ShapeDrawer.h"
#include "GlutStuff.h"
const int numObjects = 80;
const int maxNumObjects = 100;
MyMotionState ms[maxNumObjects];
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
int shapeIndex[maxNumObjects];
CcdPhysicsEnvironment* physicsEnvironmentPtr = 0;
TriangleMesh meshData;
StridingMeshInterface* ptr;
//GL_LineSegmentShape shapeE(SimdPoint3(-50,0,0),
// SimdPoint3(50,0,0));
CollisionShape* shapePtr[5] =
{
new BoxShape (SimdVector3(100,10,100)),
new BoxShape (SimdVector3(2,2,2)),
new BU_Simplex1to4(SimdPoint3(-2,-2,-2),SimdPoint3(2,-2,-2),SimdPoint3(-2,2,-2),SimdPoint3(0,0,2)),
new BoxShape (SimdVector3(1,3,1)),
#ifdef DEBUG_MESH
new TriangleMeshShape(&meshData),
#else
NULL,
#endif
//(&meshData)
};
static const int NUM_VERTICES = 5;
static const int NUM_TRIANGLES=4;
SimdVector3 gVertices[NUM_VERTICES];
int gIndices[NUM_TRIANGLES*3];
int main(int argc,char** argv)
{
setCameraDistance(30.f);
#define TRISIZE 10.f
#ifdef DEBUG_MESH
SimdVector3 vert0(-TRISIZE ,0,TRISIZE );
SimdVector3 vert1(TRISIZE ,10,TRISIZE );
SimdVector3 vert2(TRISIZE ,0,-TRISIZE );
meshData.AddTriangle(vert0,vert1,vert2);
SimdVector3 vert3(-TRISIZE ,0,TRISIZE );
SimdVector3 vert4(TRISIZE ,0,-TRISIZE );
SimdVector3 vert5(-TRISIZE ,0,-TRISIZE );
meshData.AddTriangle(vert3,vert4,vert5);
#else
#ifdef ODE_MESH
SimdVector3 Size = SimdVector3(15.f,15.f,12.5f);
gVertices[0][0] = -Size[0];
gVertices[0][1] = Size[2];
gVertices[0][2] = -Size[1];
gVertices[1][0] = Size[0];
gVertices[1][1] = Size[2];
gVertices[1][2] = -Size[1];
gVertices[2][0] = Size[0];
gVertices[2][1] = Size[2];
gVertices[2][2] = Size[1];
gVertices[3][0] = -Size[0];
gVertices[3][1] = Size[2];
gVertices[3][2] = Size[1];
gVertices[4][0] = 0;
gVertices[4][1] = 0;
gVertices[4][2] = 0;
gIndices[0] = 0;
gIndices[1] = 1;
gIndices[2] = 4;
gIndices[3] = 1;
gIndices[4] = 2;
gIndices[5] = 4;
gIndices[6] = 2;
gIndices[7] = 3;
gIndices[8] = 4;
gIndices[9] = 3;
gIndices[10] = 0;
gIndices[11] = 4;
int vertStride = sizeof(SimdVector3);
int indexStride = 3*sizeof(int);
TriangleIndexVertexArray* indexVertexArrays = new TriangleIndexVertexArray(NUM_TRIANGLES,
gIndices,
indexStride,
NUM_VERTICES,(float*) &gVertices[0].x(),vertStride);
//shapePtr[4] = new TriangleMeshShape(indexVertexArrays);
shapePtr[4] = new BvhTriangleMeshShape(indexVertexArrays);
#else
int vertStride = sizeof(SimdVector3);
int indexStride = 3*sizeof(int);
const int NUM_VERTS_X = 50;
const int NUM_VERTS_Y = 50;
const int totalVerts = NUM_VERTS_X*NUM_VERTS_Y;
const int totalTriangles = 2*(NUM_VERTS_X-1)*(NUM_VERTS_Y-1);
SimdVector3* gVertices = new SimdVector3[totalVerts];
int* gIndices = new int[totalTriangles*3];
int i;
for ( i=0;i<NUM_VERTS_X;i++)
{
for (int j=0;j<NUM_VERTS_Y;j++)
{
gVertices[i+j*NUM_VERTS_X].setValue((i-NUM_VERTS_X*0.5f)*10.f,2.f*sinf((float)i)*cosf((float)j),(j-NUM_VERTS_Y*0.5f)*10.f);
}
}
int index=0;
for ( i=0;i<NUM_VERTS_X-1;i++)
{
for (int j=0;j<NUM_VERTS_Y-1;j++)
{
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = j*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = j*NUM_VERTS_X+i;
gIndices[index++] = (j+1)*NUM_VERTS_X+i+1;
gIndices[index++] = (j+1)*NUM_VERTS_X+i;
}
}
TriangleIndexVertexArray* indexVertexArrays = new TriangleIndexVertexArray(totalTriangles,
gIndices,
indexStride,
totalVerts,(float*) &gVertices[0].x(),vertStride);
//shapePtr[4] = new TriangleMeshShape(indexVertexArrays);
shapePtr[4] = new BvhTriangleMeshShape(indexVertexArrays);
#endif
#endif//DEBUG_MESH
// GLDebugDrawer debugDrawer;
//ConstraintSolver* solver = new SimpleConstraintSolver;
ConstraintSolver* solver = new OdeConstraintSolver;
CollisionDispatcher* dispatcher = new CollisionDispatcher();
BroadphaseInterface* broadphase = new SimpleBroadphase();
physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
physicsEnvironmentPtr->setGravity(-1,-10,1);
PHY_ShapeProps shapeProps;
shapeProps.m_do_anisotropic = false;
shapeProps.m_do_fh = false;
shapeProps.m_do_rot_fh = false;
shapeProps.m_friction_scaling[0] = 1.;
shapeProps.m_friction_scaling[1] = 1.;
shapeProps.m_friction_scaling[2] = 1.;
shapeProps.m_inertia = 1.f;
shapeProps.m_lin_drag = 0.95999998f;
shapeProps.m_ang_drag = 0.89999998f;
shapeProps.m_mass = 1.0f;
PHY_MaterialProps materialProps;
materialProps.m_friction = 0.f;// 50.5f;
materialProps.m_restitution = 0.1f;
CcdConstructionInfo ccdObjectCi;
ccdObjectCi.m_friction = 0.f;//50.5f;
ccdObjectCi.m_linearDamping = shapeProps.m_lin_drag;
ccdObjectCi.m_angularDamping = shapeProps.m_ang_drag;
SimdTransform tr;
tr.setIdentity();
for (i=0;i<numObjects;i++)
{
if (i>0)
shapeIndex[i] = 1;//2 = tetrahedron
else
shapeIndex[i] = 4;
}
for (i=0;i<numObjects;i++)
{
shapeProps.m_shape = shapePtr[shapeIndex[i]];
bool isDyna = i>0;
if (!i)
{
//SimdQuaternion orn(0,0,0.1*SIMD_HALF_PI);
//ms[i].setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
//ms[i].setWorldPosition(0,-10,0);
} else
{
ms[i].setWorldPosition(10,i*15-10,0);
}
//either create a few stacks, to show several islands, or create 1 large stack, showing stability
//ms[i].setWorldPosition((i*5) % 30,i*15-10,0);
ccdObjectCi.m_MotionState = &ms[i];
ccdObjectCi.m_gravity = SimdVector3(0,0,0);
ccdObjectCi.m_localInertiaTensor =SimdVector3(0,0,0);
if (!isDyna)
{
shapeProps.m_mass = 0.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
else
{
shapeProps.m_mass = 1.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
SimdVector3 localInertia;
if (shapeProps.m_mass>0.f)
{
shapePtr[shapeIndex[i]]->CalculateLocalInertia(shapeProps.m_mass,localInertia);
} else
{
localInertia.setValue(0.f,0.f,0.f);
}
ccdObjectCi.m_localInertiaTensor = localInertia;
ccdObjectCi.m_collisionShape = shapePtr[shapeIndex[i]];
physObjects[i]= new CcdPhysicsController( ccdObjectCi);
physicsEnvironmentPtr->addCcdPhysicsController( physObjects[i]);
/* if (i==0)
{
physObjects[i]->SetAngularVelocity(0,0,-2,true);
physObjects[i]->GetRigidBody()->setDamping(0,0);
}
*/
//for the line that represents the AABB extents
// physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
}
return glutmain(argc, argv,640,480,"Static Concave Mesh Demo");
}
void renderme()
{
float m[16];
int i;
for (i=0;i<numObjects;i++)
{
SimdTransform transA;
transA.setIdentity();
float pos[3];
float rot[4];
ms[i].getWorldPosition(pos[0],pos[1],pos[2]);
ms[i].getWorldOrientation(rot[0],rot[1],rot[2],rot[3]);
SimdQuaternion q(rot[0],rot[1],rot[2],rot[3]);
transA.setRotation(q);
SimdPoint3 dpos;
dpos.setValue(pos[0],pos[1],pos[2]);
transA.setOrigin( dpos );
transA.getOpenGLMatrix( m );
SimdVector3 wireColor(0.f,0.f,1.f); //wants deactivation
///color differently for active, sleeping, wantsdeactivation states
if (physObjects[i]->GetRigidBody()->GetActivationState() == 1) //active
{
wireColor = SimdVector3 (1.f,0.f,0.f);
}
if (physObjects[i]->GetRigidBody()->GetActivationState() == 2) //ISLAND_SLEEPING
{
wireColor = SimdVector3 (0.f,1.f,0.f);
}
char extraDebug[125];
//sprintf(extraDebug,"islId, Body=%i , %i",physObjects[i]->GetRigidBody()->m_islandTag1,physObjects[i]->GetRigidBody()->m_debugBodyId);
shapePtr[shapeIndex[i]]->SetExtraDebugInfo(extraDebug);
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[shapeIndex[i]],wireColor,getDebugMode());
}
}
void clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float deltaTime = 1.f/60.f;
physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
renderme();
glFlush();
glutSwapBuffers();
}
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos ConcaveDemo ;
BulletDemo ConcaveDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,67 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "MyMotionState.h"
#include "SimdPoint3.h"
MyMotionState::MyMotionState()
{
m_worldTransform.setIdentity();
}
MyMotionState::~MyMotionState()
{
}
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
{
posX = m_worldTransform.getOrigin().x();
posY = m_worldTransform.getOrigin().y();
posZ = m_worldTransform.getOrigin().z();
}
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
{
scaleX = 1.;
scaleY = 1.;
scaleZ = 1.;
}
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{
quatIma0 = m_worldTransform.getRotation().x();
quatIma1 = m_worldTransform.getRotation().y();
quatIma2 = m_worldTransform.getRotation().z();
quatReal = m_worldTransform.getRotation()[3];
}
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
{
SimdPoint3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
{
SimdQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
m_worldTransform.setRotation( orn );
}
void MyMotionState::calculateWorldTransformations()
{
}

View File

@@ -0,0 +1,44 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MY_MOTIONSTATE_H
#define MY_MOTIONSTATE_H
#include "PHY_IMotionState.h"
#include <SimdTransform.h>
class MyMotionState : public PHY_IMotionState
{
public:
MyMotionState();
virtual ~MyMotionState();
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void calculateWorldTransformations();
SimdTransform m_worldTransform;
};
#endif //MY_MOTIONSTATE_H

View File

@@ -0,0 +1,388 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "CcdPhysicsEnvironment.h"
#include "CcdPhysicsController.h"
#include "MyMotionState.h"
//#include "GL_LineSegmentShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "CollisionShapes/EmptyShape.h"
#include "Dynamics/RigidBody.h"
#include "ConstraintSolver/SimpleConstraintSolver.h"
#include "ConstraintSolver/OdeConstraintSolver.h"
#include "CollisionDispatch/CollisionDispatcher.h"
#include "BroadphaseCollision/SimpleBroadphase.h"
#include "IDebugDraw.h"
#include "GLDebugDrawer.h"
#include "PHY_Pro.h"
#include "BMF_Api.h"
#include <stdio.h> //printf debugging
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GL_ShapeDrawer.h"
#include "GlutStuff.h"
const int numObjects = 3;
const int maxNumObjects = 400;
MyMotionState ms[maxNumObjects];
CcdPhysicsController* physObjects[maxNumObjects] = {0,0,0,0};
int shapeIndex[maxNumObjects];
CcdPhysicsEnvironment* physicsEnvironmentPtr = 0;
#define CUBE_HALF_EXTENTS 1
//GL_LineSegmentShape shapeE(SimdPoint3(-50,0,0),
// SimdPoint3(50,0,0));
CollisionShape* shapePtr[4] =
{
new BoxShape (SimdVector3(10,10,10)),
new BoxShape (SimdVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
//new EmptyShape(),
new BU_Simplex1to4(SimdPoint3(-1,-1,-1),SimdPoint3(1,-1,-1),SimdPoint3(-1,1,-1),SimdPoint3(0,0,1)),
//new BoxShape (SimdVector3(0.4,1,0.8))
};
GLDebugDrawer debugDrawer;
int main(int argc,char** argv)
{
ConstraintSolver* solver = new SimpleConstraintSolver;
//ConstraintSolver* solver = new OdeConstraintSolver;
CollisionDispatcher* dispatcher = new CollisionDispatcher();
BroadphaseInterface* broadphase = new SimpleBroadphase();
physicsEnvironmentPtr = new CcdPhysicsEnvironment(dispatcher,broadphase);
physicsEnvironmentPtr->setDeactivationTime(0.f);
physicsEnvironmentPtr->setGravity(0,-10,0);
PHY_ShapeProps shapeProps;
shapeProps.m_do_anisotropic = false;
shapeProps.m_do_fh = false;
shapeProps.m_do_rot_fh = false;
shapeProps.m_friction_scaling[0] = 1.;
shapeProps.m_friction_scaling[1] = 1.;
shapeProps.m_friction_scaling[2] = 1.;
shapeProps.m_inertia = 1.f;
shapeProps.m_lin_drag = 0.2f;
shapeProps.m_ang_drag = 0.1f;
shapeProps.m_mass = 10.0f;
PHY_MaterialProps materialProps;
materialProps.m_friction = 10.5f;
materialProps.m_restitution = 0.0f;
CcdConstructionInfo ccdObjectCi;
ccdObjectCi.m_friction = 0.5f;
ccdObjectCi.m_linearDamping = shapeProps.m_lin_drag;
ccdObjectCi.m_angularDamping = shapeProps.m_ang_drag;
SimdTransform tr;
tr.setIdentity();
int i;
for (i=0;i<numObjects;i++)
{
if (i>0)
shapeIndex[i] = 1;//2 to test start with EmptyShape
else
shapeIndex[i] = 0;
}
for (i=0;i<numObjects;i++)
{
shapeProps.m_shape = shapePtr[shapeIndex[i]];
shapeProps.m_shape->SetMargin(0.05f);
bool isDyna = i>0;
if (0)//i==1)
{
SimdQuaternion orn(0,0,0.1*SIMD_HALF_PI);
ms[i].setWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
}
if (i>0)
{
ms[i].setWorldPosition(0,i*CUBE_HALF_EXTENTS*2 - CUBE_HALF_EXTENTS,0);
} else
{
ms[i].setWorldPosition(0,-10,0);
}
ccdObjectCi.m_MotionState = &ms[i];
ccdObjectCi.m_gravity = SimdVector3(0,0,0);
ccdObjectCi.m_localInertiaTensor =SimdVector3(0,0,0);
if (!isDyna)
{
shapeProps.m_mass = 0.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
else
{
shapeProps.m_mass = 1.f;
ccdObjectCi.m_mass = shapeProps.m_mass;
}
SimdVector3 localInertia;
if (shapePtr[shapeIndex[i]]->GetShapeType() == EMPTY_SHAPE_PROXYTYPE)
{
//take inertia from first shape
shapePtr[1]->CalculateLocalInertia(shapeProps.m_mass,localInertia);
} else
{
shapePtr[shapeIndex[i]]->CalculateLocalInertia(shapeProps.m_mass,localInertia);
}
ccdObjectCi.m_localInertiaTensor = localInertia;
ccdObjectCi.m_collisionShape = shapePtr[shapeIndex[i]];
physObjects[i]= new CcdPhysicsController( ccdObjectCi);
physicsEnvironmentPtr->addCcdPhysicsController( physObjects[i]);
physicsEnvironmentPtr->setDebugDrawer(&debugDrawer);
}
clientResetScene();
{
//physObjects[i]->SetAngularVelocity(0,0,-2,true);
int constraintId;
float pivotX=CUBE_HALF_EXTENTS,
pivotY=CUBE_HALF_EXTENTS,
pivotZ=CUBE_HALF_EXTENTS;
float axisX=0,axisY=1,axisZ=0;
constraintId =physicsEnvironmentPtr->createConstraint(
physObjects[1],
//0,
physObjects[2],
PHY_POINT2POINT_CONSTRAINT,
//PHY_LINEHINGE_CONSTRAINT,
pivotX,pivotY,pivotZ,
axisX,axisY,axisZ
);
}
setCameraDistance(46.f);
return glutmain(argc, argv,640,480,"Constraint Demo. http://www.continuousphysics.com/Bullet/phpBB2/");
}
//to be implemented by the demo
void renderme()
{
debugDrawer.SetDebugMode(getDebugMode());
float m[16];
int i;
for (i=0;i<numObjects;i++)
{
SimdTransform transA;
transA.setIdentity();
float pos[3];
float rot[4];
ms[i].getWorldPosition(pos[0],pos[1],pos[2]);
ms[i].getWorldOrientation(rot[0],rot[1],rot[2],rot[3]);
SimdQuaternion q(rot[0],rot[1],rot[2],rot[3]);
transA.setRotation(q);
SimdPoint3 dpos;
dpos.setValue(pos[0],pos[1],pos[2]);
transA.setOrigin( dpos );
transA.getOpenGLMatrix( m );
SimdVector3 wireColor(0.f,0.f,1.f); //wants deactivation
///color differently for active, sleeping, wantsdeactivation states
if (physObjects[i]->GetRigidBody()->GetActivationState() == 1) //active
{
wireColor = SimdVector3 (1.f,0.f,0.f);
}
if (physObjects[i]->GetRigidBody()->GetActivationState() == 2) //ISLAND_SLEEPING
{
wireColor = SimdVector3 (0.f,1.f,0.f);
}
char extraDebug[125];
sprintf(extraDebug,"islId, Body=%i , %i",physObjects[i]->GetRigidBody()->m_islandTag1,physObjects[i]->GetRigidBody()->m_debugBodyId);
physObjects[i]->GetRigidBody()->GetCollisionShape()->SetExtraDebugInfo(extraDebug);
GL_ShapeDrawer::DrawOpenGL(m,physObjects[i]->GetRigidBody()->GetCollisionShape(),wireColor,getDebugMode());
if (getDebugMode()!=0 && (i>0))
{
if (physObjects[i]->GetRigidBody()->GetCollisionShape()->GetShapeType() == EMPTY_SHAPE_PROXYTYPE)
{
physObjects[i]->GetRigidBody()->SetCollisionShape(shapePtr[1]);
//remove the persistent collision pairs that were created based on the previous shape
BroadphaseProxy* bpproxy = physObjects[i]->GetRigidBody()->m_broadphaseHandle;
physicsEnvironmentPtr->GetBroadphase()->CleanProxyFromPairs(bpproxy);
SimdVector3 newinertia;
SimdScalar newmass = 10.f;
physObjects[i]->GetRigidBody()->GetCollisionShape()->CalculateLocalInertia(newmass,newinertia);
physObjects[i]->GetRigidBody()->setMassProps(newmass,newinertia);
physObjects[i]->GetRigidBody()->updateInertiaTensor();
}
}
}
glRasterPos3f(20,20,0);
char buf[124];
sprintf(buf,"space to reset");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
glRasterPos3f(20,15,0);
sprintf(buf,"c to show contact points");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
glRasterPos3f(20,10,0);
sprintf(buf,"cursor keys and z,x to navigate");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
glRasterPos3f(20,5,0);
sprintf(buf,"i to toggle simulation, s single step");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
glRasterPos3f(20,0,0);
sprintf(buf,"q to quit");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
glRasterPos3f(20,-5,0);
sprintf(buf,"d to toggle deactivation");
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
void clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float deltaTime = 1.f/60.f;
physicsEnvironmentPtr->proceedDeltaTime(0.f,deltaTime);
renderme();
glFlush();
glutSwapBuffers();
}
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
renderme();
glFlush();
glutSwapBuffers();
}
///make this positive to show stack falling from a distance
///this shows the penalty tresholds in action, springy/spungy look
#define EXTRA_HEIGHT 20.f
void clientResetScene()
{
int i;
for (i=0;i<numObjects;i++)
{
if (i>0)
{
//stack them
int colsize = 10;
int row = (i*CUBE_HALF_EXTENTS*2)/(colsize*2*CUBE_HALF_EXTENTS);
int col = (i)%(colsize)-colsize/2;
physObjects[i]->setPosition(col*2*CUBE_HALF_EXTENTS + (row%2)*CUBE_HALF_EXTENTS,
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,
0);
physObjects[i]->setOrientation(0,0,0,1);
physObjects[i]->SetLinearVelocity(0,0,0,false);
physObjects[i]->SetAngularVelocity(0,0,0,false);
} else
{
ms[i].setWorldPosition(0,-10,0);
}
}
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos ConstraintDemo ;
BulletDemo ConstraintDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,67 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "MyMotionState.h"
#include "SimdPoint3.h"
MyMotionState::MyMotionState()
{
m_worldTransform.setIdentity();
}
MyMotionState::~MyMotionState()
{
}
void MyMotionState::getWorldPosition(float& posX,float& posY,float& posZ)
{
posX = m_worldTransform.getOrigin().x();
posY = m_worldTransform.getOrigin().y();
posZ = m_worldTransform.getOrigin().z();
}
void MyMotionState::getWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
{
scaleX = 1.;
scaleY = 1.;
scaleZ = 1.;
}
void MyMotionState::getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
{
quatIma0 = m_worldTransform.getRotation().x();
quatIma1 = m_worldTransform.getRotation().y();
quatIma2 = m_worldTransform.getRotation().z();
quatReal = m_worldTransform.getRotation()[3];
}
void MyMotionState::setWorldPosition(float posX,float posY,float posZ)
{
SimdPoint3 pos(posX,posY,posZ);
m_worldTransform.setOrigin( pos );
}
void MyMotionState::setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
{
SimdQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
m_worldTransform.setRotation( orn );
}
void MyMotionState::calculateWorldTransformations()
{
}

View File

@@ -0,0 +1,44 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef MY_MOTIONSTATE_H
#define MY_MOTIONSTATE_H
#include "PHY_IMotionState.h"
#include <SimdTransform.h>
class MyMotionState : public PHY_IMotionState
{
public:
MyMotionState();
virtual ~MyMotionState();
virtual void getWorldPosition(float& posX,float& posY,float& posZ);
virtual void getWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
virtual void getWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
virtual void setWorldPosition(float posX,float posY,float posZ);
virtual void setWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
virtual void calculateWorldTransformations();
SimdTransform m_worldTransform;
};
#endif //MY_MOTIONSTATE_H

View File

@@ -0,0 +1,310 @@
/*
* Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies.
* Erwin Coumans makes no representations about the suitability
* of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
/*
Continuous Convex Collision Demo demonstrates an efficient continuous collision detection algorithm.
Both linear and angular velocities are supported. Convex Objects are sampled using Supporting Vertex.
Motion using Exponential Map.
Future ideas: Comparison with Screwing Motion.
Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon)
*/
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/MinkowskiSumShape.h"
#include "NarrowPhaseCollision/GjkPairDetector.h"
#include "NarrowPhaseCollision/GjkConvexCast.h"
#include "NarrowPhaseCollision/SubSimplexConvexCast.h"
#include "NarrowPhaseCollision/ContinuousConvexCollision.h"
#include "SimdTransformUtil.h"
#include "DebugCastResult.h"
#include "CollisionShapes/SphereShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 2;
SimdVector3 angVels[numObjects];
SimdVector3 linVels[numObjects];
PolyhedralConvexShape* shapePtr[maxNumObjects];
SimdTransform fromTrans[maxNumObjects];
SimdTransform toTrans[maxNumObjects];
//SimdTransform tr[numObjects];
void DrawRasterizerLine(float const* , float const*, int)
{
}
int screenWidth = 640.f;
int screenHeight = 480.f;
int main(int argc,char** argv)
{
setCameraDistance(40.f);
fromTrans[0].setOrigin(SimdVector3(0,10,20));
toTrans[0].setOrigin(SimdVector3(0,10,-20));
fromTrans[1].setOrigin(SimdVector3(-2,7,0));
toTrans[1].setOrigin(SimdVector3(-2,10,0));
SimdMatrix3x3 identBasis;
identBasis.setIdentity();
SimdMatrix3x3 basisA;
basisA.setIdentity();
basisA.setEulerZYX(0.f,-SIMD_HALF_PI,0.f);
fromTrans[0].setBasis(identBasis);
toTrans[0].setBasis(basisA);
fromTrans[1].setBasis(identBasis);
toTrans[1].setBasis(identBasis);
toTrans[1].setBasis(identBasis);
SimdVector3 boxHalfExtentsA(10,1,1);
SimdVector3 boxHalfExtentsB(1.1f,1.1f,1.1f);
BoxShape boxA(boxHalfExtentsA);
// BU_Simplex1to4 boxA(SimdPoint3(-2,0,-2),SimdPoint3(2,0,-2),SimdPoint3(0,0,2),SimdPoint3(0,2,0));
// BU_Simplex1to4 boxA(SimdPoint3(-12,0,0),SimdPoint3(12,0,0));
BoxShape boxB(boxHalfExtentsB);
// BU_Simplex1to4 boxB(SimdPoint3(0,10,0),SimdPoint3(0,-10,0));
shapePtr[0] = &boxA;
shapePtr[1] = &boxB;
shapePtr[0]->SetMargin(0.01f);
shapePtr[1]->SetMargin(0.01f);
for (int i=0;i<numObjects;i++)
{
SimdTransformUtil::CalculateVelocity(fromTrans[i],toTrans[i],1.f,linVels[i],angVels[i]);
}
return glutmain(argc, argv,screenWidth,screenHeight,"Continuous Convex Collision Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
static VoronoiSimplexSolver sVoronoiSimplexSolver;
SimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver;
bool drawLine= false;
int minlines = 0;
int maxlines = 512;
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
//GL_ShapeDrawer::DrawCoordSystem();
float m[16];
int i;
/*for (i=0;i<numObjects;i++)
{
fromTrans[i].getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i]);
}
*/
if (getDebugMode()==IDebugDraw::DBG_DrawAabb)
{
i=0;//for (i=1;i<numObjects;i++)
{
SimdScalar dt = 1.f;
SimdScalar boundingRadius = shapePtr[i]->GetAngularMotionDisc();
SimdScalar angspeed = angVels[i].length() * boundingRadius * dt;
SimdScalar linspeed = linVels[i].length() * dt;
SimdScalar totalspeed = angspeed + linspeed;
//for each object, subdivide the from/to transform in 10 equal steps
int numSubSteps = 10.f;
for (int s=0;s<10;s++)
{
SimdScalar subStep = s * 1.f/(float)numSubSteps;
SimdTransform interpolatedTrans;
SimdTransformUtil::IntegrateTransform(fromTrans[i],linVels[i],angVels[i],subStep,interpolatedTrans);
//fromTrans[i].getOpenGLMatrix(m);
//GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i]);
//toTrans[i].getOpenGLMatrix(m);
//GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i]);
interpolatedTrans.getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,0,1),getDebugMode());
}
}
}
int shapeIndex = 1;
SimdMatrix3x3 mat;
mat.setEulerZYX(yaw,pitch,roll);
SimdQuaternion orn;
mat.getRotation(orn);
orn.setEuler(yaw,pitch,roll);
fromTrans[1].setRotation(orn);
toTrans[1].setRotation(orn);
extern bool stepping;
extern bool singleStep;
if (stepping || singleStep)
{
singleStep = false;
pitch += 0.005f;
// yaw += 0.01f;
}
// SimdVector3 fromA(-25,11,0);
// SimdVector3 toA(-15,11,0);
// SimdQuaternion ornFromA(0.f,0.f,0.f,1.f);
// SimdQuaternion ornToA(0.f,0.f,0.f,1.f);
// SimdTransform rayFromWorld(ornFromA,fromA);
// SimdTransform rayToWorld(ornToA,toA);
SimdTransform rayFromWorld = fromTrans[0];
SimdTransform rayToWorld = toTrans[0];
if (drawLine)
{
glBegin(GL_LINES);
glColor3f(0, 0, 1);
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
glVertex3d(rayToWorld.getOrigin().x(),rayToWorld.getOrigin().y(),rayToWorld.getOrigin().z());
glEnd();
}
//now perform a raycast on the shapes, in local (shape) space
gGjkSimplexSolver.reset();
//choose one of the following lines
for (i=0;i<numObjects;i++)
{
fromTrans[i].getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
}
DebugCastResult rayResult1(fromTrans[0],shapePtr[0],linVels[0],angVels[0]);
for (i=1;i<numObjects;i++)
{
ConvexCast::CastResult rayResult2;
ConvexCast::CastResult* rayResultPtr;
if (IDebugDraw::DBG_DrawAabb)
{
rayResultPtr = &rayResult1;
} else
{
rayResultPtr = &rayResult2;
}
//GjkConvexCast convexCaster(&gGjkSimplexSolver);
//SubsimplexConvexCast convexCaster(&gGjkSimplexSolver);
//optional
ConvexPenetrationDepthSolver* penetrationDepthSolver = 0;
ContinuousConvexCollision convexCaster(shapePtr[0],shapePtr[i],&gGjkSimplexSolver,penetrationDepthSolver );
gGjkSimplexSolver.reset();
if (convexCaster.calcTimeOfImpact(fromTrans[0],toTrans[0],fromTrans[i] ,toTrans[i] ,*rayResultPtr))
{
glDisable(GL_DEPTH_TEST);
SimdTransform hitTrans;
SimdTransformUtil::IntegrateTransform(fromTrans[0],linVels[0],angVels[0],rayResultPtr->m_fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[0],SimdVector3(0,1,0),getDebugMode());
SimdTransformUtil::IntegrateTransform(fromTrans[i],linVels[i],angVels[i],rayResultPtr->m_fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(0,1,1),getDebugMode());
}
}
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos ContinuousConvexCollision ;
BulletDemo ContinuousConvexCollision : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,188 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
///
/// Convex Hull Distance Demo shows distance calculation between two convex hulls of points.
/// GJK with the VoronoiSimplexSolver is used.
///
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "CollisionShapes/ConvexHullShape.h"
#include "NarrowPhaseCollision/GjkPairDetector.h"
#include "NarrowPhaseCollision/PointCollector.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 2;
GL_Simplex1to4 simplex;
PolyhedralConvexShape* shapePtr[maxNumObjects];
SimdTransform tr[numObjects];
int screenWidth = 640.f;
int screenHeight = 480.f;
int main(int argc,char** argv)
{
clientResetScene();
SimdMatrix3x3 basisA;
basisA.setIdentity();
SimdMatrix3x3 basisB;
basisB.setIdentity();
tr[0].setBasis(basisA);
tr[1].setBasis(basisB);
SimdPoint3 points0[3]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1)};
SimdPoint3 points1[5]={SimdPoint3(1,0,0),SimdPoint3(0,1,0),SimdPoint3(0,0,1),SimdPoint3(0,0,-1),SimdPoint3(-1,-1,0)};
ConvexHullShape hullA(points0,3);
ConvexHullShape hullB(points1,5);
shapePtr[0] = &hullA;
shapePtr[1] = &hullB;
SimdTransform tr;
tr.setIdentity();
return glutmain(argc, argv,screenWidth,screenHeight,"Convex Hull Distance Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
static VoronoiSimplexSolver sGjkSimplexSolver;
SimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
//GL_ShapeDrawer::DrawCoordSystem();
float m[16];
int i;
GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f);
convexConvex.SetCachedSeperatingAxis(seperatingAxis);
PointCollector gjkOutput;
GjkPairDetector::ClosestPointInput input;
input.m_transformA = tr[0];
input.m_transformB = tr[1];
convexConvex.GetClosestPoints(input ,gjkOutput,0);
if (gjkOutput.m_hasResult)
{
SimdVector3 endPt = gjkOutput.m_pointInWorld +
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
glVertex3d(endPt.x(),endPt.y(),endPt.z());
glEnd();
}
for (i=0;i<numObjects;i++)
{
tr[i].getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
}
simplex.SetSimplexSolver(&sGjkSimplexSolver);
SimdPoint3 ybuf[4],pbuf[4],qbuf[4];
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
simplex.Reset();
for (i=0;i<numpoints;i++)
simplex.AddVertex(ybuf[i]);
SimdTransform ident;
ident.setIdentity();
ident.getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode());
SimdQuaternion orn;
orn.setEuler(yaw,pitch,roll);
tr[0].setRotation(orn);
tr[1].setRotation(orn);
pitch += 0.005f;
yaw += 0.01f;
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
tr[0].setOrigin(SimdVector3(0.0f,3.f,7.f));
tr[1].setOrigin(SimdVector3(0.0f,9.f,2.f));
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos ConvexHullDistance ;
BulletDemo ConvexHullDistance : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,462 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
EPA Copyright (c) Ricardo Padrela 2006
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* Sample that shows the Expanding Polytope Algorithm ( EPA )
* Generates two convex shapes and calculates the penetration depth
* between them in case they are penetrating
*/
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "GL_ShapeDrawer.h"
#include <GL/glut.h>
#include "GlutStuff.h"
#include <iostream>
#include <list>
#include <time.h>
#include "CollisionShapes/ConvexShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/SphereShape.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/EpaCommon.h"
#include "NarrowPhaseCollision/EpaVertex.h"
#include "NarrowPhaseCollision/EpaHalfEdge.h"
#include "NarrowPhaseCollision/EpaFace.h"
#include "NarrowPhaseCollision/EpaPolyhedron.h"
#include "NarrowPhaseCollision/Epa.h"
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
#include "NarrowPhaseCollision/EpaPenetrationDepthSolver.h"
SimplexSolverInterface simplexSolver;
EpaPenetrationDepthSolver epaPenDepthSolver;
int screenWidth = 640.f;
int screenHeight = 480.f;
// Scene stuff
SimdPoint3 g_sceneVolumeMin( -1, -1, -1 );
SimdPoint3 g_sceneVolumeMax( 1, 1, 1 );
bool g_shapesPenetrate = false;
SimdVector3 g_wWitnesses[ 2 ];
// Shapes stuff
ConvexShape* g_pConvexShapes[ 2 ] = { 0 };
SimdTransform g_convexShapesTransform[ 2 ];
SimdScalar g_animAngle = SIMD_RADS_PER_DEG;
bool g_pauseAnim = true;
// 0 - Box ; 1 - Sphere
int g_shapesType[ 2 ] = { 0 };
// Box config
SimdVector3 g_boxExtents( 1, 1, 1 );
// Sphere config
SimdScalar g_sphereRadius = 1;
float randomFloat( float rangeMin, float rangeMax )
{
return ( ( ( float ) ( rand() ) / ( float ) ( RAND_MAX ) ) * ( rangeMax - rangeMin ) + rangeMin );
}
int randomShapeType( int minShapeType, int maxShapeType )
{
return ( ( ( ( maxShapeType - minShapeType ) + 1 ) * rand() ) / ( ( RAND_MAX + 1 ) + minShapeType ) );
}
SimdVector3 randomPosition( const SimdPoint3& minPoint, const SimdPoint3& maxPoint )
{
return SimdVector3( randomFloat( minPoint.getX(), maxPoint.getX() ),
randomFloat( minPoint.getY(), maxPoint.getY() ),
randomFloat( minPoint.getZ(), maxPoint.getZ() ) );
}
bool createBoxShape( int shapeIndex )
{
//#ifdef _DEBUG
//static bool b = true;
//
//if ( b )
//{
// g_pConvexShapes[ shapeIndex ] = new BoxShape( SimdVector3( 1, 1, 1 ) );
// g_pConvexShapes[ shapeIndex ]->SetMargin( 0.05 );
// g_convexShapesTransform[ shapeIndex ].setIdentity();
// SimdMatrix3x3 basis( 0.99365157, 0.024418538, -0.10981932,
// -0.025452739, 0.99964380, -0.0080251107,
// 0.10958424, 0.010769366, 0.99391919 );
// g_convexShapesTransform[ shapeIndex ].setOrigin( SimdVector3( 4.4916530, -19.059078, -0.22695254 ) );
// g_convexShapesTransform[ shapeIndex ].setBasis( basis );
// b = false;
//}
//else
//{
// g_pConvexShapes[ shapeIndex ] = new BoxShape( SimdVector3( 25, 10, 25 ) );
// g_pConvexShapes[ shapeIndex ]->SetMargin( 0.05 );
// //SimdMatrix3x3 basis( 0.658257, 0.675022, -0.333709,
// // -0.333120, 0.658556, 0.675023,
// // 0.675314, -0.333120, 0.658256 );
// g_convexShapesTransform[ shapeIndex ].setIdentity();
// g_convexShapesTransform[ shapeIndex ].setOrigin( SimdVector3( 0, -30, 0/*0.326090, -0.667531, 0.214331*/ ) );
// //g_convexShapesTransform[ shapeIndex ].setBasis( basis );
//}
//#endif
g_pConvexShapes[ shapeIndex ] = new BoxShape( SimdVector3( 1, 1, 1 ) );
g_pConvexShapes[ shapeIndex ]->SetMargin( 1e-1 );
g_convexShapesTransform[ shapeIndex ].setIdentity();
g_convexShapesTransform[ shapeIndex ].setOrigin( randomPosition( g_sceneVolumeMin, g_sceneVolumeMax ) );
return true;
}
bool createSphereShape( int shapeIndex )
{
g_pConvexShapes[ shapeIndex ] = new SphereShape( g_sphereRadius );
g_pConvexShapes[ shapeIndex ]->SetMargin( 1e-1 );
g_convexShapesTransform[ shapeIndex ].setIdentity();
g_convexShapesTransform[ shapeIndex ].setOrigin( randomPosition( g_sceneVolumeMin, g_sceneVolumeMax ) );
//#ifdef _DEBUG
//static bool b = true;
//if ( b )
//{
// g_convexShapesTransform[ shapeIndex ].setOrigin( SimdVector3( 0.001, 0, 0 ) );
// b = false;
//}
//else
//{
// g_convexShapesTransform[ shapeIndex ].setOrigin( SimdVector3( 0, 0, 0 ) );
//}
//#endif
return true;
}
void destroyShapes()
{
if ( g_pConvexShapes[ 0 ] )
{
delete g_pConvexShapes[ 0 ];
g_pConvexShapes[ 0 ] = 0;
}
if ( g_pConvexShapes[ 1 ] )
{
delete g_pConvexShapes[ 1 ];
g_pConvexShapes[ 1 ] = 0;
}
}
bool calcPenDepth()
{
// Ryn Hybrid Pen Depth and EPA if necessary
SimdVector3 v( 1, 0, 0 );
SimdScalar squaredDistance = SIMD_INFINITY;
SimdScalar delta = 0.f;
const SimdScalar margin = g_pConvexShapes[ 0 ]->GetMargin() + g_pConvexShapes[ 1 ]->GetMargin();
const SimdScalar marginSqrd = margin * margin;
SimdScalar maxRelErrorSqrd = 1e-3 * 1e-3;
simplexSolver.reset();
while ( true )
{
assert( ( v.length2() > 0 ) && "Warning: v is the zero vector!" );
SimdVector3 seperatingAxisInA = -v * g_convexShapesTransform[ 0 ].getBasis();
SimdVector3 seperatingAxisInB = v * g_convexShapesTransform[ 1 ].getBasis();
SimdVector3 pInA = g_pConvexShapes[ 0 ]->LocalGetSupportingVertexWithoutMargin( seperatingAxisInA );
SimdVector3 qInB = g_pConvexShapes[ 1 ]->LocalGetSupportingVertexWithoutMargin( seperatingAxisInB );
SimdPoint3 pWorld = g_convexShapesTransform[ 0 ]( pInA );
SimdPoint3 qWorld = g_convexShapesTransform[ 1 ]( qInB );
SimdVector3 w = pWorld - qWorld;
delta = v.dot( w );
// potential exit, they don't overlap
if ( ( delta > 0 ) && ( ( delta * delta / squaredDistance ) > marginSqrd ) )
{
// Convex shapes do not overlap
return false;
}
//exit 0: the new point is already in the simplex, or we didn't come any closer
if ( ( squaredDistance - delta <= squaredDistance * maxRelErrorSqrd ) || simplexSolver.inSimplex( w ) )
{
simplexSolver.compute_points( g_wWitnesses[ 0 ], g_wWitnesses[ 1 ] );
assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" );
SimdScalar vLength = sqrt( squaredDistance );
g_wWitnesses[ 0 ] -= v * ( g_pConvexShapes[ 0 ]->GetMargin() / vLength );
g_wWitnesses[ 1 ] += v * ( g_pConvexShapes[ 1 ]->GetMargin() / vLength );
return true;
}
//add current vertex to simplex
simplexSolver.addVertex( w, pWorld, qWorld );
//calculate the closest point to the origin (update vector v)
if ( !simplexSolver.closest( v ) )
{
simplexSolver.compute_points( g_wWitnesses[ 0 ], g_wWitnesses[ 1 ] );
assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" );
SimdScalar vLength = sqrt( squaredDistance );
g_wWitnesses[ 0 ] -= v * ( g_pConvexShapes[ 0 ]->GetMargin() / vLength );
g_wWitnesses[ 1 ] += v * ( g_pConvexShapes[ 1 ]->GetMargin() / vLength );
return true;
}
SimdScalar previousSquaredDistance = squaredDistance;
squaredDistance = v.length2();
//are we getting any closer ?
if ( previousSquaredDistance - squaredDistance <= SIMD_EPSILON * previousSquaredDistance )
{
simplexSolver.backup_closest( v );
squaredDistance = v.length2();
simplexSolver.compute_points( g_wWitnesses[ 0 ], g_wWitnesses[ 1 ] );
assert( ( squaredDistance > 0 ) && "squaredDistance is zero!" );
SimdScalar vLength = sqrt( squaredDistance );
g_wWitnesses[ 0 ] -= v * ( g_pConvexShapes[ 0 ]->GetMargin() / vLength );
g_wWitnesses[ 1 ] += v * ( g_pConvexShapes[ 1 ]->GetMargin() / vLength );
return true;
}
if ( simplexSolver.fullSimplex() || ( squaredDistance <= SIMD_EPSILON * simplexSolver.maxVertex() ) )
{
// Run EPA
break;
}
}
return epaPenDepthSolver.CalcPenDepth( simplexSolver, g_pConvexShapes[ 0 ], g_pConvexShapes[ 1 ],
g_convexShapesTransform[ 0 ], g_convexShapesTransform[ 1 ], v,
g_wWitnesses[ 0 ], g_wWitnesses[ 1 ], 0 );
}
int main(int argc,char** argv)
{
srand( time( 0 ) );
g_shapesType[ 0 ] = randomShapeType( 0, 1 );
g_shapesType[ 1 ] = randomShapeType( 0, 1 );
( g_shapesType[ 0 ] == 0 ) ? createBoxShape( 0 ) : createSphereShape( 0 );
( g_shapesType[ 1 ] == 0 ) ? createBoxShape( 1 ) : createSphereShape( 1 );
g_shapesPenetrate = calcPenDepth();
return glutmain( argc, argv, screenWidth, screenHeight, "EPAPenDepthDemo" );
}
void drawShape( int shapeIndex )
{
float m[ 16 ];
g_convexShapesTransform[ shapeIndex ].getOpenGLMatrix( m );
glMultMatrixf( m );
if ( g_pConvexShapes[ shapeIndex ]->GetShapeType() == BOX_SHAPE_PROXYTYPE )
{
glutWireCube( ( ( BoxShape* ) g_pConvexShapes[ shapeIndex ] )->GetHalfExtents().x() * 2 );
}
else if ( g_pConvexShapes[ shapeIndex ]->GetShapeType() == SPHERE_SHAPE_PROXYTYPE )
{
glutWireSphere( 1, 16, 16 );
}
}
void drawPenDepthVector()
{
glLoadIdentity();
glColor3f( 1, 1, 0 );
glPointSize( 5 );
glBegin( GL_POINTS );
glVertex3f( g_wWitnesses[ 0 ].getX(), g_wWitnesses[ 0 ].getY(), g_wWitnesses[ 0 ].getZ() );
glVertex3f( g_wWitnesses[ 1 ].getX(), g_wWitnesses[ 1 ].getY(), g_wWitnesses[ 1 ].getZ() );
glEnd();
glColor3f( 1, 0, 0 );
glBegin( GL_LINES );
glVertex3f( g_wWitnesses[ 0 ].getX(), g_wWitnesses[ 0 ].getY(), g_wWitnesses[ 0 ].getZ() );
glVertex3f( g_wWitnesses[ 1 ].getX(), g_wWitnesses[ 1 ].getY(), g_wWitnesses[ 1 ].getZ() );
glEnd();
}
void clientMoveAndDisplay()
{
if ( !g_pauseAnim )
{
SimdMatrix3x3 rot;
rot.setEulerZYX( g_animAngle * 0.05, g_animAngle * 0.05, g_animAngle * 0.05 );
SimdTransform t;
t.setIdentity();
t.setBasis( rot );
//g_convexShapesTransform[ 0 ].mult( g_convexShapesTransform[ 0 ], t );
g_convexShapesTransform[ 1 ].mult( g_convexShapesTransform[ 1 ], t );
g_shapesPenetrate = calcPenDepth();
}
clientDisplay();
}
void clientDisplay(void) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glDisable( GL_LIGHTING );
GL_ShapeDrawer::DrawCoordSystem();
glMatrixMode( GL_MODELVIEW );
for ( int i = 0; i < 2; ++i )
{
glPushMatrix();
drawShape( i );
glPopMatrix();
}
if ( g_shapesPenetrate )
{
glPushMatrix();
drawPenDepthVector();
glPopMatrix();
}
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
if ( key == 'R' || key == 'r' )
{
destroyShapes();
g_shapesType[ 0 ] = randomShapeType( 0, 1 );
g_shapesType[ 1 ] = randomShapeType( 0, 1 );
( g_shapesType[ 0 ] == 0 ) ? createBoxShape( 0 ) : createSphereShape( 0 );
( g_shapesType[ 1 ] == 0 ) ? createBoxShape( 1 ) : createSphereShape( 1 );
g_shapesPenetrate = calcPenDepth();
}
else if ( key == 'Q' || key == 'q' )
{
destroyShapes();
}
else if ( key == 'T' || key == 't' )
{
#ifdef DEBUG_ME
SimdVector3 shapeAPos = g_convexShapesTransform[ 0 ].getOrigin();
SimdVector3 shapeBPos = g_convexShapesTransform[ 1 ].getOrigin();
SimdMatrix3x3 shapeARot = g_convexShapesTransform[ 0 ].getBasis();
SimdMatrix3x3 shapeBRot = g_convexShapesTransform[ 1 ].getBasis();
FILE* fp = 0;
fopen_s( &fp, "shapes.txt", "w" );
char str[ 256 ];
sprintf_s( str, 256, "PosA: %f, %f, %f\nPosB: %f, %f, %f\n", shapeAPos.x(), shapeAPos.y(), shapeAPos.z(),
shapeBPos.x(), shapeBPos.y(), shapeBPos.z() );
fputs( str, fp );
sprintf_s( str, 256, "RotA: %f, %f, %f\n%f, %f, %f\n%f, %f, %f\nRotB: %f, %f, %f\n%f, %f, %f\n%f, %f, %f\n\n",
shapeARot.getRow( 0 ).x(), shapeARot.getRow( 0 ).y(), shapeARot.getRow( 0 ).z(),
shapeARot.getRow( 1 ).x(), shapeARot.getRow( 1 ).y(), shapeARot.getRow( 1 ).z(),
shapeARot.getRow( 2 ).x(), shapeARot.getRow( 2 ).y(), shapeARot.getRow( 2 ).z(),
shapeBRot.getRow( 0 ).x(), shapeBRot.getRow( 0 ).y(), shapeBRot.getRow( 0 ).z(),
shapeBRot.getRow( 1 ).x(), shapeBRot.getRow( 1 ).y(), shapeBRot.getRow( 1 ).z(),
shapeBRot.getRow( 2 ).x(), shapeBRot.getRow( 2 ).y(), shapeBRot.getRow( 2 ).z());
fputs( str, fp );
fclose( fp );
#endif //DEBUG_ME
}
else if ( key == 'P' || key =='p' )
{
g_pauseAnim = !g_pauseAnim;
}
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos EPAPenDepthDemo ;
BulletDemo EPAPenDepthDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos GjkConvexCastDemo ;
BulletDemo GjkConvexCastDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,248 @@
/*
* Copyright (c) 2005 Erwin Coumans http://continuousphysics.com/Bullet/
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies.
* Erwin Coumans makes no representations about the suitability
* of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
/*
LinearConvexCastDemo implements an efficient continuous collision detection algorithm.
Both linear and angular velocities are supported. Gjk or Simplex based methods.
Motion using Exponential Map.
Comparison with Screwing Motion.
Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon)
*/
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/MinkowskiSumShape.h"
#include "NarrowPhaseCollision/GjkPairDetector.h"
#include "NarrowPhaseCollision/GjkConvexCast.h"
#include "NarrowPhaseCollision/ContinuousConvexCollision.h"
#include "NarrowPhaseCollision/SubSimplexConvexCast.h"
#include "NarrowPhaseCollision/BU_CollisionPair.h"
#include "CollisionShapes/SphereShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 2;
PolyhedralConvexShape* shapePtr[maxNumObjects];
SimdTransform tr[numObjects];
int screenWidth = 640.f;
int screenHeight = 480.f;
void DrawRasterizerLine(float const* , float const*, int)
{
}
int main(int argc,char** argv)
{
setCameraDistance(30.f);
tr[0].setOrigin(SimdVector3(0,0,0));
tr[1].setOrigin(SimdVector3(0,10,0));
SimdMatrix3x3 basisA;
basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
-0.00029313788f,0.99753088f,0.070228584f,
-0.00089153741f,-0.070228823f,0.99753052f);
SimdMatrix3x3 basisB;
basisB.setValue(1.0000000f,4.4865553e-018f,-4.4410586e-017f,
4.4865495e-018f,0.97979438f,0.20000751f,
4.4410586e-017f,-0.20000751f,0.97979438f);
tr[0].setBasis(basisA);
tr[1].setBasis(basisB);
SimdVector3 boxHalfExtentsA(0.2,4,4);
SimdVector3 boxHalfExtentsB(6,6,6);
BoxShape boxA(boxHalfExtentsA);
/* BU_Simplex1to4 boxB;
boxB.AddVertex(SimdPoint3(-5,0,-5));
boxB.AddVertex(SimdPoint3(5,0,-5));
boxB.AddVertex(SimdPoint3(0,0,5));
boxB.AddVertex(SimdPoint3(0,5,0));
*/
BoxShape boxB(boxHalfExtentsB);
shapePtr[0] = &boxA;
shapePtr[1] = &boxB;
shapePtr[0]->SetMargin(0.01f);
shapePtr[1]->SetMargin(0.01f);
// boxA.SetMargin(1.f);
// boxB.SetMargin(1.f);
SimdTransform tr;
tr.setIdentity();
return glutmain(argc, argv,screenWidth,screenHeight,"Linear Convex Cast Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/ConvexPenetrationDepthSolver.h"
static VoronoiSimplexSolver sVoronoiSimplexSolver;
SimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver;
bool drawLine= false;
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
//GL_ShapeDrawer::DrawCoordSystem();
float m[16];
int i;
for (i=0;i<numObjects;i++)
{
tr[i].getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
}
int shapeIndex = 1;
SimdQuaternion orn;
orn.setEuler(yaw,pitch,roll);
tr[shapeIndex].setRotation(orn);
extern bool stepping;
extern bool singleStep;
if (stepping || singleStep)
{
singleStep = false;
pitch += 0.005f;
yaw += 0.01f;
}
SimdVector3 fromA(-25,11,0);
SimdVector3 toA(15,11,0);
SimdQuaternion ornFromA(0.f,0.f,0.f,1.f);
SimdQuaternion ornToA(0.f,0.f,0.f,1.f);
SimdTransform rayFromWorld(ornFromA,fromA);
SimdTransform rayToWorld(ornToA,toA);
tr[0] = rayFromWorld;
if (drawLine)
{
glBegin(GL_LINES);
glColor3f(0, 0, 1);
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
glVertex3d(rayToWorld.getOrigin().x(),rayToWorld.getOrigin().y(),rayToWorld.getOrigin().z());
glEnd();
}
//now perform a raycast on the shapes, in local (shape) space
//choose one of the following lines
for (i=1;i<numObjects;i++)
{
ContinuousConvexCollision convexCaster0(shapePtr[0],shapePtr[i],&gGjkSimplexSolver,0);
GjkConvexCast convexCaster1(shapePtr[0],shapePtr[i],&gGjkSimplexSolver);
//BU_CollisionPair (algebraic version) is currently broken, will look into this
BU_CollisionPair convexCaster2(shapePtr[0],shapePtr[i]);
SubsimplexConvexCast convexCaster3(shapePtr[0],shapePtr[i],&gGjkSimplexSolver);
gGjkSimplexSolver.reset();
ConvexCast::CastResult rayResult;
if (convexCaster3.calcTimeOfImpact(rayFromWorld,rayToWorld,tr[i],tr[i],rayResult))
{
glDisable(GL_DEPTH_TEST);
SimdVector3 hitPoint;
hitPoint.setInterpolate3(rayFromWorld.getOrigin(),rayToWorld.getOrigin(),rayResult.m_fraction);
//draw the raycast result
glBegin(GL_LINES);
glColor3f(1, 1, 1);
glVertex3d(rayFromWorld.getOrigin().x(), rayFromWorld.getOrigin().y(),rayFromWorld.getOrigin().z());
glVertex3d(hitPoint.x(),hitPoint.y(),hitPoint.z());
glEnd();
glEnable(GL_DEPTH_TEST);
SimdTransform toTransWorld;
toTransWorld = tr[0];
toTransWorld.setOrigin(hitPoint);
toTransWorld.getOpenGLMatrix( m );
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[0],SimdVector3(0,1,1),getDebugMode());
}
}
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

53
Demos/Jamfile Normal file
View File

@@ -0,0 +1,53 @@
SubDir TOP Demos ;
SubInclude TOP Demos OpenGL ;
if $(GLUT.AVAILABLE) = "yes"
{
# All demo apps have a lot in common, so use this rule to simply things
rule BulletDemo
{
Application $(<) : $(>) : noinstall console nomanifest ;
LinkWith $(<) : bullet bulletopenglsupport bulletphysicsinterfacecommon bulletccdphysics bulletmath ;
CFlags $(<) :
[ FIncludes $(TOP)/Demos/OpenGL ]
[ FIncludes $(TOP)/Extras/PhysicsInterface/CcdPhysics ]
[ FIncludes $(TOP)/Extras/PhysicsInterface/Common ]
;
MsvcIncDirs $(<) :
"../../Demos/OpenGL"
"../../Extras/PhysicsInterface/CcdPhysics"
"../../Extras/PhysicsInterface/Common" ;
}
}
else
{
rule BulletDemo
{
}
}
rule BulletBasicDemo
{
Application $(<) : $(>) : noinstall console nomanifest ;
LinkWith $(<) : bullet bulletphysicsinterfacecommon bulletccdphysics bulletmath ;
CFlags $(<) :
[ FIncludes $(TOP)/Extras/PhysicsInterface/CcdPhysics ]
[ FIncludes $(TOP)/Extras/PhysicsInterface/Common ]
;
MsvcIncDirs $(<) :
"../../Extras/PhysicsInterface/CcdPhysics"
"../../Extras/PhysicsInterface/Common" ;
}
SubInclude TOP Demos BasicSample ;
SubInclude TOP Demos CcdPhysicsDemo ;
SubInclude TOP Demos CollisionDemo ;
SubInclude TOP Demos CollisionInterfaceDemo ;
SubInclude TOP Demos ConcaveDemo ;
SubInclude TOP Demos ConstraintDemo ;
SubInclude TOP Demos ContinuousConvexCollision ;
SubInclude TOP Demos GjkConvexCastDemo ;
SubInclude TOP Demos EPAPenDepthDemo ;
SubInclude TOP Demos Raytracer ;
SubInclude TOP Demos SimplexDemo ;

162
Demos/OpenGL/BMF_Api.cpp Normal file
View File

@@ -0,0 +1,162 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
*
* Implementation of the API of the OpenGL bitmap font library.
*/
#include "BMF_Api.h"
#include "BMF_BitmapFont.h"
#if BMF_INCLUDE_HELV10
extern BMF_FontData BMF_font_helv10;
static BMF_BitmapFont bmfHelv10(&BMF_font_helv10);
#endif // BMF_INCLUDE_HELV10
#if BMF_INCLUDE_HELV12
extern BMF_FontData BMF_font_helv12;
static BMF_BitmapFont bmfHelv12(&BMF_font_helv12);
#endif // BMF_INCLUDE_HELV12
#if BMF_INCLUDE_HELVB8
extern BMF_FontData BMF_font_helvb8;
static BMF_BitmapFont bmfHelvb8(&BMF_font_helvb8);
#endif // BMF_INCLUDE_HELVB8
#if BMF_INCLUDE_HELVB10
extern BMF_FontData BMF_font_helvb10;
static BMF_BitmapFont bmfHelvb10(&BMF_font_helvb10);
#endif // BMF_INCLUDE_HELVB10
#if BMF_INCLUDE_HELVB12
extern BMF_FontData BMF_font_helvb12;
static BMF_BitmapFont bmfHelvb12(&BMF_font_helvb12);
#endif // BMF_INCLUDE_HELVB12
#if BMF_INCLUDE_HELVB14
extern BMF_FontData BMF_font_helvb14;
static BMF_BitmapFont bmfHelvb14(&BMF_font_helvb14);
#endif // BMF_INCLUDE_HELVB14
#if BMF_INCLUDE_SCR12
extern BMF_FontData BMF_font_scr12;
static BMF_BitmapFont bmfScreen12(&BMF_font_scr12);
#endif // BMF_INCLUDE_SCR12
#if BMF_INCLUDE_SCR14
extern BMF_FontData BMF_font_scr14;
static BMF_BitmapFont bmfScreen14(&BMF_font_scr14);
#endif // BMF_INCLUDE_SCR14
#if BMF_INCLUDE_SCR15
extern BMF_FontData BMF_font_scr15;
static BMF_BitmapFont bmfScreen15(&BMF_font_scr15);
#endif // BMF_INCLUDE_SCR15
BMF_Font* BMF_GetFont(BMF_FontType font)
{
switch (font)
{
#if BMF_INCLUDE_HELV10
case BMF_kHelvetica10: return (BMF_Font*) &bmfHelv10;
#endif // BMF_INCLUDE_HELV10
#if BMF_INCLUDE_HELV12
case BMF_kHelvetica12: return (BMF_Font*) &bmfHelv12;
#endif // BMF_INCLUDE_HELV12
#if BMF_INCLUDE_HELVB8
case BMF_kHelveticaBold8: return (BMF_Font*) &bmfHelvb8;
#endif // BMF_INCLUDE_HELVB8
#if BMF_INCLUDE_HELVB10
case BMF_kHelveticaBold10: return (BMF_Font*) &bmfHelvb10;
#endif // BMF_INCLUDE_HELVB10
#if BMF_INCLUDE_HELVB12
case BMF_kHelveticaBold12: return (BMF_Font*) &bmfHelvb12;
#endif // BMF_INCLUDE_HELVB12
#if BMF_INCLUDE_HELVB14
case BMF_kHelveticaBold14: return (BMF_Font*) &bmfHelvb14;
#endif // BMF_INCLUDE_HELVB12
#if BMF_INCLUDE_SCR12
case BMF_kScreen12: return (BMF_Font*) &bmfScreen12;
#endif // BMF_INCLUDE_SCR12
#if BMF_INCLUDE_SCR14
case BMF_kScreen14: return (BMF_Font*) &bmfScreen14;
#endif // BMF_INCLUDE_SCR14
#if BMF_INCLUDE_SCR15
case BMF_kScreen15: return (BMF_Font*) &bmfScreen15;
#endif // BMF_INCLUDE_SCR15
default:
break;
}
return 0;
}
int BMF_DrawCharacter(BMF_Font* font, char c)
{
char str[2] = {c, '\0'};
return BMF_DrawString(font, str);
}
int BMF_DrawString(BMF_Font* font, const char* str)
{
if (!font) return 0;
((BMF_BitmapFont*)font)->DrawString(str);
return 1;
}
int BMF_GetCharacterWidth(BMF_Font* font, char c)
{
char str[2] = {c, '\0'};
return BMF_GetStringWidth(font, str);
}
int BMF_GetStringWidth(BMF_Font* font, char* str)
{
if (!font) return 0;
return ((BMF_BitmapFont*)font)->GetStringWidth(str);
}
void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r)
{
if (!font) return;
((BMF_BitmapFont*)font)->GetBoundingBox(*xmin_r, *ymin_r, *xmax_r, *ymax_r);
}
int BMF_GetFontTexture(BMF_Font* font) {
if (!font) return -1;
return ((BMF_BitmapFont*)font)->GetTexture();
}
void BMF_DrawStringTexture(BMF_Font* font, char *string, float x, float y, float z) {
if (!font) return;
((BMF_BitmapFont*)font)->DrawStringTexture(string, x, y, z);
}

128
Demos/OpenGL/BMF_Api.h Normal file
View File

@@ -0,0 +1,128 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
*
* API of the OpenGL bitmap font library.
* Currently draws fonts using the glBitmap routine.
* This implies that drawing speed is heavyly dependant on
* the 2D capabilities of the graphics card.
*/
#ifndef __BMF_API_H
#define __BMF_API_H
#ifdef __cplusplus
extern "C" {
#endif
#include "BMF_Fonts.h"
/**
* Returns the font for a given font type.
* @param font The font to retrieve.
* @return The font (or nil if not found).
*/
BMF_Font* BMF_GetFont(BMF_FontType font);
/**
* Draws a character at the current raster position.
* @param font The font to use.
* @param c The character to draw.
* @return Indication of success (0 == error).
*/
int BMF_DrawCharacter(BMF_Font* font, char c);
/**
* Draws a string at the current raster position.
* @param font The font to use.
* @param str The string to draw.
* @return Indication of success (0 == error).
*/
int BMF_DrawString(BMF_Font* font, const char* str);
/**
* Returns the width of a character in pixels.
* @param font The font to use.
* @param c The character.
* @return The length.
*/
int BMF_GetCharacterWidth(BMF_Font* font, char c);
/**
* Returns the width of a string of characters.
* @param font The font to use.
* @param str The string.
* @return The length.
*/
int BMF_GetStringWidth(BMF_Font* font, char* str);
/**
* Returns the bounding box of the font. The width and
* height represent the bounding box of the union of
* all glyps. The minimum and maximum values of the
* box represent the extent of the font and its positioning
* about the origin.
*/
void BMF_GetBoundingBox(BMF_Font* font, int *xmin_r, int *ymin_r, int *xmax_r, int *ymax_r);
/**
* Convert the given @a font to a texture, and return the GL texture
* ID of the texture. If the texture ID is bound, text can
* be drawn using the texture by calling DrawStringTexture.
*
* @param font The font to create the texture from.
* @return The GL texture ID of the new texture, or -1 if unable
* to create.
*/
int BMF_GetFontTexture(BMF_Font* font);
/**
* Draw the given @a str at the point @a x, @a y, @a z, using
* texture coordinates. This assumes that an appropriate texture
* has been bound, see BMF_BitmapFont::GetTexture(). The string
* is drawn along the positive X axis.
*
* @param font The font to draw with.
* @param string The c-string to draw.
* @param x The x coordinate to start drawing at.
* @param y The y coordinate to start drawing at.
* @param z The z coordinate to start drawing at.
*/
void BMF_DrawStringTexture(BMF_Font* font, char* string, float x, float y, float z);
#ifdef __cplusplus
}
#endif
#endif /* __BMF_API_H */

View File

@@ -0,0 +1,208 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
*/
#include <string.h>
#if defined(WIN32) || defined(__APPLE__)
#ifdef WIN32
#if !defined(__CYGWIN32__)
#pragma warning(disable:4244)
#endif /* __CYGWIN32__ */
#include <windows.h>
#include <GL/gl.h>
#else // WIN32
// __APPLE__ is defined
#include <AGL/gl.h>
#endif // WIN32
#else // defined(WIN32) || defined(__APPLE__)
#include <GL/gl.h>
#endif // defined(WIN32) || defined(__APPLE__)
#include "BMF_BitmapFont.h"
BMF_BitmapFont::BMF_BitmapFont(BMF_FontData* fontData)
: m_fontData(fontData)
{
}
BMF_BitmapFont::~BMF_BitmapFont(void)
{
}
void BMF_BitmapFont::DrawString(const char* str)
{
if (!str)
return;
GLint alignment;
unsigned char c;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
while (c = (unsigned char) *str++) {
BMF_CharData & cd = m_fontData->chars[c];
if (cd.data_offset==-1) {
GLubyte nullBitmap = 0;
glBitmap(1, 1, 0, 0, cd.advance, 0, &nullBitmap);
} else {
GLubyte *bitmap = &m_fontData->bitmap_data[cd.data_offset];
glBitmap(cd.width, cd.height, cd.xorig, cd.yorig, cd.advance, 0, bitmap);
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
}
int BMF_BitmapFont::GetStringWidth(char* str)
{
unsigned char c;
int length = 0;
while (c = (unsigned char) *str++) {
length += m_fontData->chars[c].advance;
}
return length;
}
void BMF_BitmapFont::GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax)
{
xMin = m_fontData->xmin;
yMin = m_fontData->ymin;
xMax = m_fontData->xmax;
yMax = m_fontData->ymax;
}
int BMF_BitmapFont::GetTexture()
{
int fWidth = m_fontData->xmax - m_fontData->xmin;
int fHeight = m_fontData->ymax - m_fontData->ymin;
if (fWidth>=16 || fHeight>=16) {
return -1;
}
int cRows = 16, cCols = 16;
int cWidth = 16, cHeight = 16;
int iWidth = cCols*cWidth;
int iHeight = cRows*cHeight;
GLubyte *img = new GLubyte [iHeight*iWidth];
GLuint texId;
int baseLine = -(m_fontData->ymin);
memset(img, 0, iHeight*iWidth);
for (int i = 0; i<256; i++) {
BMF_CharData & cd = m_fontData->chars[i];
if (cd.data_offset != -1) {
int cellX = i%16;
int cellY = i/16;
for (int y = 0; y<cd.height; y++) {
GLubyte* imgRow = &img[(cellY*cHeight + y + baseLine - cd.yorig)*iWidth];
GLubyte* chrRow = &m_fontData->bitmap_data[cd.data_offset + ((cd.width+7)/8)*y];
for (int x = 0; x<cd.width; x++) {
GLubyte* imgPxl = &imgRow[(cellX*cWidth + x - cd.xorig)];
int byteIdx = x/8;
int bitIdx = 7 - (x%8);
if (chrRow[byteIdx]&(1<<bitIdx)) {
imgPxl[0] = 255;
}
}
}
}
}
glGenTextures(1, &texId);
glBindTexture(GL_TEXTURE_2D, texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA4, iWidth, iHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, img);
if (glGetError()) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE4_ALPHA4, iWidth, iHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, img);
}
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
delete [] img;
return texId;
}
void BMF_BitmapFont::DrawStringTexture(char *str, float x, float y, float z)
{
unsigned char c;
float pos = 0;
int baseLine = -(m_fontData->ymin);
glBegin(GL_QUADS);
while (c = (unsigned char) *str++) {
BMF_CharData & cd = m_fontData->chars[c];
if (cd.data_offset != -1) {
float cellX = (c%16)/16.0;
float cellY = (c/16)/16.0;
glTexCoord2f(cellX + 1.0/16.0, cellY);
glVertex3f(x + pos + 16.0, -baseLine + y + 0.0, z);
glTexCoord2f(cellX + 1.0/16.0, cellY + 1.0/16.0);
glVertex3f(x + pos + 16.0, -baseLine + y + 16.0, z);
glTexCoord2f(cellX, cellY + 1.0/16.0);
glVertex3f(x + pos + 0.0, -baseLine + y + 16.0, z);
glTexCoord2f(cellX, cellY);
glVertex3f(x + pos + 0.0, -baseLine + y + 0.0, z);
}
pos += cd.advance;
}
glEnd();
}

View File

@@ -0,0 +1,111 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
*/
#ifndef __BMF_BITMAP_FONT_H
#define __BMF_BITMAP_FONT_H
#include "BMF_FontData.h"
/**
* Base class for OpenGL bitmap fonts.
*/
class BMF_BitmapFont
{
public:
/**
* Default constructor.
*/
BMF_BitmapFont(BMF_FontData* fontData);
/**
* Destructor.
*/
virtual ~BMF_BitmapFont(void);
/**
* Draws a string at the current raster position.
* @param str The string to draw.
*/
void DrawString(const char* str);
void DrawStringMemory(char* str);
/**
* Draws a string at the current raster position.
* @param str The string to draw.
* @return The width of the string.
*/
int GetStringWidth(char* str);
/**
* Returns the bounding box of the font. The width and
* height represent the bounding box of the union of
* all glyps. The minimum and maximum values of the
* box represent the extent of the font and its positioning
* about the origin.
*/
void GetBoundingBox(int & xMin, int & yMin, int & xMax, int & yMax);
/**
* Convert the font to a texture, and return the GL texture
* ID of the texture. If the texture ID is bound, text can
* be drawn using the texture by calling DrawStringTexture.
*
* @return The GL texture ID of the new texture, or -1 if unable
* to create.
*/
int GetTexture();
/**
* Draw the given @a string at the point @a x, @a y, @a z, using
* texture coordinates. This assumes that an appropriate texture
* has been bound, see BMF_BitmapFont::GetTexture(). The string
* is drawn along the positive X axis.
*
* @param string The c-string to draw.
* @param x The x coordinate to start drawing at.
* @param y The y coordinate to start drawing at.
* @param z The z coordinate to start drawing at.
*/
void DrawStringTexture(char* string, float x, float y, float z);
protected:
/** Pointer to the font data. */
BMF_FontData* m_fontData;
};
#endif // __BMF_BITMAP_FONT_H

View File

@@ -0,0 +1,56 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
*/
#ifndef __BMF_FONTDATA_H__
#define __BMF_FONTDATA_H__
typedef struct {
signed char width, height;
signed char xorig, yorig;
signed char advance;
short data_offset;
} BMF_CharData;
typedef struct {
int xmin, ymin;
int xmax, ymax;
BMF_CharData chars[256];
unsigned char* bitmap_data;
} BMF_FontData;
#endif

75
Demos/OpenGL/BMF_Fonts.h Normal file
View File

@@ -0,0 +1,75 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
* Defines the names of the fonts in the library.
*/
#ifndef __BMF_FONTS_H
#define __BMF_FONTS_H
#include "BMF_Settings.h"
typedef enum
{
BMF_kHelvetica10 = 0,
#if BMF_INCLUDE_HELV12
BMF_kHelvetica12,
#endif
#if BMF_INCLUDE_HELVB8
BMF_kHelveticaBold8,
#endif
#if BMF_INCLUDE_HELVB10
BMF_kHelveticaBold10,
#endif
#if BMF_INCLUDE_HELVB12
BMF_kHelveticaBold12,
#endif
#if BMF_INCLUDE_HELVB14
BMF_kHelveticaBold14,
#endif
#if BMF_INCLUDE_SCR12
BMF_kScreen12,
#endif
#if BMF_INCLUDE_SCR14
BMF_kScreen14,
#endif
#if BMF_INCLUDE_SCR15
BMF_kScreen15,
#endif
BMF_kNumFonts
} BMF_FontType;
typedef struct BMF_Font BMF_Font;
#endif /* __BMF_FONTS_H */

View File

@@ -0,0 +1,52 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
/**
* Copyright (C) 2001 NaN Technologies B.V.
* Allows you to determine which fonts to include in the library.
*/
#ifndef __BMF_SETTINGS_H
#define __BMF_SETTINGS_H
#define BMF_INCLUDE_HELV12 0
#define BMF_INCLUDE_HELVB8 0
#define BMF_INCLUDE_HELVB10 0
#define BMF_INCLUDE_HELVB12 0
#define BMF_INCLUDE_HELVB14 0
#define BMF_INCLUDE_SCR12 0
#define BMF_INCLUDE_SCR14 0
#define BMF_INCLUDE_SCR15 0
#define BMF_INCLUDE_HELV10 1
#endif /* __BMF_SETTINGS_H */

View File

@@ -0,0 +1,491 @@
/**
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include "BMF_FontData.h"
#include "BMF_Settings.h"
#if BMF_INCLUDE_HELV10
static unsigned char bitmap_data[]= {
0x80,0x00,0x80,0x80,0x80,0x80,0x80,0x80,
0xa0,0xa0,0x50,0x50,0xf8,0x28,0x7c,0x28,
0x28,0x20,0x70,0xa8,0x28,0x70,0xa0,0xa8,
0x70,0x20,0x26,0x29,0x16,0x10,0x08,0x68,
0x94,0x64,0x64,0x98,0x98,0xa4,0x60,0x50,
0x50,0x20,0x80,0x40,0x40,0x20,0x40,0x40,
0x80,0x80,0x80,0x80,0x40,0x40,0x20,0x80,
0x40,0x40,0x20,0x20,0x20,0x20,0x40,0x40,
0x80,0xa0,0x40,0xa0,0x20,0x20,0xf8,0x20,
0x20,0x80,0x40,0x40,0xf8,0x80,0x80,0x80,
0x40,0x40,0x40,0x40,0x20,0x20,0x70,0x88,
0x88,0x88,0x88,0x88,0x88,0x70,0x40,0x40,
0x40,0x40,0x40,0x40,0xc0,0x40,0xf8,0x80,
0x40,0x30,0x08,0x08,0x88,0x70,0x70,0x88,
0x08,0x08,0x30,0x08,0x88,0x70,0x10,0x10,
0xf8,0x90,0x50,0x50,0x30,0x10,0x70,0x88,
0x08,0x08,0xf0,0x80,0x80,0xf8,0x70,0x88,
0x88,0xc8,0xb0,0x80,0x88,0x70,0x40,0x40,
0x20,0x20,0x10,0x10,0x08,0xf8,0x70,0x88,
0x88,0x88,0x70,0x88,0x88,0x70,0x70,0x88,
0x08,0x68,0x98,0x88,0x88,0x70,0x80,0x00,
0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x00,
0x00,0x00,0x00,0x40,0x20,0x40,0x80,0x40,
0x20,0xf0,0x00,0xf0,0x80,0x40,0x20,0x40,
0x80,0x40,0x00,0x40,0x40,0x20,0x10,0x90,
0x60,0x3e,0x00,0x40,0x00,0x9b,0x00,0xa4,
0x80,0xa4,0x80,0xa2,0x40,0x92,0x40,0x4d,
0x40,0x20,0x80,0x1f,0x00,0x82,0x82,0x7c,
0x44,0x28,0x28,0x10,0x10,0xf0,0x88,0x88,
0x88,0xf0,0x88,0x88,0xf0,0x78,0x84,0x80,
0x80,0x80,0x80,0x84,0x78,0xf0,0x88,0x84,
0x84,0x84,0x84,0x88,0xf0,0xf8,0x80,0x80,
0x80,0xf8,0x80,0x80,0xf8,0x80,0x80,0x80,
0x80,0xf0,0x80,0x80,0xf8,0x74,0x8c,0x84,
0x8c,0x80,0x80,0x84,0x78,0x84,0x84,0x84,
0x84,0xfc,0x84,0x84,0x84,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x60,0x90,0x10,
0x10,0x10,0x10,0x10,0x10,0x88,0x88,0x90,
0x90,0xe0,0xa0,0x90,0x88,0xf0,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x92,0x92,0x92,
0xaa,0xaa,0xc6,0xc6,0x82,0x8c,0x8c,0x94,
0x94,0xa4,0xa4,0xc4,0xc4,0x78,0x84,0x84,
0x84,0x84,0x84,0x84,0x78,0x80,0x80,0x80,
0x80,0xf0,0x88,0x88,0xf0,0x02,0x7c,0x8c,
0x94,0x84,0x84,0x84,0x84,0x78,0x88,0x88,
0x88,0x88,0xf0,0x88,0x88,0xf0,0x70,0x88,
0x88,0x08,0x70,0x80,0x88,0x70,0x20,0x20,
0x20,0x20,0x20,0x20,0x20,0xf8,0x78,0x84,
0x84,0x84,0x84,0x84,0x84,0x84,0x10,0x28,
0x28,0x44,0x44,0x44,0x82,0x82,0x22,0x00,
0x22,0x00,0x22,0x00,0x55,0x00,0x49,0x00,
0x49,0x00,0x88,0x80,0x88,0x80,0x88,0x88,
0x50,0x50,0x20,0x50,0x88,0x88,0x10,0x10,
0x10,0x28,0x28,0x44,0x44,0x82,0xf8,0x80,
0x40,0x20,0x20,0x10,0x08,0xf8,0xc0,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xc0,
0x20,0x20,0x40,0x40,0x40,0x40,0x80,0x80,
0xc0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
0x40,0xc0,0x88,0x50,0x50,0x20,0x20,0xfc,
0x80,0x80,0x40,0x68,0x90,0x90,0x70,0x10,
0xe0,0xb0,0xc8,0x88,0x88,0xc8,0xb0,0x80,
0x80,0x60,0x90,0x80,0x80,0x90,0x60,0x68,
0x98,0x88,0x88,0x98,0x68,0x08,0x08,0x60,
0x90,0x80,0xf0,0x90,0x60,0x40,0x40,0x40,
0x40,0x40,0xe0,0x40,0x30,0x70,0x08,0x68,
0x98,0x88,0x88,0x98,0x68,0x88,0x88,0x88,
0x88,0xc8,0xb0,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x00,0x80,0x90,0x90,
0xa0,0xc0,0xa0,0x90,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x92,0x92,
0x92,0x92,0x92,0xec,0x88,0x88,0x88,0x88,
0xc8,0xb0,0x70,0x88,0x88,0x88,0x88,0x70,
0x80,0x80,0xb0,0xc8,0x88,0x88,0xc8,0xb0,
0x08,0x08,0x68,0x98,0x88,0x88,0x98,0x68,
0x80,0x80,0x80,0x80,0xc0,0xa0,0x60,0x90,
0x10,0x60,0x90,0x60,0x60,0x40,0x40,0x40,
0x40,0xe0,0x40,0x40,0x70,0x90,0x90,0x90,
0x90,0x90,0x20,0x20,0x50,0x50,0x88,0x88,
0x28,0x28,0x54,0x54,0x92,0x92,0x88,0x88,
0x50,0x20,0x50,0x88,0x80,0x40,0x40,0x60,
0xa0,0xa0,0x90,0x90,0xf0,0x80,0x40,0x20,
0x10,0xf0,0x20,0x40,0x40,0x40,0x40,0x80,
0x40,0x40,0x40,0x20,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x40,
0x40,0x40,0x40,0x20,0x40,0x40,0x40,0x80,
0x98,0x64,0x80,0x80,0x80,0x80,0x80,0x80,
0x00,0x80,0x40,0x70,0xa8,0xa0,0xa0,0xa8,
0x70,0x10,0xb0,0x48,0x40,0x40,0xe0,0x40,
0x48,0x30,0x90,0x60,0x90,0x90,0x60,0x90,
0x20,0xf8,0x20,0xf8,0x50,0x50,0x88,0x88,
0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x80,
0x80,0x80,0x70,0x88,0x18,0x70,0xc8,0x98,
0x70,0xc0,0x88,0x70,0xa0,0x38,0x44,0x9a,
0xa2,0x9a,0x44,0x38,0xe0,0x00,0xa0,0x20,
0xe0,0x28,0x50,0xa0,0x50,0x28,0x08,0x08,
0xf8,0xe0,0x38,0x44,0xaa,0xb2,0xba,0x44,
0x38,0xe0,0x60,0x90,0x90,0x60,0xf8,0x00,
0x20,0x20,0xf8,0x20,0x20,0xe0,0x40,0xa0,
0x60,0xc0,0x20,0x40,0xe0,0x80,0x40,0x80,
0x80,0xf0,0x90,0x90,0x90,0x90,0x90,0x28,
0x28,0x28,0x28,0x28,0x68,0xe8,0xe8,0xe8,
0x7c,0xc0,0xc0,0x40,0x40,0x40,0xc0,0x40,
0xe0,0x00,0xe0,0xa0,0xe0,0xa0,0x50,0x28,
0x50,0xa0,0x21,0x00,0x17,0x80,0x13,0x00,
0x09,0x00,0x48,0x00,0x44,0x00,0xc4,0x00,
0x42,0x00,0x27,0x12,0x15,0x0b,0x48,0x44,
0xc4,0x42,0x21,0x00,0x17,0x80,0x13,0x00,
0x09,0x00,0xc8,0x00,0x24,0x00,0x44,0x00,
0xe2,0x00,0x60,0x90,0x80,0x40,0x20,0x20,
0x00,0x20,0x82,0x82,0x7c,0x44,0x28,0x28,
0x10,0x10,0x00,0x10,0x20,0x82,0x82,0x7c,
0x44,0x28,0x28,0x10,0x10,0x00,0x10,0x08,
0x82,0x82,0x7c,0x44,0x28,0x28,0x10,0x10,
0x00,0x28,0x10,0x82,0x82,0x7c,0x44,0x28,
0x28,0x10,0x10,0x00,0x28,0x14,0x82,0x82,
0x7c,0x44,0x28,0x28,0x10,0x10,0x00,0x28,
0x82,0x82,0x7c,0x44,0x28,0x28,0x10,0x10,
0x10,0x28,0x10,0x8f,0x80,0x88,0x00,0x78,
0x00,0x48,0x00,0x2f,0x80,0x28,0x00,0x18,
0x00,0x1f,0x80,0x30,0x10,0x78,0x84,0x80,
0x80,0x80,0x80,0x84,0x78,0xf8,0x80,0x80,
0x80,0xf8,0x80,0x80,0xf8,0x00,0x20,0x40,
0xf8,0x80,0x80,0x80,0xf8,0x80,0x80,0xf8,
0x00,0x20,0x10,0xf8,0x80,0x80,0xf8,0x80,
0x80,0x80,0xf8,0x00,0x50,0x20,0xf8,0x80,
0x80,0x80,0xf8,0x80,0x80,0xf8,0x00,0x50,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
0x00,0x40,0x80,0x80,0x80,0x80,0x80,0x80,
0x80,0x80,0x80,0x00,0x80,0x40,0x40,0x40,
0x40,0x40,0x40,0x40,0x40,0x40,0x00,0xa0,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
0x40,0x00,0xa0,0x78,0x44,0x42,0x42,0xf2,
0x42,0x44,0x78,0x8c,0x8c,0x94,0x94,0xa4,
0xa4,0xc4,0xc4,0x00,0x50,0x28,0x78,0x84,
0x84,0x84,0x84,0x84,0x84,0x78,0x00,0x10,
0x20,0x78,0x84,0x84,0x84,0x84,0x84,0x84,
0x78,0x00,0x10,0x08,0x78,0x84,0x84,0x84,
0x84,0x84,0x84,0x78,0x00,0x28,0x10,0x78,
0x84,0x84,0x84,0x84,0x84,0x84,0x78,0x00,
0x50,0x28,0x78,0x84,0x84,0x84,0x84,0x84,
0x84,0x78,0x00,0x48,0x88,0x50,0x20,0x50,
0x88,0x80,0x78,0xc4,0xa4,0xa4,0x94,0x94,
0x8c,0x78,0x04,0x78,0x84,0x84,0x84,0x84,
0x84,0x84,0x84,0x00,0x10,0x20,0x78,0x84,
0x84,0x84,0x84,0x84,0x84,0x84,0x00,0x20,
0x10,0x78,0x84,0x84,0x84,0x84,0x84,0x84,
0x84,0x00,0x28,0x10,0x78,0x84,0x84,0x84,
0x84,0x84,0x84,0x84,0x00,0x48,0x10,0x10,
0x10,0x28,0x28,0x44,0x44,0x82,0x00,0x10,
0x08,0x80,0x80,0xf0,0x88,0x88,0xf0,0x80,
0x80,0xa0,0x90,0x90,0x90,0xa0,0x90,0x90,
0x60,0x68,0x90,0x90,0x70,0x10,0xe0,0x00,
0x20,0x40,0x68,0x90,0x90,0x70,0x10,0xe0,
0x00,0x20,0x10,0x68,0x90,0x90,0x70,0x10,
0xe0,0x00,0x50,0x20,0x68,0x90,0x90,0x70,
0x10,0xe0,0x00,0xa0,0x50,0x68,0x90,0x90,
0x70,0x10,0xe0,0x00,0x50,0x68,0x90,0x90,
0x70,0x10,0xe0,0x20,0x50,0x20,0x6c,0x92,
0x90,0x7e,0x12,0xec,0x60,0x20,0x60,0x90,
0x80,0x80,0x90,0x60,0x60,0x90,0x80,0xf0,
0x90,0x60,0x00,0x20,0x40,0x60,0x90,0x80,
0xf0,0x90,0x60,0x00,0x40,0x20,0x60,0x90,
0x80,0xf0,0x90,0x60,0x00,0x50,0x20,0x60,
0x90,0x80,0xf0,0x90,0x60,0x00,0x50,0x40,
0x40,0x40,0x40,0x40,0x40,0x00,0x40,0x80,
0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x80,
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
0xa0,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
0x00,0xa0,0x70,0x88,0x88,0x88,0x88,0x78,
0x90,0x60,0x50,0x90,0x90,0x90,0x90,0x90,
0xe0,0x00,0xa0,0x50,0x70,0x88,0x88,0x88,
0x88,0x70,0x00,0x20,0x40,0x70,0x88,0x88,
0x88,0x88,0x70,0x00,0x20,0x10,0x70,0x88,
0x88,0x88,0x88,0x70,0x00,0x50,0x20,0x70,
0x88,0x88,0x88,0x88,0x70,0x00,0x50,0x28,
0x70,0x88,0x88,0x88,0x88,0x70,0x00,0x50,
0x20,0x00,0xf8,0x00,0x20,0x70,0x88,0xc8,
0xa8,0x98,0x74,0x70,0x90,0x90,0x90,0x90,
0x90,0x00,0x20,0x40,0x70,0x90,0x90,0x90,
0x90,0x90,0x00,0x40,0x20,0x70,0x90,0x90,
0x90,0x90,0x90,0x00,0x50,0x20,0x70,0x90,
0x90,0x90,0x90,0x90,0x00,0x50,0x80,0x40,
0x40,0x60,0xa0,0xa0,0x90,0x90,0x00,0x20,
0x10,0x80,0x80,0xb0,0xc8,0x88,0x88,0xc8,
0xb0,0x80,0x80,0x80,0x40,0x40,0x60,0xa0,
0xa0,0x90,0x90,0x00,0x50,
};
BMF_FontData BMF_font_helv10 = {
-1, -2,
10, 11,
{
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0, 0, 0, 0, 12, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0, 0, 0, 0, 3, -1},
{1, 8, -1, 0, 3, 0},
{3, 2, -1, -6, 4, 8},
{6, 7, 0, 0, 6, 10},
{5, 9, 0, 1, 6, 17},
{8, 8, 0, 0, 9, 26},
{6, 8, -1, 0, 8, 34},
{2, 3, -1, -5, 3, 42},
{3, 10, 0, 2, 4, 45},
{3, 10, -1, 2, 4, 55},
{3, 3, 0, -5, 4, 65},
{5, 5, 0, -1, 6, 68},
{2, 3, 0, 2, 3, 73},
{5, 1, -1, -3, 7, 76},
{1, 1, -1, 0, 3, 77},
{3, 8, 0, 0, 3, 78},
{5, 8, 0, 0, 6, 86},
{2, 8, -1, 0, 6, 94},
{5, 8, 0, 0, 6, 102},
{5, 8, 0, 0, 6, 110},
{5, 8, 0, 0, 6, 118},
{5, 8, 0, 0, 6, 126},
{5, 8, 0, 0, 6, 134},
{5, 8, 0, 0, 6, 142},
{5, 8, 0, 0, 6, 150},
{5, 8, 0, 0, 6, 158},
{1, 6, -1, 0, 3, 166},
{2, 8, 0, 2, 3, 172},
{3, 5, -1, -1, 6, 180},
{4, 3, 0, -2, 5, 185},
{3, 5, -1, -1, 6, 188},
{4, 8, -1, 0, 6, 193},
{10, 10, 0, 2, 11, 201},
{7, 8, 0, 0, 7, 221},
{5, 8, -1, 0, 7, 229},
{6, 8, -1, 0, 8, 237},
{6, 8, -1, 0, 8, 245},
{5, 8, -1, 0, 7, 253},
{5, 8, -1, 0, 6, 261},
{6, 8, -1, 0, 8, 269},
{6, 8, -1, 0, 8, 277},
{1, 8, -1, 0, 3, 285},
{4, 8, 0, 0, 5, 293},
{5, 8, -1, 0, 7, 301},
{4, 8, -1, 0, 6, 309},
{7, 8, -1, 0, 9, 317},
{6, 8, -1, 0, 8, 325},
{6, 8, -1, 0, 8, 333},
{5, 8, -1, 0, 7, 341},
{7, 9, -1, 1, 8, 349},
{5, 8, -1, 0, 7, 358},
{5, 8, -1, 0, 7, 366},
{5, 8, 0, 0, 5, 374},
{6, 8, -1, 0, 8, 382},
{7, 8, 0, 0, 7, 390},
{9, 8, 0, 0, 9, 398},
{5, 8, -1, 0, 7, 414},
{7, 8, 0, 0, 7, 422},
{5, 8, -1, 0, 7, 430},
{2, 10, -1, 2, 3, 438},
{3, 8, 0, 0, 3, 448},
{2, 10, 0, 2, 3, 456},
{5, 5, 0, -3, 6, 466},
{6, 1, 0, 2, 6, 471},
{2, 3, 0, -5, 3, 472},
{5, 6, 0, 0, 5, 475},
{5, 8, 0, 0, 6, 481},
{4, 6, 0, 0, 5, 489},
{5, 8, 0, 0, 6, 495},
{4, 6, 0, 0, 5, 503},
{4, 8, 0, 0, 4, 509},
{5, 8, 0, 2, 6, 517},
{5, 8, 0, 0, 6, 525},
{1, 8, 0, 0, 2, 533},
{1, 9, 0, 1, 2, 541},
{4, 8, 0, 0, 5, 550},
{1, 8, 0, 0, 2, 558},
{7, 6, 0, 0, 8, 566},
{5, 6, 0, 0, 6, 572},
{5, 6, 0, 0, 6, 578},
{5, 8, 0, 2, 6, 584},
{5, 8, 0, 2, 6, 592},
{3, 6, 0, 0, 4, 600},
{4, 6, 0, 0, 5, 606},
{3, 8, 0, 0, 4, 612},
{4, 6, 0, 0, 5, 620},
{5, 6, 0, 0, 6, 626},
{7, 6, 0, 0, 8, 632},
{5, 6, 0, 0, 6, 638},
{4, 8, 0, 2, 5, 644},
{4, 6, 0, 0, 5, 652},
{3, 10, 0, 2, 3, 658},
{1, 10, -1, 2, 3, 668},
{3, 10, 0, 2, 3, 678},
{6, 2, 0, -3, 7, 688},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0,0,0,0,0, -1},
{0, 0, 0, 0, 3, -1},
{1, 8, -1, 2, 3, 690},
{5, 8, 0, 1, 6, 698},
{5, 8, 0, 0, 6, 706},
{4, 6, 0, -1, 5, 714},
{5, 8, 0, 0, 6, 720},
{1, 10, -1, 2, 3, 728},
{5, 10, 0, 2, 6, 738},
{3, 1, 0, -7, 3, 748},
{7, 7, -1, 0, 9, 749},
{3, 5, 0, -3, 4, 756},
{5, 5, 0, 0, 6, 761},
{5, 3, -1, -2, 7, 766},
{3, 1, 0, -3, 4, 769},
{7, 7, -1, 0, 9, 770},
{3, 1, 0, -7, 3, 777},
{4, 4, 0, -3, 4, 778},
{5, 7, 0, 0, 6, 782},
{3, 4, 0, -3, 3, 789},
{3, 4, 0, -3, 3, 793},
{2, 2, 0, -6, 3, 797},
{4, 8, 0, 2, 5, 799},
{6, 10, 0, 2, 6, 807},
{2, 1, 0, -3, 3, 817},
{2, 2, 0, 2, 3, 818},
{2, 4, 0, -3, 3, 820},
{3, 5, 0, -3, 4, 824},
{5, 5, 0, 0, 6, 829},
{9, 8, 0, 0, 9, 834},
{8, 8, 0, 0, 9, 850},
{9, 8, 0, 0, 9, 858},
{4, 8, -1, 2, 6, 874},
{7, 11, 0, 0, 7, 882},
{7, 11, 0, 0, 7, 893},
{7, 11, 0, 0, 7, 904},
{7, 11, 0, 0, 7, 915},
{7, 10, 0, 0, 7, 926},
{7, 11, 0, 0, 7, 936},
{9, 8, 0, 0, 10, 947},
{6, 10, -1, 2, 8, 963},
{5, 11, -1, 0, 7, 973},
{5, 11, -1, 0, 7, 984},
{5, 11, -1, 0, 7, 995},
{5, 10, -1, 0, 7, 1006},
{2, 11, 0, 0, 3, 1016},
{2, 11, -1, 0, 3, 1027},
{3, 11, 0, 0, 3, 1038},
{3, 10, 0, 0, 3, 1049},
{7, 8, 0, 0, 8, 1059},
{6, 11, -1, 0, 8, 1067},
{6, 11, -1, 0, 8, 1078},
{6, 11, -1, 0, 8, 1089},
{6, 11, -1, 0, 8, 1100},
{6, 11, -1, 0, 8, 1111},
{6, 10, -1, 0, 8, 1122},
{5, 5, 0, -1, 6, 1132},
{6, 10, -1, 1, 8, 1137},
{6, 11, -1, 0, 8, 1147},
{6, 11, -1, 0, 8, 1158},
{6, 11, -1, 0, 8, 1169},
{6, 10, -1, 0, 8, 1180},
{7, 11, 0, 0, 7, 1190},
{5, 8, -1, 0, 7, 1201},
{4, 8, 0, 0, 5, 1209},
{5, 9, 0, 0, 5, 1217},
{5, 9, 0, 0, 5, 1226},
{5, 9, 0, 0, 5, 1235},
{5, 9, 0, 0, 5, 1244},
{5, 8, 0, 0, 5, 1253},
{5, 9, 0, 0, 5, 1261},
{7, 6, 0, 0, 8, 1270},
{4, 8, 0, 2, 5, 1276},
{4, 9, 0, 0, 5, 1284},
{4, 9, 0, 0, 5, 1293},
{4, 9, 0, 0, 5, 1302},
{4, 8, 0, 0, 5, 1311},
{2, 9, 1, 0, 2, 1319},
{2, 9, 0, 0, 2, 1328},
{3, 9, 1, 0, 2, 1337},
{3, 8, 0, 0, 2, 1346},
{5, 9, 0, 0, 6, 1354},
{4, 9, 0, 0, 5, 1363},
{5, 9, 0, 0, 6, 1372},
{5, 9, 0, 0, 6, 1381},
{5, 9, 0, 0, 6, 1390},
{5, 9, 0, 0, 6, 1399},
{5, 8, 0, 0, 6, 1408},
{5, 5, 0, -1, 6, 1416},
{6, 6, 0, 0, 6, 1421},
{4, 9, 0, 0, 5, 1427},
{4, 9, 0, 0, 5, 1436},
{4, 9, 0, 0, 5, 1445},
{4, 8, 0, 0, 5, 1454},
{4, 11, 0, 2, 5, 1462},
{5, 10, 0, 2, 6, 1473},
{4, 10, 0, 2, 5, 1483},
},
bitmap_data
};
#endif

View File

@@ -0,0 +1,76 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef DEBUG_CAST_RESULT_H
#define DEBUG_CAST_RESULT_H
#include "NarrowPhaseCollision/ConvexCast.h"
#include "SimdTransform.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
struct DebugCastResult : public ConvexCast::CastResult
{
SimdTransform m_fromTrans;
const PolyhedralConvexShape* m_shape;
SimdVector3 m_linVel;
SimdVector3 m_angVel;
DebugCastResult(const SimdTransform& fromTrans,const PolyhedralConvexShape* shape,
const SimdVector3& linVel,const SimdVector3& angVel)
:m_fromTrans(fromTrans),
m_shape(shape),
m_linVel(linVel),
m_angVel(angVel)
{
}
virtual void DrawCoordSystem(const SimdTransform& tr)
{
float m[16];
tr.getOpenGLMatrix(m);
glPushMatrix();
glLoadMatrixf(m);
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(0, 0, 0);
glVertex3d(1, 0, 0);
glColor3f(0, 1, 0);
glVertex3d(0, 0, 0);
glVertex3d(0, 1, 0);
glColor3f(0, 0, 1);
glVertex3d(0, 0, 0);
glVertex3d(0, 0, 1);
glEnd();
glPopMatrix();
}
virtual void DebugDraw(SimdScalar fraction)
{
float m[16];
SimdTransform hitTrans;
SimdTransformUtil::IntegrateTransform(m_fromTrans,m_linVel,m_angVel,fraction,hitTrans);
hitTrans.getOpenGLMatrix(m);
GL_ShapeDrawer::DrawOpenGL(m,m_shape,SimdVector3(1,0,0),IDebugDraw::DBG_NoDebug);
}
};
#endif //DEBUG_CAST_RESULT_H

View File

@@ -0,0 +1,53 @@
#include "GLDebugDrawer.h"
#include "SimdPoint3.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "BMF_Api.h"
#include <stdio.h> //printf debugging
GLDebugDrawer::GLDebugDrawer()
:m_debugMode(0)
{
}
void GLDebugDrawer::DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color)
{
if (m_debugMode > 0)
{
glBegin(GL_LINES);
glColor3f(color.getX(), color.getY(), color.getZ());
glVertex3d(from.getX(), from.getY(), from.getZ());
glVertex3d(to.getX(), to.getY(), to.getZ());
glEnd();
}
}
void GLDebugDrawer::SetDebugMode(int debugMode)
{
m_debugMode = debugMode;
}
void GLDebugDrawer::DrawContactPoint(const SimdVector3& pointOnB,const SimdVector3& normalOnB,float distance,int lifeTime,const SimdVector3& color)
{
if (m_debugMode & IDebugDraw::DBG_DrawContactPoints)
{
SimdVector3 to=pointOnB+normalOnB*distance;
const SimdVector3&from = pointOnB;
glBegin(GL_LINES);
glColor3f(color.getX(), color.getY(), color.getZ());
glVertex3d(from.getX(), from.getY(), from.getZ());
glVertex3d(to.getX(), to.getY(), to.getZ());
glEnd();
glRasterPos3f(from.x(), from.y(), from.z());
char buf[12];
sprintf(buf," %d",lifeTime);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
}

View File

@@ -0,0 +1,26 @@
#ifndef GL_DEBUG_DRAWER_H
#define GL_DEBUG_DRAWER_H
#include "IDebugDraw.h"
class GLDebugDrawer : public IDebugDraw
{
int m_debugMode;
public:
GLDebugDrawer();
virtual void DrawLine(const SimdVector3& from,const SimdVector3& to,const SimdVector3& color);
virtual void DrawContactPoint(const SimdVector3& PointOnB,const SimdVector3& normalOnB,float distance,int lifeTime,const SimdVector3& color);
virtual void SetDebugMode(int debugMode);
virtual int GetDebugMode() const { return m_debugMode;}
};
#endif//GL_DEBUG_DRAWER_H

View File

@@ -0,0 +1,232 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GL_ShapeDrawer.h"
#include "CollisionShapes/PolyhedralConvexShape.h"
#include "CollisionShapes/TriangleMeshShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/SphereShape.h"
#include "CollisionShapes/ConeShape.h"
#include "CollisionShapes/CylinderShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "IDebugDraw.h"
//for debugmodes
#include "BMF_Api.h"
#include <stdio.h> //printf debugging
void GL_ShapeDrawer::DrawCoordSystem() {
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(0, 0, 0);
glVertex3d(1, 0, 0);
glColor3f(0, 1, 0);
glVertex3d(0, 0, 0);
glVertex3d(0, 1, 0);
glColor3f(0, 0, 1);
glVertex3d(0, 0, 0);
glVertex3d(0, 0, 1);
glEnd();
}
class GlDrawcallback : public TriangleCallback
{
public:
virtual void ProcessTriangle(SimdVector3* triangle,int partId, int triangleIndex)
{
glBegin(GL_LINES);
glColor3f(1, 0, 0);
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 1, 0);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[1].getX(), triangle[1].getY(), triangle[1].getZ());
glColor3f(0, 0, 1);
glVertex3d(triangle[2].getX(), triangle[2].getY(), triangle[2].getZ());
glVertex3d(triangle[0].getX(), triangle[0].getY(), triangle[0].getZ());
glEnd();
}
};
void GL_ShapeDrawer::DrawOpenGL(float* m, const CollisionShape* shape, const SimdVector3& color,int debugMode)
{
glPushMatrix();
glLoadMatrixf(m);
//DrawCoordSystem();
glPushMatrix();
glEnable(GL_COLOR_MATERIAL);
glColor3f(color.x(),color.y(), color.z());
glRasterPos3f(0.0, 0.0, 0.0);
bool useWireframeFallback = true;
if (!(debugMode & IDebugDraw::DBG_DrawWireframe))
{
switch (shape->GetShapeType())
{
case BOX_SHAPE_PROXYTYPE:
{
const BoxShape* boxShape = static_cast<const BoxShape*>(shape);
SimdVector3 halfExtent = boxShape->GetHalfExtents();
glScaled(2*halfExtent[0], 2*halfExtent[1], 2*halfExtent[2]);
glutSolidCube(1.0);
useWireframeFallback = false;
break;
}
case TRIANGLE_SHAPE_PROXYTYPE:
case TETRAHEDRAL_SHAPE_PROXYTYPE:
{
const BU_Simplex1to4* tetra = static_cast<const BU_Simplex1to4*>(shape);
//todo:
useWireframeFallback = false;
break;
}
case CONVEX_HULL_SHAPE_PROXYTYPE:
case SPHERE_SHAPE_PROXYTYPE:
{
const SphereShape* sphereShape = static_cast<const SphereShape*>(shape);
float radius = sphereShape->GetMargin();//radius doesn't include the margin, so draw with margin
glutSolidSphere(radius,10,10);
useWireframeFallback = false;
break;
}
case MULTI_SPHERE_SHAPE_PROXYTYPE:
case CONE_SHAPE_PROXYTYPE:
{
const ConeShape* coneShape = static_cast<const ConeShape*>(shape);
float radius = coneShape->GetRadius();//+coneShape->GetMargin();
float height = coneShape->GetHeight();//+coneShape->GetMargin();
glutSolidCone(radius,height,10,10);
useWireframeFallback = false;
break;
}
case CONVEX_SHAPE_PROXYTYPE:
case CYLINDER_SHAPE_PROXYTYPE:
{
break;
}
default:
{
}
};
}
if (useWireframeFallback)
{
/// for polyhedral shapes
if (shape->IsPolyhedral())
{
PolyhedralConvexShape* polyshape = (PolyhedralConvexShape*) shape;
glBegin(GL_LINES);
int i;
for (i=0;i<polyshape->GetNumEdges();i++)
{
SimdPoint3 a,b;
polyshape->GetEdge(i,a,b);
glVertex3f(a.getX(),a.getY(),a.getZ());
glVertex3f(b.getX(),b.getY(),b.getZ());
}
glEnd();
if (debugMode==IDebugDraw::DBG_DrawText)
{
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->GetName());
}
if (debugMode==IDebugDraw::DBG_DrawFeaturesText)
{
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),polyshape->GetExtraDebugInfo());
glColor3f(1.f, 1.f, 1.f);
for (i=0;i<polyshape->GetNumVertices();i++)
{
SimdPoint3 vtx;
polyshape->GetVertex(i,vtx);
glRasterPos3f(vtx.x(), vtx.y(), vtx.z());
char buf[12];
sprintf(buf," %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
for (i=0;i<polyshape->GetNumPlanes();i++)
{
SimdVector3 normal;
SimdPoint3 vtx;
polyshape->GetPlane(normal,vtx,i);
SimdScalar d = vtx.dot(normal);
glRasterPos3f(normal.x()*d, normal.y()*d, normal.z()*d);
char buf[12];
sprintf(buf," plane %d",i);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
}
}
}
}
if (shape->GetShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
TriangleMeshShape* concaveMesh = (TriangleMeshShape*) shape;
//SimdVector3 aabbMax(1e30f,1e30f,1e30f);
//SimdVector3 aabbMax(100,100,100);//1e30f,1e30f,1e30f);
extern float eye[3];
SimdVector3 aabbMax(eye[0]+100,eye[1]+100,eye[2]+100);//1e30f,1e30f,1e30f);
SimdVector3 aabbMin(eye[0]-100,eye[1]-100,eye[2]-100);//1e30f,1e30f,1e30f);
GlDrawcallback drawCallback;
concaveMesh->ProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
}
glPopMatrix();
glPopMatrix();
}

View File

@@ -0,0 +1,31 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GL_SHAPE_DRAWER_H
#define GL_SHAPE_DRAWER_H
class CollisionShape;
#include "SimdVector3.h"
/// OpenGL shape drawing
class GL_ShapeDrawer
{
public:
static void DrawOpenGL(float* m, const CollisionShape* shape, const SimdVector3& color,int debugMode);
static void DrawCoordSystem();
};
#endif //GL_SHAPE_DRAWER_H

View File

@@ -0,0 +1,75 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "GL_Simplex1to4.h"
#include "NarrowPhaseCollision/SimplexSolverInterface.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include "SimdTransform.h"
GL_Simplex1to4::GL_Simplex1to4()
:m_simplexSolver(0)
{
}
///
/// Debugging method CalcClosest calculates the closest point to the origin, using m_simplexSolver
///
void GL_Simplex1to4::CalcClosest(float* m)
{
SimdTransform tr;
tr.setFromOpenGLMatrix(m);
GL_ShapeDrawer::DrawCoordSystem();
if (m_simplexSolver)
{
m_simplexSolver->reset();
bool res;
SimdVector3 v;
SimdPoint3 pBuf[4];
SimdPoint3 qBuf[4];
SimdPoint3 yBuf[4];
for (int i=0;i<m_numVertices;i++)
{
v = tr(m_vertices[i]);
m_simplexSolver->addVertex(v,v,SimdPoint3(0.f,0.f,0.f));
res = m_simplexSolver->closest(v);
int res = m_simplexSolver->getSimplex(pBuf, qBuf, yBuf);
}
//draw v?
glDisable(GL_LIGHTING);
glBegin(GL_LINES);
glColor3f(1.f, 0.f, 0.f);
glVertex3f(0.f, 0.f, 0.f);
glVertex3f(v.x(),v.y(),v.z());
glEnd();
glEnable(GL_LIGHTING);
}
}

View File

@@ -0,0 +1,40 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GL_SIMPLEX_1TO4_H
#define GL_SIMPLEX_1TO4_H
#include "CollisionShapes/Simplex1to4Shape.h"
#include "NarrowPhaseCollision/SimplexSolverInterface.h"
///GL_Simplex1to4 is a class to debug a Simplex Solver with 1 to 4 points.
///Can be used by GJK.
class GL_Simplex1to4 : public BU_Simplex1to4
{
SimplexSolverInterface* m_simplexSolver;
public:
GL_Simplex1to4();
void CalcClosest(float* m);
void SetSimplexSolver(SimplexSolverInterface* simplexSolver) {
m_simplexSolver = simplexSolver;
}
};
#endif //GL_SIMPLEX_1TO4_H

358
Demos/OpenGL/GlutStuff.cpp Normal file
View File

@@ -0,0 +1,358 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifdef WIN32//for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "IDebugDraw.h"
//see IDebugDraw.h for modes
static int sDebugMode = 0;
int getDebugMode()
{
return sDebugMode ;
}
void setDebugMode(int mode)
{
sDebugMode = mode;
}
#include "GlutStuff.h"
void myinit(void) {
GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
/* light_position is NOT default value */
GLfloat light_position0[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloat light_position1[] = { -1.0, -1.0, -1.0, 0.0 };
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT1, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearColor(0.8,0.8,0.8,0);
// glEnable(GL_CULL_FACE);
// glCullFace(GL_BACK);
}
static float DISTANCE = 15;
void setCameraDistance(float dist)
{
DISTANCE = dist;
}
static float ele = 0, azi = 0;
float eye[3] = {0, 0, DISTANCE};
static float center[3] = {0, 0, 0};
static const double SCALE_BOTTOM = 0.5;
static const double SCALE_FACTOR = 2;
bool stepping= true;
bool singleStep = false;
static bool idle = false;
void toggleIdle() {
if (idle) {
glutIdleFunc(clientMoveAndDisplay);
idle = false;
}
else {
glutIdleFunc(0);
idle = true;
}
}
void setCamera() {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float rele = ele * 0.01745329251994329547;// rads per deg
float razi = azi * 0.01745329251994329547;// rads per deg
eye[0] = DISTANCE * sin(razi) * cos(rele);
eye[1] = DISTANCE * sin(rele);
eye[2] = DISTANCE * cos(razi) * cos(rele);
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
gluLookAt(eye[0], eye[1], eye[2],
center[0], center[1], center[2],
0, 1, 0);
glMatrixMode(GL_MODELVIEW);
}
const float STEPSIZE = 5;
void stepLeft() { azi -= STEPSIZE; if (azi < 0) azi += 360; setCamera(); }
void stepRight() { azi += STEPSIZE; if (azi >= 360) azi -= 360; setCamera(); }
void stepFront() { ele += STEPSIZE; if (azi >= 360) azi -= 360; setCamera(); }
void stepBack() { ele -= STEPSIZE; if (azi < 0) azi += 360; setCamera(); }
void zoomIn() { DISTANCE -= 1; setCamera(); }
void zoomOut() { DISTANCE += 1; setCamera(); }
int glutScreenWidth = 0;
int glutScreenHeight = 0;
void myReshape(int w, int h) {
glutScreenWidth = w;
glutScreenHeight = h;
glViewport(0, 0, w, h);
setCamera();
}
int lastKey = 0;
void defaultKeyboard(unsigned char key, int x, int y)
{
lastKey = 0;
switch (key)
{
case 'q' : exit(0); break;
case 'l' : stepLeft(); break;
case 'r' : stepRight(); break;
case 'f' : stepFront(); break;
case 'b' : stepBack(); break;
case 'z' : zoomIn(); break;
case 'x' : zoomOut(); break;
case 'i' : toggleIdle(); break;
case 'h':
if (sDebugMode & IDebugDraw::DBG_NoHelpText)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoHelpText);
else
sDebugMode |= IDebugDraw::DBG_NoHelpText;
break;
case 'w':
if (sDebugMode & IDebugDraw::DBG_DrawWireframe)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawWireframe);
else
sDebugMode |= IDebugDraw::DBG_DrawWireframe;
break;
case 'p':
if (sDebugMode & IDebugDraw::DBG_ProfileTimings)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_ProfileTimings);
else
sDebugMode |= IDebugDraw::DBG_ProfileTimings;
break;
case 'm':
if (sDebugMode & IDebugDraw::DBG_EnableSatComparison)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableSatComparison);
else
sDebugMode |= IDebugDraw::DBG_EnableSatComparison;
break;
case 'n':
if (sDebugMode & IDebugDraw::DBG_DisableBulletLCP)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DisableBulletLCP);
else
sDebugMode |= IDebugDraw::DBG_DisableBulletLCP;
break;
case 't' :
if (sDebugMode & IDebugDraw::DBG_DrawText)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawText);
else
sDebugMode |= IDebugDraw::DBG_DrawText;
break;
case 'y':
if (sDebugMode & IDebugDraw::DBG_DrawFeaturesText)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawFeaturesText);
else
sDebugMode |= IDebugDraw::DBG_DrawFeaturesText;
break;
case 'a':
if (sDebugMode & IDebugDraw::DBG_DrawAabb)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawAabb);
else
sDebugMode |= IDebugDraw::DBG_DrawAabb;
break;
case 'c' :
if (sDebugMode & IDebugDraw::DBG_DrawContactPoints)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_DrawContactPoints);
else
sDebugMode |= IDebugDraw::DBG_DrawContactPoints;
break;
case 'd' :
if (sDebugMode & IDebugDraw::DBG_NoDeactivation)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_NoDeactivation);
else
sDebugMode |= IDebugDraw::DBG_NoDeactivation;
break;
case 'o' :
{
stepping = !stepping;
break;
}
case 's' : clientMoveAndDisplay(); break;
// case ' ' : newRandom(); break;
case ' ':
clientResetScene();
break;
case '1':
{
if (sDebugMode & IDebugDraw::DBG_EnableCCD)
sDebugMode = sDebugMode & (~IDebugDraw::DBG_EnableCCD);
else
sDebugMode |= IDebugDraw::DBG_EnableCCD;
break;
}
default:
// std::cout << "unused key : " << key << std::endl;
break;
}
glutPostRedisplay();
}
void mySpecial(int key, int x, int y)
{
switch (key)
{
case GLUT_KEY_LEFT : stepLeft(); break;
case GLUT_KEY_RIGHT : stepRight(); break;
case GLUT_KEY_UP : stepFront(); break;
case GLUT_KEY_DOWN : stepBack(); break;
case GLUT_KEY_PAGE_UP : zoomIn(); break;
case GLUT_KEY_PAGE_DOWN : zoomOut(); break;
case GLUT_KEY_HOME : toggleIdle(); break;
default:
// std::cout << "unused (special) key : " << key << std::endl;
break;
}
glutPostRedisplay();
}
void goodbye( void)
{
printf("goodbye \n");
exit(0);
}
void menu(int choice)
{
static int fullScreen = 0;
static int px, py, sx, sy;
switch(choice) {
case 1:
if (fullScreen == 1) {
glutPositionWindow(px,py);
glutReshapeWindow(sx,sy);
glutChangeToMenuEntry(1,"Full Screen",1);
fullScreen = 0;
} else {
px=glutGet((GLenum)GLUT_WINDOW_X);
py=glutGet((GLenum)GLUT_WINDOW_Y);
sx=glutGet((GLenum)GLUT_WINDOW_WIDTH);
sy=glutGet((GLenum)GLUT_WINDOW_HEIGHT);
glutFullScreen();
glutChangeToMenuEntry(1,"Close Full Screen",1);
fullScreen = 1;
}
break;
case 2:
toggleIdle();
break;
case 3:
goodbye();
break;
default:
break;
}
}
void createMenu()
{
glutCreateMenu(menu);
glutAddMenuEntry("Full Screen", 1);
glutAddMenuEntry("Toggle Idle (Start/Stop)", 2);
glutAddMenuEntry("Quit", 3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
int glutmain(int argc, char **argv,int width,int height,const char* title) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(0, 0);
glutInitWindowSize(width, height);
glutCreateWindow(title);
myinit();
glutKeyboardFunc(clientKeyboard);
glutSpecialFunc(mySpecial);
glutReshapeFunc(myReshape);
//createMenu();
glutIdleFunc(clientMoveAndDisplay);
glutMouseFunc(clientMouseFunc);
glutMotionFunc(clientMotionFunc);
glutDisplayFunc( clientDisplay );
glutMainLoop();
return 0;
}

35
Demos/OpenGL/GlutStuff.h Normal file
View File

@@ -0,0 +1,35 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef GLUT_STUFF_H
#define GLUT_STUFF_H
//to be implemented by the demo
void clientDisplay();
void clientMoveAndDisplay();
void clientResetScene();
int glutmain(int argc, char **argv,int width,int height,const char* title);
void setCameraDistance(float dist);
int getDebugMode();
void setDebugMode(int mode);
void defaultKeyboard(unsigned char key, int x, int y);
void clientKeyboard(unsigned char 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

8
Demos/OpenGL/Jamfile Normal file
View File

@@ -0,0 +1,8 @@
SubDir TOP Demos OpenGL ;
if $(GLUT.AVAILABLE) = "yes"
{
Description bulletopenglsupport : "Bullet OpenGL support" ;
Library bulletopenglsupport : [ Wildcard *.h *.cpp ] : noinstall ;
ExternalLibs bulletopenglsupport : GLUT ;
}

View File

@@ -0,0 +1,73 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "RenderTexture.h"
#include <memory.h>
#include "BMF_FontData.h"
RenderTexture::RenderTexture(int width,int height)
:m_height(height),m_width(width)
{
m_buffer = new unsigned char[m_width*m_height*4];
//clear screen
memset(m_buffer,0,m_width*m_height*4);
//clear screen version 2
for (int x=0;x<m_width;x++)
{
for (int y=0;y<m_height;y++)
{
SetPixel(x,y,SimdVector4(float(x),float(y),0.f,1.f));
}
}
}
void RenderTexture::Printf(char* str, BMF_FontData* fontData, int startx,int starty)
{
unsigned char c;
int rasterposx = startx;
int rasterposy = starty;
while (c = (unsigned char) *str++) {
BMF_CharData & cd = fontData->chars[c];
if (cd.data_offset!=-1) {
unsigned char* bitmap = &fontData->bitmap_data[cd.data_offset];
for (int y=0;y<cd.height;y++)
{
int bit = 128;
for (int x=0;x<cd.width;x++)
{
char packedColor = bitmap[y];
float colorf = packedColor & bit ? 1.f : 0.f;
SimdVector4 rgba(colorf,colorf,colorf,1.f);
SetPixel(rasterposx+x,rasterposy+8-y-1,rgba);
bit >>=1;
}
}
}
rasterposx+= cd.advance;
}
}
RenderTexture::~RenderTexture()
{
delete [] m_buffer;
}

View File

@@ -0,0 +1,53 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef RENDER_TEXTURE_H
#define RENDER_TEXTURE_H
#include "SimdVector3.h"
#include "BMF_FontData.h"
///
///RenderTexture provides a software-render context (setpixel/printf)
///
class RenderTexture
{
int m_height;
int m_width;
unsigned char* m_buffer;
public:
RenderTexture(int width,int height);
~RenderTexture();
inline void SetPixel(int x,int y,const SimdVector4& rgba)
{
unsigned char* pixel = &m_buffer[ (x+y*m_width) * 4];
pixel[0] = (unsigned char)(255*rgba.getX());
pixel[1] = (unsigned char)(255*rgba.getY());
pixel[2] = (unsigned char)(255*rgba.getZ());
pixel[3] = (unsigned char)(255*rgba.getW());
}
const unsigned char* GetBuffer() const { return m_buffer;}
int GetWidth() const { return m_width;}
int GetHeight() const { return m_height;}
void Printf(char* str, BMF_FontData* fontData, int startx = 0,int starty=0);
};
#endif //RENDER_TEXTURE_H

3
Demos/Raytracer/Jamfile Normal file
View File

@@ -0,0 +1,3 @@
SubDir TOP Demos Raytracer ;
BulletDemo Raytracer : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,412 @@
/*
* Copyright (c) 2005 Erwin Coumans <www.erwincoumans.com>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies.
* Erwin Coumans makes no representations about the suitability
* of this software for any purpose.
* It is provided "as is" without express or implied warranty.
*/
/*
Raytracer uses the Convex Raycast to visualize the Collision Shapes/Minkowski Sum.
Very basic raytracer, rendering into a texture.
*/
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
#include "NarrowPhaseCollision/SubSimplexConvexCast.h"
#include "NarrowPhaseCollision/GjkConvexCast.h"
#include "NarrowPhaseCollision/ContinuousConvexCollision.h"
#include "NarrowPhaseCollision/BU_CollisionPair.h"
#include "CollisionShapes/SphereShape.h"
#include "CollisionShapes/MultiSphereShape.h"
#include "CollisionShapes/ConvexHullShape.h"
#include "CollisionShapes/BoxShape.h"
#include "CollisionShapes/Simplex1to4Shape.h"
#include "CollisionShapes/ConeShape.h"
#include "CollisionShapes/CylinderShape.h"
#include "CollisionShapes/MinkowskiSumShape.h"
#include "RenderTexture.h"
VoronoiSimplexSolver simplexSolver;
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 4;
/// simplex contains the vertices, and some extra code to draw and debug
GL_Simplex1to4 simplex;
ConvexShape* shapePtr[maxNumObjects];
SimdTransform transforms[maxNumObjects];
RenderTexture* raytracePicture = 0;
int screenWidth = 128;
int screenHeight = 128;
GLuint glTextureId;
SphereShape mySphere(1);
BoxShape myBox(SimdVector3(0.4f,0.4f,0.4f));
CylinderShape myCylinder(SimdVector3(0.3f,0.3f,0.3f));
ConeShape myCone(1,1);
MinkowskiSumShape myMink(&myCylinder,&myBox);
///
///
///
int main(int argc,char** argv)
{
raytracePicture = new RenderTexture(screenWidth,screenHeight);
myBox.SetMargin(0.02f);
myCone.SetMargin(0.2f);
simplex.SetSimplexSolver(&simplexSolver);
simplex.AddVertex(SimdPoint3(-1,0,-1));
simplex.AddVertex(SimdPoint3(1,0,-1));
simplex.AddVertex(SimdPoint3(0,0,1));
simplex.AddVertex(SimdPoint3(0,1,0));
/// convex hull of 5 spheres
#define NUM_SPHERES 5
SimdVector3 inertiaHalfExtents(10.f,10.f,10.f);
SimdVector3 positions[NUM_SPHERES] = {
SimdVector3(-1.2f, -0.3f, 0.f),
SimdVector3(0.8f, -0.3f, 0.f),
SimdVector3(0.5f, 0.6f, 0.f),
SimdVector3(-0.5f, 0.6f, 0.f),
SimdVector3(0.f, 0.f, 0.f)
};
SimdScalar radi[NUM_SPHERES] = { 0.35f,0.35f,0.45f,0.40f,0.40f };
MultiSphereShape multiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES);
ConvexHullShape convexHullShape(positions,3);
//choose shape
shapePtr[0] = &myCone;
shapePtr[1] =&simplex;
shapePtr[2] =&convexHullShape;
shapePtr[3] =&myMink;//myBox;
simplex.SetMargin(0.3f);
setCameraDistance(6.f);
return glutmain(argc, argv,screenWidth,screenHeight,"Minkowski-Sum Raytracer Demo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
int once = 1;
extern float eye[3];
void clientDisplay(void)
{
for (int i=0;i<numObjects;i++)
{
transforms[i].setIdentity();
SimdVector3 pos(-3.5f+i*2.5f,0.f,0.f);
transforms[i].setOrigin( pos );
SimdQuaternion orn;
if (i < 2)
{
orn.setEuler(yaw,pitch,roll);
transforms[i].setRotation(orn);
}
}
myMink.SetTransformA(SimdTransform(transforms[0].getRotation()));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
if (once)
{
glGenTextures(1, &glTextureId);
glBindTexture(GL_TEXTURE_2D,glTextureId );
once = 0;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
}
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
#define RAYTRACER
#ifdef RAYTRACER
SimdVector4 rgba(1.f,0.f,0.f,0.5f);
float top = 1.f;
float bottom = -1.f;
float nearPlane = 1.f;
float tanFov = (top-bottom)*0.5f / nearPlane;
float fov = 2.0 * atanf (tanFov);
SimdVector3 rayFrom(eye[0],eye[1],eye[2]);
SimdVector3 rayForward = -rayFrom;
rayForward.normalize();
float farPlane = 600.f;
rayForward*= farPlane;
SimdVector3 rightOffset;
SimdVector3 vertical(0.f,1.f,0.f);
SimdVector3 hor;
hor = rayForward.cross(vertical);
hor.normalize();
vertical = hor.cross(rayForward);
vertical.normalize();
float tanfov = tanf(0.5f*fov);
hor *= 2.f * farPlane * tanfov;
vertical *= 2.f * farPlane * tanfov;
SimdVector3 rayToCenter = rayFrom + rayForward;
SimdVector3 dHor = hor * 1.f/float(screenWidth);
SimdVector3 dVert = vertical * 1.f/float(screenHeight);
SimdTransform rayFromTrans;
rayFromTrans.setIdentity();
rayFromTrans.setOrigin(rayFrom);
SimdTransform rayFromLocal;
SimdTransform rayToLocal;
SphereShape pointShape(0.0f);
///clear texture
for (int x=0;x<screenWidth;x++)
{
for (int y=0;y<screenHeight;y++)
{
SimdVector4 rgba(0.f,0.f,0.f,0.f);
raytracePicture->SetPixel(x,y,rgba);
}
}
ConvexCast::CastResult rayResult;
SimdTransform rayToTrans;
rayToTrans.setIdentity();
SimdVector3 rayTo;
for (int x=0;x<screenWidth;x++)
{
for (int y=0;y<screenHeight;y++)
{
rayTo = rayToCenter - 0.5f * hor + 0.5f * vertical;
rayTo += x * dHor;
rayTo -= y * dVert;
rayToTrans.setOrigin(rayTo);
for (int s=0;s<numObjects;s++)
{
// rayFromLocal = transforms[s].inverse()* rayFromTrans;
// rayToLocal = transforms[s].inverse()* rayToTrans;
//choose the continuous collision detection method
SubsimplexConvexCast convexCaster(&pointShape,shapePtr[s],&simplexSolver);
//GjkConvexCast convexCaster(&pointShape,shapePtr[0],&simplexSolver);
//ContinuousConvexCollision convexCaster(&pointShape,shapePtr[0],&simplexSolver,0);
// BU_Simplex1to4 ptShape(SimdVector3(0,0,0));//algebraic needs features, doesnt use 'supporting vertex'
// BU_CollisionPair convexCaster(&ptShape,shapePtr[0]);
//reset previous result
rayResult.m_fraction = 1.f;
if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,transforms[s],transforms[s],rayResult))
{
//float fog = 1.f - 0.1f * rayResult.m_fraction;
rayResult.m_normal.normalize();
SimdVector3 worldNormal;
worldNormal = transforms[s].getBasis() *rayResult.m_normal;
float light = worldNormal.dot(SimdVector3(0.4f,-1.f,-0.4f));
if (light < 0.2f)
light = 0.2f;
if (light > 1.f)
light = 1.f;
rgba = SimdVector4(light,light,light,1.f);
raytracePicture->SetPixel(x,y,rgba);
} else
{
//clear is already done
//rgba = SimdVector4(0.f,0.f,0.f,0.f);
//raytracePicture->SetPixel(x,y,rgba);
}
}
}
}
#define TEST_PRINTF
#ifdef TEST_PRINTF
extern BMF_FontData BMF_font_helv10;
raytracePicture->Printf("CCD RAYTRACER",&BMF_font_helv10);
char buffer[256];
sprintf(buffer,"%d RAYS / Frame",screenWidth*screenHeight*numObjects);
raytracePicture->Printf(buffer,&BMF_font_helv10,0,10);
#endif //TEST_PRINTF
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0,3,2020.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity(); // Reset The Modelview Matrix
glTranslatef(0.0f,0.0f,-3.0f); // Move Into The Screen 5 Units
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,glTextureId );
const unsigned char *ptr = raytracePicture->GetBuffer();
glTexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
raytracePicture->GetWidth(),raytracePicture->GetHeight(),
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
ptr);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f (1,1,1,1); // alpha=0.5=half visible
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1,1);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(1,1);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(1,-1);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-1,-1);
glEnd();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
#endif //RAYRACER
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
GL_ShapeDrawer::DrawCoordSystem();
glPushMatrix();
/*
/// normal opengl rendering
float m[16];
int i;
for (i=0;i<numObjects;i++)
{
transA.getOpenGLMatrix( m );
/// draw the simplex
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1));
/// calculate closest point from simplex to the origin, and draw this vector
simplex.CalcClosest(m);
}
*/
glPopMatrix();
pitch += 0.005f;
yaw += 0.01f;
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}

View File

@@ -0,0 +1,3 @@
SubDir TOP Demos SimplexDemo ;
BulletDemo SimplexDemo : [ Wildcard *.h *.cpp ] ;

View File

@@ -0,0 +1,134 @@
/*
Bullet Continuous Collision Detection and Physics Library
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/*
SimplexDemo demonstrated the working of the subdistance algorithm as used in GJK.
It draws the simplex, and calculates the closest vector from simplex to the origin
*/
#include "GL_Simplex1to4.h"
#include "SimdQuaternion.h"
#include "SimdTransform.h"
#include "GL_ShapeDrawer.h"
#ifdef WIN32 //needed for glut.h
#include <windows.h>
#endif
#include <GL/glut.h>
#include "GlutStuff.h"
#include "NarrowPhaseCollision/VoronoiSimplexSolver.h"
VoronoiSimplexSolver simplexSolver;
float yaw=0.f,pitch=0.f,roll=0.f;
const int maxNumObjects = 4;
const int numObjects = 1;
int screenWidth = 640.f;
int screenHeight = 480.f;
/// simplex contains the vertices, and some extra code to draw and debug
GL_Simplex1to4 simplex;
PolyhedralConvexShape* shapePtr[maxNumObjects];
///
///
///
int main(int argc,char** argv)
{
simplex.SetSimplexSolver(&simplexSolver);
simplex.AddVertex(SimdPoint3(-2,0,-2));
simplex.AddVertex(SimdPoint3(2,0,-2));
simplex.AddVertex(SimdPoint3(0,0,2));
simplex.AddVertex(SimdPoint3(0,2,0));
shapePtr[0] = &simplex;
SimdTransform tr;
tr.setIdentity();
return glutmain(argc, argv,screenWidth,screenHeight,"SimplexDemo");
}
//to be implemented by the demo
void clientMoveAndDisplay()
{
clientDisplay();
}
void clientDisplay(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
GL_ShapeDrawer::DrawCoordSystem();
float m[16];
int i;
for (i=0;i<numObjects;i++)
{
SimdTransform transA;
transA.setIdentity();
SimdVector3 dpos(0.f,5.f,0.f);
transA.setOrigin( dpos );
SimdQuaternion orn;
orn.setEuler(yaw,pitch,roll);
transA.setRotation(orn);
transA.getOpenGLMatrix( m );
/// draw the simplex
GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode());
/// calculate closest point from simplex to the origin, and draw this vector
simplex.CalcClosest(m);
}
pitch += 0.005f;
yaw += 0.01f;
glFlush();
glutSwapBuffers();
}
void clientResetScene()
{
}
void clientKeyboard(unsigned char key, int x, int y)
{
defaultKeyboard(key, x, y);
}
void clientMouseFunc(int button, int state, int x, int y)
{
}
void clientMotionFunc(int x,int y)
{
}