void SetTransform(const Transformation& t){ Mat44 mat4; t.GetHomogeneous(mat4); auto aT = FBToBullet(mat4); mSelf->setWorldTransform(aT); auto numConstraints = mSelf->getNumConstraintRefs(); for (int i = 0; i < numConstraints; ++i){ auto con = mSelf->getConstraintRef(i); if (con->isEnabled() && con->getConstraintType() == D6_SPRING_2_CONSTRAINT_TYPE){ btFixedConstraint* fixedCon = (btFixedConstraint*)con; auto a = &con->getRigidBodyA(); auto b = &con->getRigidBodyB(); auto trA = fixedCon->getFrameOffsetA(); auto trB = fixedCon->getFrameOffsetB(); if (b->getUserPointer() == mSelf){ std::swap(a, b); std::swap(trA, trB); } auto bT = aT * trA * trB.inverse(); b->setWorldTransform(bT); auto ms = b->getMotionState(); if (ms) ms->setWorldTransform(bT); } } mSelf->activate(); }
void RemoveConstraints(){ while (mSelf->getNumConstraintRefs()>0) { btTypedConstraint* pConstraint = mSelf->getConstraintRef(0); Physics::GetInstance().RemoveConstraint(pConstraint); } }
void SetTransform(const btTransform& aT, VectorMap<void*, int>& set){ if (set.Find(mSelf) != set.end()) return; mSelf->setWorldTransform(aT); mSelf->clearForces(); set[mSelf] = 1; if (mGameFlag != 0) Logger::Log(FB_DEFAULT_LOG_ARG, FormatString("(info) Setting rigid body transform for %d", mGameFlag).c_str()); auto numConstraints = mSelf->getNumConstraintRefs(); for (int i = 0; i < numConstraints; ++i){ auto con = mSelf->getConstraintRef(i); auto conType = con->getConstraintType(); if (conType == FIXED_CONSTRAINT_TYPE || conType == D6_SPRING_2_CONSTRAINT_TYPE){ btFixedConstraint* fixedCon = (btFixedConstraint*)con; auto a = &con->getRigidBodyA(); auto b = &con->getRigidBodyB(); auto trA = fixedCon->getFrameOffsetA(); auto trB = fixedCon->getFrameOffsetB(); if (b->getUserPointer() == mSelf){ std::swap(a, b); std::swap(trA, trB); } auto bT = aT * trA * trB.inverse(); auto rigidBodyImpl = (RigidBodyImpl*)b->getUserPointer(); rigidBodyImpl->mImpl->SetTransform(bT, set); } } mSelf->activate(); }
void RemoveConstraint(void* constraintPtr){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ++i){ btTypedConstraint* pConstraint = mSelf->getConstraintRef(i); if (pConstraint == constraintPtr){ Physics::GetInstance().RemoveConstraint(pConstraint); break; } } }
void UnregisterFromWorld(){ if (mWorld){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ++i){ auto constraint = mSelf->getConstraintRef(i); assert(constraint); constraint->setEnabled(false); } mWorld->removeRigidBody(mSelf); mAddedToWorld = false; } }
void RemoveConstraintsFor(void* gamePtr){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ){ btTypedConstraint* pConstraint = mSelf->getConstraintRef(i); if (pConstraint->getRigidBodyA().getUserPointer() == pConstraint->getRigidBodyB().getUserPointer()){ Physics::GetInstance().RemoveConstraint(pConstraint); } else{ ++i; } } }
void UnregisterFromWorld(){ if (mWorld){ auto num = mSelf->getNumConstraintRefs(); for (int i = 0; i < num; ++i){ auto constraint = mSelf->getConstraintRef(i); assert(constraint); constraint->setEnabled(false); } mWorld->removeRigidBody(mSelf); mAddedToWorld = false; } else Logger::Log(FB_ERROR_LOG_ARG, "No colprovier exists!"); }
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!"); }
void* GetLastConstraintsPtr(){ auto num = mSelf->getNumConstraintRefs(); if (num == 0) return 0; return mSelf->getConstraintRef(num - 1); }