void addPickingConstraint(const btVector3& rayFrom, const btVector3& rayTo) { if (!dynamicsWorld) { return; } removePickingConstraint(); if (pickedObjectIndex <= 0 || pickedObjectIndex >= dynamicsWorld->getNumCollisionObjects()) { return; } pickedBody = btRigidBody::upcast(dynamicsWorld->getCollisionObjectArray()[pickedObjectIndex]); btVector3 pickPos = rayTo; btVector3 localPivot = pickedBody->getCenterOfMassTransform().inverse() * pickPos; pickConstraint = new btPoint2PointConstraint(*pickedBody,localPivot); pickedBody->setActivationState(DISABLE_DEACTIVATION); dynamicsWorld->addConstraint(pickConstraint,true); pickingDistance = (rayFrom-rayTo).length(); pickConstraint->m_setting.m_impulseClamp = 3.0f; pickConstraint->m_setting.m_tau = 0.001f; }
void EmptyScene() { if (dynamicsWorld) { int i; for (i=dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--) { btCollisionObject* obj = dynamicsWorld->getCollisionObjectArray()[i]; btRigidBody* body = btRigidBody::upcast(obj); if (body && body->getMotionState()) { delete body->getMotionState(); } dynamicsWorld->removeCollisionObject(obj); delete obj; } removePickingConstraint(); } if (dynamicsWorld) { delete dynamicsWorld; dynamicsWorld = NULL; } if (solver) { delete solver; solver = NULL; } if (broadphase) { delete broadphase; broadphase = NULL; } if (dispatcher) { delete dispatcher; dispatcher = NULL; } if (collisionConfiguration) { delete collisionConfiguration; collisionConfiguration = NULL; } // Delete shapes std::map<std::string, btCollisionShape*>::iterator it = shapes.begin(); while (it != shapes.end()) { delete (*it).second; it++; } shapes.clear(); // Clear name table objectNames.clear(); }