2006-05-25 19:18:29 +00:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2006-09-30 01:36:39 +00:00
|
|
|
|
2006-09-25 08:58:57 +00:00
|
|
|
#include "btBulletDynamicsCommon.h"
|
2006-09-27 20:43:51 +00:00
|
|
|
#include "LinearMath/btIDebugDraw.h"
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
#include "GLDebugDrawer.h"
|
|
|
|
|
|
|
|
#include "BMF_Api.h"
|
|
|
|
#include <stdio.h> //printf debugging
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
#include "ConstraintDemo.h"
|
2006-05-25 19:18:29 +00:00
|
|
|
#include "GL_ShapeDrawer.h"
|
|
|
|
|
|
|
|
#include "GlutStuff.h"
|
|
|
|
|
|
|
|
const int numObjects = 3;
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
#define CUBE_HALF_EXTENTS 1.f
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
GLDebugDrawer debugDrawer;
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
int main(int argc,char** argv)
|
|
|
|
{
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
ConstraintDemo* constraintDemo = new ConstraintDemo();
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
constraintDemo->initPhysics();
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
constraintDemo->setCameraDistance(46.f);
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
return glutmain(argc, argv,640,480,"Constraint Demo. http://www.continuousphysics.com/Bullet/phpBB2/",constraintDemo);
|
|
|
|
}
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
void ConstraintDemo::initPhysics()
|
|
|
|
{
|
2006-09-27 20:43:51 +00:00
|
|
|
//ConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
|
2006-09-11 05:31:22 +00:00
|
|
|
//ConstraintSolver* solver = new OdeConstraintSolver;
|
2006-10-01 00:08:09 +00:00
|
|
|
//btCollisionDispatcher* dispatcher = new btCollisionDispatcher();
|
|
|
|
//btOverlappingPairCache* broadphase = new btSimpleBroadphase();
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-30 01:36:39 +00:00
|
|
|
m_dynamicsWorld = new btDiscreteDynamicsWorld();
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-27 20:43:51 +00:00
|
|
|
btCollisionShape* shape = new btBoxShape(btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
|
|
|
|
btTransform trans;
|
2006-09-11 05:31:22 +00:00
|
|
|
trans.setIdentity();
|
2006-09-27 20:43:51 +00:00
|
|
|
trans.setOrigin(btVector3(0,20,0));
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-10-04 23:46:27 +00:00
|
|
|
float mass = 0.f;
|
|
|
|
btRigidBody* body0 = localCreateRigidBody( mass,trans,shape);
|
2006-09-27 20:43:51 +00:00
|
|
|
trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));
|
2006-10-04 23:46:27 +00:00
|
|
|
|
|
|
|
mass = 1.f;
|
|
|
|
btRigidBody* body1 = localCreateRigidBody( mass,trans,shape);
|
2006-09-30 03:16:02 +00:00
|
|
|
body1->setDamping(0.3,0.3);
|
2006-10-04 23:46:27 +00:00
|
|
|
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
clientResetScene();
|
2006-09-11 05:31:22 +00:00
|
|
|
|
2006-05-25 19:18:29 +00:00
|
|
|
{
|
2006-09-30 01:36:39 +00:00
|
|
|
btVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS);
|
|
|
|
btVector3 axisInA(0,0,1);
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-30 01:36:39 +00:00
|
|
|
btVector3 pivotInB = body1 ? body1->getCenterOfMassTransform().inverse()(body0->getCenterOfMassTransform()(pivotInA)) : pivotInA;
|
|
|
|
btVector3 axisInB = body1?
|
|
|
|
(body1->getCenterOfMassTransform().getBasis().inverse()*(body1->getCenterOfMassTransform().getBasis() * axisInA)) :
|
|
|
|
body0->getCenterOfMassTransform().getBasis() * axisInA;
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-09-30 01:36:39 +00:00
|
|
|
btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB);
|
|
|
|
|
|
|
|
m_dynamicsWorld->addConstraint(p2p);
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
void ConstraintDemo::clientMoveAndDisplay()
|
2006-05-25 19:18:29 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
2006-10-18 04:32:00 +00:00
|
|
|
float dt = m_clock.getTimeMilliseconds() * 0.001f;
|
|
|
|
m_clock.reset();
|
2006-05-25 19:18:29 +00:00
|
|
|
|
2006-10-18 04:32:00 +00:00
|
|
|
|
|
|
|
m_dynamicsWorld->stepSimulation(dt);
|
2006-05-25 19:18:29 +00:00
|
|
|
renderme();
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
glutSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-09-11 05:31:22 +00:00
|
|
|
void ConstraintDemo::displayCallback(void) {
|
2006-05-25 19:18:29 +00:00
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
renderme();
|
|
|
|
|
|
|
|
glFlush();
|
|
|
|
glutSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
|