本文整理汇总了C++中btDiscreteDynamicsWorld类的典型用法代码示例。如果您正苦于以下问题:C++ btDiscreteDynamicsWorld类的具体用法?C++ btDiscreteDynamicsWorld怎么用?C++ btDiscreteDynamicsWorld使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了btDiscreteDynamicsWorld类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void setup()
{
mCam = new CameraPersp( getWindowWidth(), getWindowHeight(), 60.0f );
mCam->lookAt(Vec3f(100,400,-400), Vec3f::zero());
mSurface = 0;
mTexture = 0;
mCapture = new Capture( 320, 240 );
mCapture->startCapture();
mPaused = false;
mDrawTextured = true;
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
int maxProxies = 1024;
btAxisSweep3 * broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
btDefaultCollisionConfiguration * collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher * dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver * solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
btCollisionShape * groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState * groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
}
示例2: init
void init()
{
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_overlappingPairCache = new btDbvtBroadphase();
m_solver = new btSequentialImpulseConstraintSolver();
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_overlappingPairCache, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0, 0, 0));
m_debugDraw = new BulletDebugDraw();
m_dynamicsWorld->setDebugDrawer(m_debugDraw);
}
示例3:
BulletBoundsInstance::BulletBoundsInstance(btDiscreteDynamicsWorld& dynamicsWorld, float mass, const btTransform& instanceToWorldTransform, btCollisionShape* collisionShape, const btVector3& localInertia) :
motionState_(instanceToWorldTransform),
rigidBody_( btRigidBody::btRigidBodyConstructionInfo(mass, &motionState_, collisionShape, localInertia) )
{
rigidBody_.setDamping(0.1, 0.75);
//add the body to the dynamics world
dynamicsWorld.addRigidBody(&rigidBody_);
}
示例4: btDefaultCollisionConfiguration
void triMeshApp::initPhysics()
{
// setup physics environment. for all basic rigid body physics this can be left as it is
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_broadphase = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
}
示例5: btDefaultCollisionConfiguration
void winBodiesApp::initPhysics()
{
// setup physics environment. for all basic rigid body physics this can be left as it is
m_collisionConfiguration = new btDefaultCollisionConfiguration();
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
m_broadphase = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
m_solver = sol;
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher, m_broadphase, m_solver, m_collisionConfiguration);
m_dynamicsWorld->setGravity(btVector3(0,-10,0));
// make a ground plane that cannot be moved
btCollisionShape * groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState * groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
m_groundRigidBody = std::shared_ptr<btRigidBody>(new btRigidBody(groundRigidBodyCI));
m_dynamicsWorld->addRigidBody(m_groundRigidBody.get());
}
示例6: PhysicsObject
PhysicsObject(btDiscreteDynamicsWorld & world, const T & shape,
btScalar mass, btVector3 velocity,
const btTransform & transform,
GameBall * ptrBall):
_shape(shape),
_motionState(transform),
_rigidBody(mass, &_motionState, &_shape),
_ptrBall(ptrBall)
{
// TODO angular velocity ?
_rigidBody.setLinearVelocity(velocity);
_rigidBody.setDamping(0.1, 0.1);
_rigidBody.setRestitution(0.7);
_rigidBody.setFriction(0.1);
// TODO _rigidBody.setRollingFriction(0.01);
world.addRigidBody(&_rigidBody);
}
示例7: clean
void clean()
{
if (!m_dynamicsWorld)
return;
for (int i = m_dynamicsWorld->getNumCollisionObjects() - 1; i >= 0; i--)
{
btCollisionObject *obj = m_dynamicsWorld->getCollisionObjectArray()[i];
btRigidBody *body = btRigidBody::upcast(obj);
if (body && body->getMotionState())
delete body->getMotionState();
if (body && body->getCollisionShape())
delete body->getCollisionShape();
m_dynamicsWorld->removeCollisionObject(obj);
delete obj;
}
SAFE_DELETE(m_dynamicsWorld);
SAFE_DELETE(m_solver);
SAFE_DELETE(m_overlappingPairCache);
SAFE_DELETE(m_dispatcher);
SAFE_DELETE(m_collisionConfiguration);
SAFE_DELETE(m_debugDraw);
}
示例8: exitPhysics
void triMeshApp::exitPhysics()
{
//cleanup in the reverse order of creation/initialization
if(m_convexRigidBody->getMotionState())
delete m_convexRigidBody->getMotionState();
m_dynamicsWorld->removeRigidBody(m_convexRigidBody);
delete m_convexRigidBody;
if(m_concaveRigidBody->getMotionState())
delete m_concaveRigidBody->getMotionState();
m_dynamicsWorld->removeRigidBody(m_concaveRigidBody);
delete m_concaveRigidBody;
if(m_hfRigidBody->getMotionState())
delete m_hfRigidBody->getMotionState();
m_dynamicsWorld->removeRigidBody(m_hfRigidBody);
delete m_hfRigidBody;
delete m_dynamicsWorld;
delete m_solver;
delete m_broadphase;
delete m_dispatcher;
delete m_collisionConfiguration;
}
示例9:
~World(void) {
for (auto &robot : robots)
dynamics.removeRigidBody(&robot.body);
for (auto &ball : balls)
dynamics.removeRigidBody(&ball.body);
dynamics.removeRigidBody(&field.ground_body);
dynamics.removeRigidBody(&field.ceil_body);
dynamics.removeRigidBody(&field.left_wall_body);
dynamics.removeRigidBody(&field.right_wall_body);
dynamics.removeRigidBody(&field.top_wall_body);
dynamics.removeRigidBody(&field.bottom_wall_body);
dynamics.removeRigidBody(&field.left_goal_body);
dynamics.removeRigidBody(&field.right_goal_body);
}
示例10: World
World(const FieldGeometry *const field_geom)
: field_geometry{field_geom}, field{field_geom} {
dynamics.setGravity({0, 0, -9.80665});
dynamics.addRigidBody(&field.ground_body);
dynamics.addRigidBody(&field.ceil_body);
dynamics.addRigidBody(&field.left_wall_body);
dynamics.addRigidBody(&field.right_wall_body);
dynamics.addRigidBody(&field.top_wall_body);
dynamics.addRigidBody(&field.bottom_wall_body);
dynamics.addRigidBody(&field.left_goal_body);
dynamics.addRigidBody(&field.right_goal_body);
balls.emplace_back();
dynamics.addRigidBody(&balls.back().body);
ball_set_vec(&balls.back(), {});
}
示例11: RefreshColShape
// Physics dll internal
void RefreshColShape(IPhysicsInterface* colProvider){
if (!colProvider)
{
Logger::Log(FB_ERROR_LOG_ARG, "No colProvider");
return;
}
mWorld->removeRigidBody(mSelf);
mAddedToWorld = false;
auto prevColShape = mSelf->getCollisionShape();
if (prevColShape){
Physics::GetInstance().Release(prevColShape);
}
btCollisionShape* colShape = 0;
float mass = 1.0f;
auto& physics = Physics::GetInstance();
if (mGroupedRigidBody){
if (colProvider->GetNumColShapes(mGroupIdx) == 0)
return;
colShape = physics.CreateColShapeForGroup(colProvider, mGroupIdx);
mass = colProvider->GetMassForGroup(mGroupIdx);
}
else{
if (colProvider->GetNumColShapes() == 0)
return;
colShape = physics.CreateColShape(colProvider);
mass = colProvider->GetMass();
}
assert(colShape);
mSelf->setCollisionShape(colShape);
if (colShape)
physics.AddRef(colShape);
if (mass > 0 && colShape)
{
btVector3 inertia;
colShape->calculateLocalInertia(mass, inertia);
mSelf->setMassProps(mass, inertia);
}
else{
SetMass(0.f);
}
assert(!mAddedToWorld);
mWorld->addRigidBody(mSelf, colProvider->GetCollisionGroup(), colProvider->GetCollisionMask());
mAddedToWorld = true;
}
示例12: update
void triMeshApp::update()
{
m_dynamicsWorld->stepSimulation(1.0f, 10);
double now = getElapsedSeconds();
double dt = now - lastTime;
lastTime = now;
bool objectsErased = false;
for(int i = 0; i < mObjects.size(); i++)
{
mObjects[i]->update(dt);
if(mObjects[i]->lifetime > MAX_LIFETIME)
{
mObjects.erase(mObjects.begin() + i);
objectsErased = true;
}
}
if(objectsErased)
activateAllObjects(m_dynamicsWorld);
yrot += dt * 36.0;
if(yrot >=360.0) yrot = 0.0;
}
示例13: frameStarted
// frame listener
bool frameStarted(const FrameEvent &evt)
{
mKeyboard->capture();
// update physics simulation
dynamicsWorld->stepSimulation(evt.timeSinceLastFrame,50);
return mContinue;
}
示例14: update
void update()
{
if( mCapture->checkNewFrame() ) {
delete mTexture;
mTexture = new gl::Texture( mCapture->getSurface() );
}
if( ! mPaused )
dynamicsWorld->stepSimulation(1.0f, 10);
}
示例15: UnregisterFromWorld
void UnregisterFromWorld(){
if (mWorld){
auto num = mSelf->getNumConstraintRefs();
for (int i = 0; i < num; ++i){
auto constraint = mSelf->getConstraintRef(i);
assert(constraint);
constraint->setEnabled(false);
}
mWorld->removeRigidBody(mSelf);
mAddedToWorld = false;
}
}