【问题标题】:Bullet physics - sphere doesn't bounce子弹物理 - 球体不反弹
【发布时间】:2014-07-25 22:20:54
【问题描述】:

我在玩 Bullet,我有一个地面和一个球,我希望球在地面上落下并弹跳。然而,即使m_restitution 的值非常高,这也不会发生,这应该是为了调节弹性。

任何线索为什么会发生这种情况?这折磨了我几个小时,但没有运气。

btBroadphaseInterface* broadphase = new btDbvtBroadphase();

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();

btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);

btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);

dynamicsWorld->setGravity(btVector3(0,+9.8,0)); // GLWidget - y axis points downwards !!!


/////////////////////////////////////////////////////////////////////////////
////  Ground  ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,0,0)));

btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0, groundMotionState, groundShape, btVector3(0,0,0));

groundRigidBodyCI.m_restitution     = 1.0f;
groundRigidBodyCI.m_friction        = 3.0f;
groundRigidBodyCI.m_rollingFriction = 3.0f;
groundRigidBodyCI.m_mass            = 0.0f;

btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);

dynamicsWorld->addRigidBody(groundRigidBody);


/////////////////////////////////////////////////////////////////////////////
////  Ball  /////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////

btDefaultMotionState* ballMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,-100,0)));

btScalar ballMass = 1;
btVector3 ballInertia;//(0,0,0);
ballShape->calculateLocalInertia(ballMass, ballInertia);

btRigidBody::btRigidBodyConstructionInfo ballRigidBodyCI(ballMass, ballMotionState, ballShape, ballInertia);
groundRigidBodyCI.m_restitution   = 1.0f;
ballRigidBodyCI.m_friction        = 1.0f;
ballRigidBodyCI.m_rollingFriction = 1.0f;

btRigidBody* ballRigidBody = new btRigidBody(ballRigidBodyCI);
dynamicsWorld->addRigidBody(ballRigidBody);


//Without the next it doesn't bounce at all
//With it, it bounces just a TINY little bit
dynamicsWorld->getSolverInfo().m_splitImpulse = false;

【问题讨论】:

  • 只是说:阅读那段代码真的很痛苦,可以做些什么来缩进它并更好地间隔它吗?
  • 是的,现在我希望它会更好。

标签: bulletphysics


【解决方案1】:

好的,上面的代码理论上应该可以工作,但我不确定为什么它不起作用。

如前所述,调节弹性的属性是m_restitution。这可以通过两种方式设置。第一种方法在问题帖中注明。另一种方式如下:

groundRigidBody->setRestitution(1.0);
ballRigidBody->setRestitution(1.0);

...它的工作原理。根据我在网上阅读的内容(例如here),两种方式都应该没问题,但就我而言,它只适用于第二种方式。我在 Ubuntu 上使用 bullet-2.82-r2704

这仅发生在 m_restitution 属性中,所有其他属性都按照我的问题发布方式设置好。

另外,dynamicsWorld->getSolverInfo().m_splitImpulse = false; 行不再需要了。

【讨论】:

    猜你喜欢
    • 2014-08-18
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 2015-02-27
    • 1970-01-01
    • 2015-07-29
    • 1970-01-01
    相关资源
    最近更新 更多