本文整理汇总了C++中IActor::MustBreakGlass方法的典型用法代码示例。如果您正苦于以下问题:C++ IActor::MustBreakGlass方法的具体用法?C++ IActor::MustBreakGlass怎么用?C++ IActor::MustBreakGlass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IActor
的用法示例。
在下文中一共展示了IActor::MustBreakGlass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleImpact
//--------------------------------------------------------------------------------------------------
// Name: HandleImpact
// Desc: Passes an impact on to the simulation
//--------------------------------------------------------------------------------------------------
int CBreakableGlassSystem::HandleImpact(const EventPhys* pPhysEvent)
{
if (CCryAction* pCryAction = CCryAction::GetCryAction())
{
if (CBreakableGlassSystem* pGlassSystem = static_cast<CBreakableGlassSystem*>(pCryAction->GetIBreakableGlassSystem()))
{
pGlassSystem->AssertUnusedIfDisabled();
if (pGlassSystem->m_enabled)
{
if (const EventPhysCollision* pCollEvent = static_cast<const EventPhysCollision*>(pPhysEvent))
{
// Glass fragments always get destroyed on their first collision
const uint physFrag = (pCollEvent->iForeignData[0] == PHYS_FOREIGN_ID_BREAKABLE_GLASS_FRAGMENT) ? 0 : 1;
IPhysicalEntity* pPhysEnt = pCollEvent->pEntity[physFrag];
if (pPhysEnt && pCollEvent->iForeignData[physFrag] == PHYS_FOREIGN_ID_BREAKABLE_GLASS_FRAGMENT)
{
// Fragments only collide with non-glass geometry
const int nonFragType = pCollEvent->iForeignData[1-physFrag];
if (nonFragType != PHYS_FOREIGN_ID_BREAKABLE_GLASS
&& nonFragType != PHYS_FOREIGN_ID_BREAKABLE_GLASS_FRAGMENT
&& nonFragType != PHYS_FOREIGN_ID_ENTITY) // Only break on floors, walls, etc.
{
// Verify parent glass node, then allow it to handle impact
if (SGlassPhysFragment* pPhysFrag = (SGlassPhysFragment*)pCollEvent->pForeignData[physFrag])
{
if (IBreakableGlassRenderNode* pRenderNode = (IBreakableGlassRenderNode*)pPhysFrag->m_pRenderNode)
{
pRenderNode->DestroyPhysFragment(pPhysFrag);
}
}
}
}
else if (pCollEvent->iForeignData[PHYSEVENT_COLLIDEE] == PHYS_FOREIGN_ID_BREAKABLE_GLASS)
{
// Get breakable glass data
PodArray<IBreakableGlassRenderNode*>& glassPlanes = pGlassSystem->m_glassPlanes;
const int numPlanes = glassPlanes.Count();
// Duplicate event so we can freely manipulate it
EventPhysCollision dupeEvent = *pCollEvent;
const EventPhysCollision* pDupeEvent = (const EventPhysCollision*)&dupeEvent;
// Some actors can force breaks for gameplay reasons
IPhysicalEntity* pCollider = dupeEvent.pEntity[PHYSEVENT_COLLIDER];
if (pCollider && pCollider->GetType() == PE_LIVING)
{
IEntity* pColliderEntity = (IEntity*)pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY);
IActor* pActor = pColliderEntity ? gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pColliderEntity->GetId()) : NULL;
if (pActor && pActor->MustBreakGlass())
{
pGlassSystem->ModifyEventToForceBreak(&dupeEvent);
}
}
// Verify glass node and pass impact through
IBreakableGlassRenderNode* pRenderNode = (IBreakableGlassRenderNode*)pCollEvent->pForeignData[PHYSEVENT_COLLIDEE];
const int targetId = pRenderNode ? pRenderNode->GetId() : numPlanes;
if (targetId < numPlanes && pRenderNode == glassPlanes[targetId])
{
pGlassSystem->PassImpactToNode(pRenderNode, pDupeEvent);
}
}
}
}
}
}
return 1; // Pass event to other handlers even if we processed it
}//-------------------------------------------------------------------------------------------------