-1
我正在玩子彈,我有一個地面和一個球,我希望球落在地面上彈跳。然而,這並沒有發生,即使是非常高的值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;
只是說:讀代碼真的很痛苦,可以做些什麼來縮進它,並將其更好地分開? –
是的,現在我希望它更好。 –