virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: if (IsPortActive(pActInfo, EIP_Trigger)) { const Vec3& dir = GetPortVec3(pActInfo, EIP_LimitDir); const bool localSpace = GetPortBool(pActInfo, EIP_LocalSpace); const float rangeH = GetPortFloat(pActInfo, EIP_LimitYaw); const float rangeV = GetPortFloat(pActInfo, EIP_LimitPitch); CActor *pPlayerActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor()); if (pPlayerActor) { CPlayer::SStagingParams stagingParams; CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor); if (dir.len2()>0.01f) { if (localSpace) { const Quat& viewQuat = pPlayer->GetViewQuatFinal(); // WC Vec3 dirWC = viewQuat * dir; stagingParams.vLimitDir = dirWC.GetNormalizedSafe(ZERO); } else stagingParams.vLimitDir = dir.GetNormalizedSafe(ZERO); } stagingParams.vLimitRangeH = DEG2RAD(rangeH); stagingParams.vLimitRangeV = DEG2RAD(rangeV); stagingParams.bLocked = GetPortBool(pActInfo, EIP_Lock); int stance = GetPortInt(pActInfo, EIP_Stance); if (stance < STANCE_NULL || stance >= STANCE_LAST) { stance = STANCE_NULL; GameWarning("[flow] PlayerStaging: stance=%d invalid", stance); } stagingParams.stance = (EStance) stance; bool bActive = (stagingParams.bLocked || (!stagingParams.vLimitDir.IsZero() && !iszero(stagingParams.vLimitRangeH) && !iszero(stagingParams.vLimitRangeV)) ); pPlayer->StagePlayer(bActive, &stagingParams); /* SActorParams* pActorParams = pPlayerActor->GetActorParams(); if (pActorParams) { CPlayer* pPlayer = static_cast<CPlayer*> (pPlayerActor); if (dir.len2()>0.01f) { if (localSpace) { const Quat& viewQuat = pPlayer->GetViewQuatFinal(); // WC Vec3 dirWC = viewQuat * dir; pActorParams->vLimitDir = dirWC.GetNormalizedSafe(ZERO); } else pActorParams->vLimitDir = dir.GetNormalizedSafe(ZERO); } else pActorParams->vLimitDir.zero(); pActorParams->vLimitRangeH = DEG2RAD(rangeH); pActorParams->vLimitRangeV = DEG2RAD(rangeV); const bool bLock = GetPortBool(pActInfo, EIP_Lock); // AlexL 23/01/2007: disable this until we have a working solution to lock player movement (action filter) // SPlayerStats* pActorStats = static_cast<SPlayerStats*> (pPlayer->GetActorStats()); // if (pActorStats) // pActorStats->spectatorMode = bLock ? CActor::eASM_Cutscene : 0; IActionMapManager* pAmMgr = g_pGame->GetIGameFramework()->GetIActionMapManager(); if (pAmMgr) pAmMgr->EnableFilter("no_move", bLock); if (bLock) { // CPlayerMovementController* pMC = static_cast<CPlayerMovementController*> (pPlayer->GetMovementController()); // pMC->Reset(); if(pPlayer->GetPlayerInput()) pPlayer->GetPlayerInput()->Reset(); } } */ } ActivateOutput(pActInfo, EOP_Done, false); } break; } }
virtual void ProcessEvent( EFlowEvent event,SActivationInfo *pActInfo ) { if (event != eFE_Activate) return; if (!InputEntityIsLocalPlayer( pActInfo )) return; const bool bTriggered = IsPortActive(pActInfo, EIP_Trigger); const bool bFreqTriggered = IsPortActive(pActInfo, EIP_Frequency); if (bTriggered == false && bFreqTriggered == false) return; IGameFramework* pGF = gEnv->pGame->GetIGameFramework(); IView* pView = 0; IView* pActiveView = pGF->GetIViewSystem()->GetActiveView(); int viewType = GetPortInt(pActInfo, EIP_ViewType); if (viewType == VT_FirstPerson) // use player's view { IActor* pActor = pGF->GetClientActor(); if (pActor == 0) return; const int restriction = GetPortInt(pActInfo, EIP_Restriction); if (restriction != ER_None) { IVehicle* pVehicle = pActor->GetLinkedVehicle(); if (restriction == ER_InVehicle && pVehicle == 0) return; if (restriction == ER_NoVehicle && pVehicle != 0 /* && pVehicle->GetSeatForPassenger(entityId) != 0 */) return; } EntityId entityId = pActor->GetEntityId(); pView = pGF->GetIViewSystem()->GetViewByEntityId(entityId); } else // active view { pView = pActiveView; } if (pView == 0 || pView != pActiveView) return; const bool bGroundOnly = GetPortBool(pActInfo, EIP_GroundOnly); Ang3 angles = Ang3(DEG2RAD(GetPortVec3(pActInfo, EIP_Angle))); Vec3 shift = GetPortVec3(pActInfo, EIP_Shift); const float duration = GetPortFloat(pActInfo, EIP_Duration); float freq = GetPortFloat(pActInfo, EIP_Frequency); if (iszero(freq) == false) freq = 1.0f / freq; const float randomness = GetPortFloat(pActInfo, EIP_Randomness); static const bool bFlip = true; // GetPortBool(pActInfo, EIP_Flip); const bool bUpdateOnly = !bTriggered && bFreqTriggered; // it's an update if and only if Frequency has been changed const float distance = GetPortFloat(pActInfo, EIP_Distance); const float rangeMin = GetPortFloat(pActInfo, EIP_RangeMin); const float rangeMax = GetPortFloat(pActInfo, EIP_RangeMax); float amount = min(1.f, max(0.f, (rangeMax-distance) / (rangeMax-rangeMin) )); angles *= amount; shift *= amount; pView->SetViewShake(angles, shift, duration, freq, randomness, FLOWGRAPH_SHAKE_ID, bFlip, bUpdateOnly, bGroundOnly); }
virtual void ProcessEvent( EFlowEvent event,SActivationInfo* pActInfo ) { switch (event) { case eFE_Activate: { m_lastTime = gEnv->pTimer->GetFrameStartTime(); m_bActive = !GetPortBool(pActInfo, 1); pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, m_bActive ); if (!m_bActive) { ResetVelocity(pActInfo); } } break; case eFE_Initialize: { if (pActInfo->pEntity) m_localRot = pActInfo->pEntity->GetRotation(); else m_localRot.SetIdentity(); m_worldRot.SetIdentity(); m_lastTime = gEnv->pTimer->GetFrameStartTime(); m_bActive = !GetPortBool(pActInfo, 1); pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, m_bActive ); break; } case eFE_Update: { if (m_bActive && pActInfo->pEntity) { CTimeValue time = gEnv->pTimer->GetFrameStartTime(); float timeDifference = (time - m_lastTime).GetSeconds(); m_lastTime = time; IEntity* pEntity = pActInfo->pEntity; const bool bUseWorld = GetPortInt(pActInfo, 2) == 0 ? true : false; Vec3 speed = GetPortVec3(pActInfo, 0); speed *= timeDifference; Quat deltaRot (Ang3(DEG2RAD(speed))); Quat finalRot; if (bUseWorld == false) { finalRot = pEntity->GetRotation(); finalRot *= deltaRot; } else { m_worldRot *= deltaRot; finalRot = m_worldRot; finalRot *= m_localRot; } finalRot.NormalizeSafe(); IPhysicalEntity* piPhysEnt = pEntity->GetPhysics(); if (piPhysEnt && piPhysEnt->GetType() != PE_STATIC) { if (timeDifference > 0.0001f) { pe_action_set_velocity asv; asv.w = Quat::log(deltaRot) * (2.f / timeDifference); asv.bRotationAroundPivot = 1; pEntity->GetPhysics()->Action(&asv); } } else { pEntity->SetRotation(finalRot); } Ang3 currentAng = Ang3(finalRot); ActivateOutput(pActInfo, 1, Vec3(currentAng)); currentAng = RAD2DEG(currentAng); ActivateOutput(pActInfo, 0, Vec3(currentAng)); } break; } } }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: IGameFramework* pGameFramework = gEnv->pGame->GetIGameFramework(); if(IsPortActive(pActInfo, EIP_Cast)) { // setup ray + optionally skip 1 entity ray_hit rayHit; static const float maxRayDist = 100.f; const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any; IPhysicalEntity *skipList[1]; int skipCount = 0; IEntity* skipEntity = gEnv->pEntitySystem->GetEntity(GetPortEntityId(pActInfo, EIP_SkipEntity)); if(skipEntity) { skipList[0] = skipEntity->GetPhysics(); skipCount = 1; } Vec3 rayPos = GetPortVec3(pActInfo, EIP_RayPos); Vec3 rayDir = GetPortVec3(pActInfo, EIP_RayDir); // Check if the ray hits an entity if(gEnv->pSystem->GetIPhysicalWorld()->RayWorldIntersection(rayPos, rayDir * 100, ent_all, flags, &rayHit, 1, skipList, skipCount)) { int type = rayHit.pCollider->GetiForeignData(); if (type == PHYS_FOREIGN_ID_ENTITY) { IEntity* pEntity = (IEntity*)rayHit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY); IEntityRenderProxy* pRenderProxy = pEntity ? (IEntityRenderProxy*)pEntity->GetProxy(ENTITY_PROXY_RENDER) : 0; // Get the renderproxy, and use it to check if the material is a DynTex, and get the UIElement if so if(pRenderProxy) { IRenderNode *pRenderNode = pRenderProxy->GetRenderNode(); IMaterial* pMaterial = pRenderProxy->GetRenderMaterial(); SEfResTexture* texture = 0; if(pMaterial && pMaterial->GetShaderItem().m_pShaderResources) texture= pMaterial->GetShaderItem().m_pShaderResources->GetTexture(EFTT_DIFFUSE); IUIElement* pElement = texture ? gEnv->pFlashUI->GetUIElementByInstanceStr(texture->m_Name) : 0; if(pElement && pRenderNode) { int m_dynTexGeomSlot = 0; IStatObj* pObj = pRenderNode->GetEntityStatObj(m_dynTexGeomSlot); // result bool hasHit = false; Vec2 uv0, uv1, uv2; Vec3 p0, p1, p2; Vec3 hitpos; // calculate ray dir CCamera cam = gEnv->pRenderer->GetCamera(); if (pEntity->GetSlotFlags(m_dynTexGeomSlot) & ENTITY_SLOT_RENDER_NEAREST) { ICVar *r_drawnearfov = gEnv->pConsole->GetCVar("r_DrawNearFoV"); assert(r_drawnearfov); cam.SetFrustum(cam.GetViewSurfaceX(),cam.GetViewSurfaceZ(),DEG2RAD(r_drawnearfov->GetFVal()),cam.GetNearPlane(),cam.GetFarPlane(), cam.GetPixelAspectRatio()); } Vec3 vPos0 = rayPos; Vec3 vPos1 = rayPos + rayDir; // translate into object space const Matrix34 m = pEntity->GetWorldTM().GetInverted(); vPos0 = m * vPos0; vPos1 = m * vPos1; // walk through all sub objects const int objCount = pObj->GetSubObjectCount(); for (int obj = 0; obj <= objCount && !hasHit; ++obj) { Vec3 vP0, vP1; IStatObj* pSubObj = NULL; if (obj == objCount) { vP0 = vPos0; vP1 = vPos1; pSubObj = pObj; } else { IStatObj::SSubObject* pSub = pObj->GetSubObject(obj); const Matrix34 mm = pSub->tm.GetInverted(); vP0 = mm * vPos0; vP1 = mm * vPos1; pSubObj = pSub->pStatObj; } IRenderMesh* pMesh = pSubObj ? pSubObj->GetRenderMesh() : NULL; if (pMesh) { const Ray ray(vP0, (vP1-vP0).GetNormalized() * maxRayDist); hasHit = RayIntersectMesh(pMesh, pMaterial, pElement, ray, hitpos, p0, p1, p2, uv0, uv1, uv2); } } // skip if not hit if (!hasHit) { ActivateOutput(pActInfo, EOP_Failed, 1); return; } // calculate vectors from hitpos to vertices p0, p1 and p2: const Vec3 v0 = p0-hitpos; const Vec3 v1 = p1-hitpos; const Vec3 v2 = p2-hitpos; // calculate factors const float h = (p0-p1).Cross(p0-p2).GetLength(); const float f0 = v1.Cross(v2).GetLength() / h; const float f1 = v2.Cross(v0).GetLength() / h; const float f2 = v0.Cross(v1).GetLength() / h; // find the uv corresponding to hitpos Vec3 uv = uv0 * f0 + uv1 * f1 + uv2 * f2; // translate to flash space int x, y, width, height; float aspect; pElement->GetFlashPlayer()->GetViewport(x, y, width, height, aspect); int iX = int_round(uv.x * (float)width); int iY = int_round(uv.y * (float)height); // call the function provided if it is present in the UIElement description string funcName = GetPortString(pActInfo, EIP_CallFunction); const SUIEventDesc* eventDesc = pElement->GetFunctionDesc(funcName); if(eventDesc) { SUIArguments arg; arg.AddArgument(iX); arg.AddArgument(iY); pElement->CallFunction(eventDesc->sName, arg); } ActivateOutput(pActInfo, EOP_Success, 1); } } } } ActivateOutput(pActInfo, EOP_Failed, 1); } break; } }
void CFlowSetupModelPostRender::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: if (IsPortActive(pActInfo, IN_SHUTDOWN)) { CMenuRender3DModelMgr::Release(true); ITexture *tex = NULL; //unbind tex from MC if(gEnv->pConsole->GetCVar("r_UsePersistentRTForModelHUD")->GetIVal() > 0) tex = gEnv->pRenderer->EF_LoadTexture("$ModelHUD"); else tex = gEnv->pRenderer->EF_LoadTexture("$BackBuffer"); IUIElement* pElement = gEnv->pFlashUI->GetUIElement(sUIElement.c_str()); IUIElement* pUIElement = pElement ? pElement->GetInstance(0) : NULL; if(pUIElement) pUIElement->UnloadTexFromMc(sMovieClipName.c_str(), tex); return; } if (IsPortActive(pActInfo, IN_START)) { INDENT_LOG_DURING_SCOPE(); // Setup scene settings CMenuRender3DModelMgr::SSceneSettings sceneSettings; sceneSettings.fovScale = 0.85f; sceneSettings.fadeInSpeed = 0.01f; sceneSettings.flashEdgeFadeScale = 0.0f; sceneSettings.ambientLight = Vec4(GetPortVec3(pActInfo, IN_AMBIENTLIGHTCOLOR), GetPortFloat(pActInfo, IN_AMBIENTLIGHTSTRENGTH)); sceneSettings.lights.resize(3); sceneSettings.lights[0].pos.Set(-25.f, -10.f, 30.f); sceneSettings.lights[0].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR1); sceneSettings.lights[0].specular = 4.f; sceneSettings.lights[0].radius = 400.f; sceneSettings.lights[1].pos.Set(25.f, -4.f, 30.f); sceneSettings.lights[1].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR2); sceneSettings.lights[1].specular = 10.f; sceneSettings.lights[1].radius = 400.f; sceneSettings.lights[2].pos.Set(60.f, 40.f, 10.f); sceneSettings.lights[2].color = GetPortVec3(pActInfo, IN_LIGHTCOLOR3); sceneSettings.lights[2].specular = 10.f; sceneSettings.lights[2].radius = 400.f; //Create scene CMenuRender3DModelMgr *renderModels = new CMenuRender3DModelMgr(); renderModels->SetSceneSettings(sceneSettings); ITexture *tex = NULL; //Fetch texture and send to movieclip if(gEnv->pConsole->GetCVar("r_UsePersistentRTForModelHUD")->GetIVal() > 0) tex = gEnv->pRenderer->EF_LoadTexture("$ModelHUD"); else tex = gEnv->pRenderer->EF_LoadTexture("$BackBuffer"); string sStr = GetPortString(pActInfo, IN_MC); string::size_type sPos = sStr.find( ':' ); sUIElement = sStr.substr( 0, sPos ); sMovieClipName = sStr.substr( sPos + 1 ); IUIElement* pElement = gEnv->pFlashUI->GetUIElement(sUIElement.c_str()); IUIElement* pUIElement = pElement ? pElement->GetInstance(0) : NULL; if(pUIElement) pUIElement->LoadTexIntoMc(sMovieClipName.c_str(), tex); else CryWarning(VALIDATOR_MODULE_FLOWGRAPH, VALIDATOR_WARNING, "CFlowAdd3DModelToHUD: Movieclip not found"); //check debug info float debugscale = GetPortFloat(pActInfo, IN_DEBUGSCALE); ICVar* cv_debugRender = gEnv->pConsole->GetCVar("g_post3DRendererDebug"); if(debugscale > 0.0f) { if(cv_debugRender) { cv_debugRender->Set(2); CMenuRender3DModelMgr::GetInstance()->SetDebugScale(debugscale); } } else { cv_debugRender->Set(0); } } break; } }