Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
| Show First 20 Lines • Show All 3,352 Lines • ▼ Show 20 Lines | //bm->setMargin(ci.m_margin); | ||||
| if (isCompoundChild) | if (isCompoundChild) | ||||
| { | { | ||||
| //find parent, compound shape and add to it | //find parent, compound shape and add to it | ||||
| //take relative transform into account! | //take relative transform into account! | ||||
| CcdPhysicsController* parentCtrl = (CcdPhysicsController*)parent->GetPhysicsController(); | CcdPhysicsController* parentCtrl = (CcdPhysicsController*)parent->GetPhysicsController(); | ||||
| assert(parentCtrl); | assert(parentCtrl); | ||||
| // only makes compound shape if parent has a physics controller (i.e not an empty, etc) | |||||
| if (parentCtrl) { | |||||
| CcdShapeConstructionInfo* parentShapeInfo = parentCtrl->GetShapeInfo(); | CcdShapeConstructionInfo* parentShapeInfo = parentCtrl->GetShapeInfo(); | ||||
| btRigidBody* rigidbody = parentCtrl->GetRigidBody(); | btRigidBody* rigidbody = parentCtrl->GetRigidBody(); | ||||
| btCollisionShape* colShape = rigidbody->getCollisionShape(); | btCollisionShape* colShape = rigidbody->getCollisionShape(); | ||||
| assert(colShape->isCompound()); | assert(colShape->isCompound()); | ||||
| btCompoundShape* compoundShape = (btCompoundShape*)colShape; | btCompoundShape* compoundShape = (btCompoundShape*)colShape; | ||||
| // compute the local transform from parent, this may include several node in the chain | // compute the local transform from parent, this may include several node in the chain | ||||
| SG_Node* gameNode = gameobj->GetSGNode(); | SG_Node* gameNode = gameobj->GetSGNode(); | ||||
| SG_Node* parentNode = parent->GetSGNode(); | SG_Node* parentNode = parent->GetSGNode(); | ||||
| // relative transform | // relative transform | ||||
| MT_Vector3 parentScale = parentNode->GetWorldScaling(); | MT_Vector3 parentScale = parentNode->GetWorldScaling(); | ||||
| parentScale[0] = MT_Scalar(1.0)/parentScale[0]; | parentScale[0] = MT_Scalar(1.0)/parentScale[0]; | ||||
| parentScale[1] = MT_Scalar(1.0)/parentScale[1]; | parentScale[1] = MT_Scalar(1.0)/parentScale[1]; | ||||
| parentScale[2] = MT_Scalar(1.0)/parentScale[2]; | parentScale[2] = MT_Scalar(1.0)/parentScale[2]; | ||||
| MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale; | MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale; | ||||
| MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed(); | MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed(); | ||||
| MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale); | MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale); | ||||
| MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation(); | MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation(); | ||||
| shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]); | shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]); | ||||
| bm->setLocalScaling(shapeInfo->m_childScale); | bm->setLocalScaling(shapeInfo->m_childScale); | ||||
| shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]); | shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]); | ||||
| float rot[12]; | float rot[12]; | ||||
| relativeRot.getValue(rot); | relativeRot.getValue(rot); | ||||
| shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot); | shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot); | ||||
| parentShapeInfo->AddShape(shapeInfo); | parentShapeInfo->AddShape(shapeInfo); | ||||
| compoundShape->addChildShape(shapeInfo->m_childTrans,bm); | compoundShape->addChildShape(shapeInfo->m_childTrans,bm); | ||||
| //do some recalc? | //do some recalc? | ||||
| //recalc inertia for rigidbody | //recalc inertia for rigidbody | ||||
| if (!rigidbody->isStaticOrKinematicObject()) | if (!rigidbody->isStaticOrKinematicObject()) | ||||
| { | { | ||||
| btVector3 localInertia; | btVector3 localInertia; | ||||
| float mass = 1.f/rigidbody->getInvMass(); | float mass = 1.f/rigidbody->getInvMass(); | ||||
| compoundShape->calculateLocalInertia(mass,localInertia); | compoundShape->calculateLocalInertia(mass,localInertia); | ||||
| rigidbody->setMassProps(mass,localInertia); | rigidbody->setMassProps(mass,localInertia); | ||||
| } | } | ||||
| shapeInfo->Release(); | shapeInfo->Release(); | ||||
| // delete motionstate as it's not used | // delete motionstate as it's not used | ||||
| delete motionstate; | delete motionstate; | ||||
| } | |||||
| return; | return; | ||||
| } | } | ||||
| if (hasCompoundChildren) | if (hasCompoundChildren) | ||||
| { | { | ||||
| // create a compound shape info | // create a compound shape info | ||||
| CcdShapeConstructionInfo *compoundShapeInfo = new CcdShapeConstructionInfo(); | CcdShapeConstructionInfo *compoundShapeInfo = new CcdShapeConstructionInfo(); | ||||
| compoundShapeInfo->m_shapeType = PHY_SHAPE_COMPOUND; | compoundShapeInfo->m_shapeType = PHY_SHAPE_COMPOUND; | ||||
| ▲ Show 20 Lines • Show All 169 Lines • Show Last 20 Lines | |||||