void ModelPhysics::insert(ModelInstance & modelInst, f32 mass, f32 friction, vec3 linearFactor, vec3 angularFactor, u32 group, const ivec4 & mask03, const ivec4 & mask47) { if (mBodies.find(modelInst.model().uid()) == mBodies.end()) { ASSERT(modelInst.mHasBody == false); vec3 halfExtents = modelInst.model().gmdl().halfExtents(); auto colShapeIt = mCollisionShapes.find(halfExtents); btVector3 btExtents(halfExtents.x, halfExtents.y, halfExtents.z); btCollisionShape * pCollisionShape = nullptr; if (colShapeIt != mCollisionShapes.end()) pCollisionShape = colShapeIt->second.get(); else { auto empRes = mCollisionShapes.emplace(std::piecewise_construct, std::forward_as_tuple(halfExtents), std::forward_as_tuple(GNEW(kMEM_Physics, btBoxShape, btExtents))); pCollisionShape = empRes.first->second.get(); } ModelMotionState * pMotionState = GNEW(kMEM_Physics, ModelMotionState, modelInst); btRigidBody::btRigidBodyConstructionInfo constrInfo(mass, pMotionState, pCollisionShape); constrInfo.m_friction = friction; // constrInfo.m_angularDamping = 0.1; // constrInfo.m_localInertia = btExtents; ModelBody * pBody = GNEW(kMEM_Physics, ModelBody, pMotionState, group, constrInfo); mBodies.emplace(modelInst.model().uid(), pBody); pBody->setLinearFactor(btVector3(linearFactor.x, linearFactor.y, linearFactor.z)); pBody->setAngularFactor(btVector3(angularFactor.x, angularFactor.y, angularFactor.z)); if (group == 0) { mpDynamicsWorld->addRigidBody(pBody); } else { u16 groupMask = maskFromHash(group); u16 mask = buildMask(mask03, mask47); mpDynamicsWorld->addRigidBody(pBody, maskFromHash(group), buildMask(mask03, mask47)); } pBody->setGravity(btVector3(0,0,0)); } else { LOG_ERROR("ModelBody for %u already created", modelInst.model().uid()); } }
// ------------------------------------------------------------- void Mask::buildMask(BaseFab<int>& a_mask, const Box& a_dProblem, const BoxLayout& a_grids, const BoxLayout* a_fineGridsPtr, int a_nRefFine) { ProblemDomain physdomain(a_dProblem); buildMask(a_mask, physdomain, a_grids, a_fineGridsPtr, a_nRefFine); }
// ------------------------------------------------------------- void Mask::buildMasks(LevelData<BaseFab<int> >& a_masks, const ProblemDomain& a_dProblem, const BoxLayout& a_grids, const BoxLayout* a_fineGridsPtr, int a_nRefFine) { // simply iterate over boxes and call single-basefab function DataIterator dit = a_masks.dataIterator(); for (dit.reset(); dit.ok(); ++dit) { buildMask(a_masks[dit()], a_dProblem, a_grids, a_fineGridsPtr, a_nRefFine); } }