本文整理汇总了C++中PhysicsComponent::getTransform方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsComponent::getTransform方法的具体用法?C++ PhysicsComponent::getTransform怎么用?C++ PhysicsComponent::getTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsComponent
的用法示例。
在下文中一共展示了PhysicsComponent::getTransform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnHierarchyChange
void PhysicsComponent::OnHierarchyChange()
{
// Clear out old data
if(absoluteCShape != nullptr)
delete absoluteCShape;
absoluteMass = mass;
if(children.size() == 0)
{
absoluteCOG = cog;
absoluteCShape = cShape;
}
else
{
btCompoundShape* compAbsShape = new btCompoundShape();
absoluteCShape = compAbsShape;
compAbsShape->addChildShape(btTransform(), cShape);
for(auto it = children.begin(); it != children.end(); ++it)
{
PhysicsComponent* curr = static_cast<PhysicsComponent*>(*it);
compAbsShape->addChildShape(curr->getTransform(), curr->absoluteCShape);
absoluteMass += curr->absoluteMass;
}
absoluteCOG.setValue(0.0f, 0.0f, 0.0f);
absoluteCOG += cog * (mass / absoluteMass);
for(auto it = children.begin(); it != children.end(); ++it)
{
PhysicsComponent* curr = static_cast<PhysicsComponent*>(*it);
absoluteCOG += curr->cog
* (curr->absoluteMass / absoluteMass);
}
}
// Allow collision shape to be traced back to us
absoluteCShape->setUserPointer(owner);
// Only entities with no parents should have rigid bodies.
if(parent == nullptr)
{
//TODO: Update body mass and possibly motionstate
// If the body already exists, this entity was already a parent
// beforehand. We just need to update it's collision shape
// with the new absolute shape.
if(body != nullptr)
{
body->setCollisionShape(absoluteCShape);
body->setMassProps(absoluteMass, btVector3());
}
// Otherwise we need to instantiate a new rigid body and register
// it with the physics world.
else
{
btRigidBody::btRigidBodyConstructionInfo ci(absoluteMass, nullptr,
absoluteCShape);
body = new btRigidBody(ci);
}
// Set new center of gravity
btTransform comTrans;
comTrans.setOrigin(absoluteCOG);
body->setCenterOfMassTransform(comTrans);
}
// If the entitiy is no longer a parent, remove it from the world
else if(body != nullptr)
{
physMan->GetWorld()->removeRigidBody(body);
delete body;
body = nullptr;
}
// There is no else. Child objects do not get their own rigid body
}