本文整理汇总了C++中PhysicsObject::getLinearVelocity方法的典型用法代码示例。如果您正苦于以下问题:C++ PhysicsObject::getLinearVelocity方法的具体用法?C++ PhysicsObject::getLinearVelocity怎么用?C++ PhysicsObject::getLinearVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsObject
的用法示例。
在下文中一共展示了PhysicsObject::getLinearVelocity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEvent
void PhysicsComponent::onEvent(Event* e)
{
EventType type = e->getType();
switch(type)
{
case EVENT_ATTRIBUTE_UPDATED: //Removes physics objects when the corresponding physics attribute is removed
{
Event_AttributeUpdated* attributeUpdated = static_cast<Event_AttributeUpdated*>(e);
int attributeIndex = attributeUpdated->index;
if(attributeUpdated->attributeEnum == ATTRIBUTE_PHYSICS)
{
if(attributeUpdated->isDeleted)
{
if(attributeIndex < physicsObjects_->size() && physicsObjects_->at(attributeIndex) != nullptr)
{
dynamicsWorld_->removeRigidBody(physicsObjects_->at(attributeIndex));
delete physicsObjects_->at(attributeIndex);
physicsObjects_->at(attributeIndex) = nullptr;
}
else
{
DEBUGPRINT("Mismatch when synchronizing deletion of physics objects with physics attributes");
}
}
else if(attributeUpdated->isCreated)
{
}
else
{
itrPhysics.at(attributeIndex)->reloadDataIntoBulletPhysics = true;
}
}
/*else if(attributeUpdated->attributeEnum == ATTRIBUTE_CAMERA)
{
if(attributeUpdated->isDeleted)
{
dynamicsWorld_->removeRigidBody(frustumPhysicsObjects_->at(attributeIndex));
delete frustumPhysicsObjects_->at(attributeIndex);
frustumPhysicsObjects_->at(attributeIndex) = nullptr;
}
}*/
break;
}
case EVENT_MODIFY_PHYSICS_OBJECT:
{
Event_ModifyPhysicsObject* modifyPhysicsObject = static_cast<Event_ModifyPhysicsObject*>(e);
int physicsAttributeIndex = modifyPhysicsObject->ptr_physics.index();
if(physicsAttributeIndex < physicsObjects_->size() && physicsAttributeIndex > -1)
{
PhysicsObject* physicsObject = physicsObjects_->at(physicsAttributeIndex);
if(physicsObject != NULL)
{
//Cast void pointer sent in Event_ModifyPhysicsObject to its expected data type and modify physics object accordingly
switch(modifyPhysicsObject->modifyWhatDataInPhysicsObjectData)
{
case XKILL_Enums::ModifyPhysicsObjectData::GRAVITY:
{
Float3* gravity = static_cast<Float3*>(modifyPhysicsObject->data);
physicsObject->setGravity(btVector3(gravity->x, gravity->y, gravity->z));
break;
}
case XKILL_Enums::ModifyPhysicsObjectData::VELOCITY:
{
Float3* velocity = static_cast<Float3*>(modifyPhysicsObject->data);
physicsObject->setLinearVelocity(btVector3(velocity->x, velocity->y, velocity->z));
break;
}
case XKILL_Enums::ModifyPhysicsObjectData::VELOCITYPERCENTAGE:
{
Float3* velocityPercentage = static_cast<Float3*>(modifyPhysicsObject->data);
btVector3 currentLinearVelocity = physicsObject->getLinearVelocity();
physicsObject->setLinearVelocity(btVector3(currentLinearVelocity.x()*velocityPercentage->x, currentLinearVelocity.y()*velocityPercentage->y, currentLinearVelocity.z()*velocityPercentage->z));
break;
}
case XKILL_Enums::ModifyPhysicsObjectData::FLAG_STATIC:
{
bool* staticPhysicsObject = static_cast<bool*>(modifyPhysicsObject->data);
if(*staticPhysicsObject == true)
{
physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
}
else if(*staticPhysicsObject == false)
{
physicsObject->setCollisionFlags(physicsObject->getCollisionFlags() & ~ btCollisionObject::CF_STATIC_OBJECT);
}
break;
}
case XKILL_Enums::ModifyPhysicsObjectData::COLLISIONFILTERMASK:
{
/*In order to modify "collisionFilterMask", a physics objects needs to be removed from the Bullet Physics dynamics world and then readded using "addRigidBody", where "collisionFilterMask" is passed as argument.
Write physics object data to physics attribute, modify "collisionFilterMask", and set the "reloadDataIntoBulletPhysics" flag, and this class will handle the removal and addition of the physics object.*/
short* collisionFilterMaskFromEvent = static_cast<short*>(modifyPhysicsObject->data);
AttributePtr<Attribute_Physics> ptr_physics = itrPhysics.at(physicsAttributeIndex);
//.........这里部分代码省略.........