implement hello world
from http://bulletphysics.org/mediawiki-1.5.8/index.php/Hello_World
This commit is contained in:
commit
136c7bfde8
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/main
|
4
Makefile
Normal file
4
Makefile
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
all: main
|
||||||
|
|
||||||
|
main: main.cc
|
||||||
|
g++ -o $@ $$(pkg-config --cflags bullet) $^ $$(pkg-config --libs bullet)
|
62
main.cc
Normal file
62
main.cc
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
btBroadphaseInterface * broadphase = new btDbvtBroadphase();
|
||||||
|
btDefaultCollisionConfiguration * collision_configuration = new btDefaultCollisionConfiguration();
|
||||||
|
btCollisionDispatcher * dispatcher = new btCollisionDispatcher(collision_configuration);
|
||||||
|
btSequentialImpulseConstraintSolver * solver = new btSequentialImpulseConstraintSolver;
|
||||||
|
btDiscreteDynamicsWorld * dynamics_world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collision_configuration);
|
||||||
|
dynamics_world->setGravity(btVector3(0, -9.8, 0));
|
||||||
|
|
||||||
|
btCollisionShape * ground_shape = new btStaticPlaneShape(btVector3(0, 1, 0), 1);
|
||||||
|
btCollisionShape * fall_shape = new btSphereShape(1);
|
||||||
|
|
||||||
|
btDefaultMotionState * ground_motion_state =
|
||||||
|
new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
|
||||||
|
btRigidBody::btRigidBodyConstructionInfo
|
||||||
|
ground_rigid_body_ci(0, ground_motion_state, ground_shape, btVector3(0, 0, 0));
|
||||||
|
btRigidBody * ground_rigid_body = new btRigidBody(ground_rigid_body_ci);
|
||||||
|
|
||||||
|
dynamics_world->addRigidBody(ground_rigid_body);
|
||||||
|
|
||||||
|
btDefaultMotionState * fall_motion_state =
|
||||||
|
new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 50, 0)));
|
||||||
|
|
||||||
|
btScalar mass = 1;
|
||||||
|
btVector3 fall_inertia(0, 0, 0);
|
||||||
|
fall_shape->calculateLocalInertia(mass, fall_inertia);
|
||||||
|
btRigidBody::btRigidBodyConstructionInfo
|
||||||
|
fall_rigid_body_ci(mass, fall_motion_state, fall_shape, fall_inertia);
|
||||||
|
btRigidBody * fall_rigid_body = new btRigidBody(fall_rigid_body_ci);
|
||||||
|
|
||||||
|
dynamics_world->addRigidBody(fall_rigid_body);
|
||||||
|
|
||||||
|
for (int i = 0; i < 300; i++)
|
||||||
|
{
|
||||||
|
dynamics_world->stepSimulation(1.0 / 60.0, 10);
|
||||||
|
|
||||||
|
btTransform trans;
|
||||||
|
fall_rigid_body->getMotionState()->getWorldTransform(trans);
|
||||||
|
|
||||||
|
std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete fall_rigid_body;
|
||||||
|
delete fall_motion_state;
|
||||||
|
|
||||||
|
delete ground_rigid_body;
|
||||||
|
delete ground_motion_state;
|
||||||
|
|
||||||
|
delete fall_shape;
|
||||||
|
delete ground_shape;
|
||||||
|
|
||||||
|
delete dynamics_world;
|
||||||
|
delete solver;
|
||||||
|
delete dispatcher;
|
||||||
|
delete collision_configuration;
|
||||||
|
delete broadphase;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user