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


C++ IActor::MustBreakGlass方法代码示例

本文整理汇总了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
}//------------------------------------------------------------------------------------------------- 
开发者ID:aronarts,项目名称:FireNET,代码行数:79,代码来源:BreakableGlassSystem.cpp


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