当前位置: 首页>>代码示例>>C++>>正文


C++ PhysicsComponent::rigidBody方法代码示例

本文整理汇总了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);
开发者ID:CZdravko,项目名称:Horde,代码行数:67,代码来源:PhysicsComponent.cpp


注:本文中的PhysicsComponent::rigidBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。