本文整理汇总了C++中PhysicsComponent::rigidBody方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsComponent::rigidBody方法的具体用法?C++ PhysicsComponent::rigidBody怎么用?C++ PhysicsComponent::rigidBody使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsComponent
的用法示例。
在下文中一共展示了PhysicsComponent::rigidBody方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFromXml
//.........这里部分代码省略.........
tr.setRotation(btQuaternion(r.x, r.y, r.z));
btMatrix3x3 rot = tr.getBasis();
XMLNode offsetXMLNode = description->getChildNode("Offset");
if (!offsetXMLNode.isEmpty()) {
lX = static_cast<float>(atof(offsetXMLNode.getAttribute("lX", "0.0")));
lY = static_cast<float>(atof(offsetXMLNode.getAttribute("lY", "0.0")));
lZ = static_cast<float>(atof(offsetXMLNode.getAttribute("lZ", "0.0")));
}
btVector3 offset = btVector3(lX * s.x, lY * s.y, lZ * s.z);
tr.setOrigin(btVector3(t.x, t.y, t.z) + rot * offset);
// Set local scaling in collision shape because Bullet does not support scaling in the world transformation matrices
m_collisionShape->setLocalScaling(btVector3(s.x, s.y, s.z));
btVector3 localInertia(0, 0, 0);
//rigidbody is dynamic if and only if mass is non zero otherwise static
if (mass != 0)
m_collisionShape->calculateLocalInertia(mass, localInertia);
if (mass != 0 || kinematic)
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
m_motionState = new btDefaultMotionState(tr);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, m_motionState, m_collisionShape, localInertia);
rbInfo.m_startWorldTransform = tr;
//rbInfo.m_restitution = btScalar( atof(description->getAttribute("restitution", "0")) );
//rbInfo.m_friction = btScalar( atof(description->getAttribute("static_friction", "0.5")) );
// Threshold for deactivation of objects (if movement is below this value the object gets deactivated)
//rbInfo.m_angularSleepingThreshold = 0.8f;
//rbInfo.m_linearSleepingThreshold = 0.8f;
m_rigidBody = new btRigidBody(rbInfo);
m_rigidBody->setUserPointer(this);
m_rigidBody->setDeactivationTime(2.0f);
// Add support for collision detection if mass is zero but kinematic is explicitly enabled
if (kinematic && mass == 0 && !nondynamic) {
m_rigidBody->setCollisionFlags(m_rigidBody->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
m_rigidBody->setActivationState(DISABLE_DEACTIVATION);
}
if (nondynamic && mass == 0) {
m_rigidBody->setCollisionFlags(m_rigidBody->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
}
bool isTrigger = _stricmp(description->getAttribute("solid", "true"), "false") == 0 || _stricmp(description->getAttribute("solid", "1"), "0") == 0;
if (isTrigger) {
setCollisionResponse(true);
}
GameLog::logMessage("I'm a new Physics body: %s my Motion state: %d", m_owner->id().c_str(), m_motionState);
printf("I'm a new Physics body: %s my Motion state: %d\n", m_owner->id().c_str(), m_motionState);
if(!ragdoll) Physics::instance()->addObject(this);
/*Geometry Proxy*/
XMLNode proxyXMLNode = description->getChildNode("Proxy");
if (proxyXMLNode.isEmpty())
return;
m_proxy = GameModules::gameWorld()->entity(proxyXMLNode.getAttribute("name", ""));
if (m_proxy) {
m_proxy->addListener(GameEvent::E_SET_TRANSFORMATION, this);
m_proxy->addListener(GameEvent::E_SET_TRANSLATION, this);