本文整理汇总了C++中btDiscreteDynamicsWorld::addRigidBody方法的典型用法代码示例。如果您正苦于以下问题:C++ btDiscreteDynamicsWorld::addRigidBody方法的具体用法?C++ btDiscreteDynamicsWorld::addRigidBody怎么用?C++ btDiscreteDynamicsWorld::addRigidBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类btDiscreteDynamicsWorld
的用法示例。
在下文中一共展示了btDiscreteDynamicsWorld::addRigidBody方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:
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_);
}
示例3: 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(), {});
}
示例4: 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;
}
示例5: RegisterToWorld
void RegisterToWorld(){
if (mWorld && mColProvider){
assert(!mAddedToWorld);
mWorld->addRigidBody(mSelf, mColProvider->GetCollisionGroup(), mColProvider->GetCollisionMask());
mAddedToWorld = true;
auto num = mSelf->getNumConstraintRefs();
for (int i = 0; i < num; ++i){
auto constraint = mSelf->getConstraintRef(i);
assert(constraint);
if (constraint->getRigidBodyA().isInWorld() && constraint->getRigidBodyB().isInWorld())
constraint->setEnabled(true);
}
}
else
Logger::Log(FB_ERROR_LOG_ARG, "No colprovier exists!");
}
示例6: utilAddGround
void BulletWrapper::utilAddGround()
{
m_BodyDatas.resize(m_BodyDatas.size() + 1);
BodyData& bodyData = m_BodyDatas.back();
// Create shape
bodyData.m_SharedShape.reset(new btStaticPlaneShape(btVector3(0, 1, 0), 1));
// Create motion
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -1, 0)));
// Create body
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, bodyData.m_SharedShape.get(), btVector3(0, 0, 0));
bodyData.m_Body = new btRigidBody(groundRigidBodyCI);
m_DynamicsWorld->addRigidBody(bodyData.m_Body);
}
示例7: 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);
}
示例8: utilAddFingerSphere
btRigidBody* BulletWrapper::utilAddFingerSphere(const EigenTypes::Vector3f& position, float radius, bool visible)
{
m_BodyDatas.resize(m_BodyDatas.size() + 1);
BodyData& bodyData = m_BodyDatas.back();
bodyData.m_SharedShape.reset(new btSphereShape(radius));
btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(position.x(), position.y(), position.z())));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
bodyData.m_SharedShape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, bodyData.m_SharedShape.get(), fallInertia);
bodyData.m_ShapeType = SHAPE_TYPE_SPHERE;
bodyData.m_Visible = visible;
bodyData.m_Body = new btRigidBody(fallRigidBodyCI);
bodyData.m_Body->setActivationState(DISABLE_DEACTIVATION);
m_DynamicsWorld->addRigidBody(bodyData.m_Body, COLLISION_GROUP_HAND, COLLISION_GROUP_DYNAMIC);
return bodyData.m_Body;
}
示例9: utilAddCube
void BulletWrapper::utilAddCube(const EigenTypes::Vector3f& position, const EigenTypes::Vector3f& halfExtents)
{
m_BodyDatas.resize(m_BodyDatas.size() + 1);
BodyData& bodyData = m_BodyDatas.back();
bodyData.m_SharedShape.reset(new btBoxShape(ToBullet(halfExtents)));
btDefaultMotionState* fallMotionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(position.x(), position.y(), position.z())));
btScalar mass = 1;
btVector3 fallInertia(0, 0, 0);
bodyData.m_SharedShape->calculateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, bodyData.m_SharedShape.get(), fallInertia);
bodyData.m_Body = new btRigidBody(fallRigidBodyCI);
bodyData.m_ShapeType = SHAPE_TYPE_BOX;
bodyData.m_Visible = true;
bodyData.m_Body->setActivationState(DISABLE_DEACTIVATION);
m_DynamicsWorld->addRigidBody(bodyData.m_Body, COLLISION_GROUP_DYNAMIC, COLLISION_GROUP_DYNAMIC | COLLISION_GROUP_HAND);
}
示例10: initPhysics
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());
}
示例11: createBulletSim
void createBulletSim(void) {
// EN:: collision configuration contains default setup for memory, collision setup.
// EN:: Advanced users can create their own configuration.
// BR:: configuração de colisão contem configurações padrão da memória.
// BR:: usuários avançados podem criar suas próprias configurações.
collisionConfiguration = new btDefaultCollisionConfiguration();
// EN:: use the default collision dispatcher. For parallel processing
// EN:: you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
// BR:: use o dispatcher padrão. para processamento paralelo
// BR:: você pode usar um dispatcher diferente. (ver Doc)
dispatcher = new btCollisionDispatcher(collisionConfiguration);
// EN:: btDbvtBroadphase is a good general purpose broadphase.
// EN:: You can also try out btAxis3Sweep.
// BR:: btDbvtBroadphase é um bom broadphase de propósito geral.
// BR:: Você pode tentar também btAxis3Sweep.
overlappingPairCache = new btDbvtBroadphase();
// EN:: the default constraint solver. For parallel processing
// EN:: you can use a different solver (see Extras/BulletMultiThreaded)
// BR:: usa a constraint solver padrão. Para processamento paralelo
// BR:: você pode ver um solver diferente (ver Doc)
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
// EN:: create a few basic rigid bodies
// EN:: start with ground plane, 1500, 1500
// BR:: cria alguns corpos rígidos básicos
// BR:: inicializa com um chão plano.
btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(1500.),btScalar(1.),btScalar(1500.)));
collisionShapes.push_back(groundShape);
btTransform groundTransform;
groundTransform.setIdentity();
groundTransform.setOrigin(btVector3(0,-2,0));
{
btScalar mass(0.);
// EN:: rigidbody is dynamic if and only if mass is non zero, otherwise static
// BR:: corpo rigido é dimâmico apenas se massa for diferente de 0.
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
// EN:: add the body to the dynamics world
// BR:: adiciona o corpo às dinâmicas do mundo
dynamicsWorld->addRigidBody(body);
}
{
// EN:: create a dynamic rigidbody
// BR:: cria um corpo rígido dinâmico
btCollisionShape* colShape = new btBoxShape(btVector3(1,1,1));
collisionShapes.push_back(colShape);
// EN:: Create Dynamic Objects
// BR:: Cria objetos dinâmicos
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(1.f);
// EN:: rigidbody is dynamic if and only if mass is non zero, otherwise static
// BR:: corpo rigido é dimâmico apenas se massa for diferente de 0.
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,-1.0);
if (isDynamic)
colShape->calculateLocalInertia(mass,localInertia);
startTransform.setOrigin(btVector3(0,250,0));
// *** give it a slight twist so it bouncees more interesting
startTransform.setRotation(btQuaternion(btVector3(1.0, 1.0, 0.0), 0.6));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
//btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
MyMotionState* motionState = new MyMotionState(startTransform, boxNode);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,motionState,colShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);
}
}