//------------------------------------------------------------------------ IMPLEMENT_RMI(CC4Projectile, ClSetPosition) { Matrix34 mat; mat.SetRotation33(Matrix33(params.rot)); mat.SetTranslation(params.pos); GetEntity()->SetWorldTM(mat); m_stuck = true; return true; }
//------------------------------------------------------------------------- IMPLEMENT_RMI(CC4Projectile, ClStickToEntity) { if(IEntity *pEntity = gEnv->pEntitySystem->GetEntity(params.targetId)) { Matrix34 localMatrix; localMatrix.SetRotation33(Matrix33(params.localRotation)); localMatrix.SetTranslation(params.localCollisonPos); StickToEntity(pEntity,localMatrix); } return true; }
void CBurnEffectManager::SpawnImpactEffect(const EventPhysCollision& pCollision, const char* effectName) { Vec3 surfaceNormal = pCollision.n; Vec3 surfacePosition = pCollision.pt; CItemParticleEffectCache& particleCache = g_pGame->GetGameSharedParametersStorage()->GetItemResourceCache().GetParticleEffectCache(); IParticleEffect* pParticleEffect = particleCache.GetCachedParticle(effectName); if (pParticleEffect) { Matrix34 loc; loc.SetIdentity(); loc.SetTranslation(surfacePosition); loc.SetRotation33(OrthoNormalVector(surfaceNormal)); pParticleEffect->Spawn(false, loc); } }
void CStickyProjectile::NetSetStuck(CProjectile* pProjectile, bool stuck) { if(stuck && ((m_flags&eSF_IsStuck)==0)) { IEntity* pTargetEntity = gEnv->pEntitySystem->GetEntity(m_parentId); if(pTargetEntity) { if(ICharacterInstance* pTargetCharacter = pTargetEntity->GetCharacter(0)) { const char* boneName = pTargetCharacter->GetICharacterModel()->GetICharacterModelSkeleton()->GetJointNameByID(m_stuckJoint); if(AttachToCharacter(pProjectile, *pTargetEntity, *pTargetCharacter, boneName)) { IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTargetEntity->GetId()); m_flags |= eSF_IsStuck; m_flags |= pActor ? pActor->IsPlayer() ? eSF_StuckToPlayer : eSF_StuckToAI : 0; m_childId = pProjectile->GetEntityId(); } } } if((m_flags&eSF_IsStuck)==0) { IEntity* pProjectileEntity = pProjectile->GetEntity(); AttachTo(pProjectile, pTargetEntity); m_childId = pProjectileEntity->GetId(); if(pTargetEntity) //If we have a parent then the stuck position/rotation are local to the parent { pProjectileEntity->SetPos(m_stuckPos); pProjectileEntity->SetRotation(m_stuckRot); } else if(m_flags&eSF_OrientateToCollNormal) { Matrix34 mat; mat.SetTranslation(m_stuckPos); mat.SetRotation33(Matrix33(m_stuckRot)); pProjectileEntity->SetWorldTM(mat); } else { pProjectileEntity->SetPos(m_stuckPos); } m_flags |= eSF_IsStuck; } } }
//--------------------------------------------------------------------- //This function is only executed on the server void CC4Projectile::StickToStaticObject(EventPhysCollision *pCollision, IPhysicalEntity *pTarget) { //Calculate new position and orientation Matrix34 mat; Vec3 pos = pCollision->pt+(pCollision->n*0.05f); mat.SetRotation33(Matrix33::CreateOrientation(-pCollision->n,GetEntity()->GetWorldTM().TransformVector(Vec3(0,0,1)),gf_PI)); Vec3 newUpDir = mat.TransformVector(Vec3(0,0,1)); pos += (newUpDir*-0.1f); mat.SetTranslation(pos+(newUpDir*-0.1f)); GetEntity()->SetWorldTM(mat); GetGameObject()->SetAspectProfile(eEA_Physics, ePT_Static); pos = mat.GetTranslation(); Quat rot = GetEntity()->GetWorldRotation(); if(gEnv->bMultiplayer) GetGameObject()->InvokeRMI(CC4Projectile::ClSetPosition(),ProjectileStaticParams(pos,rot),eRMI_ToAllClients); }
void CBurnEffectManager::CreateBurnEffect(const EventPhysCollision& pCollision, CBurnEffectManager::SBurnPoint* pBurnPoint) { Vec3 surfaceNormal = pCollision.n; Vec3 hitDir(ZERO); if (pCollision.vloc[0].GetLengthSquared() > 1e-6f) { hitDir = pCollision.vloc[0].GetNormalized(); } Vec3 surfacePosition = pCollision.pt; Vec3 halfVector = (surfaceNormal + (-hitDir)).GetNormalized(); CItemParticleEffectCache& particleCache = g_pGame->GetGameSharedParametersStorage()->GetItemResourceCache().GetParticleEffectCache(); IParticleEffect* pParticleEffect = particleCache.GetCachedParticle(pBurnPoint->m_pBurnParams->m_effectName); if (pParticleEffect) { Matrix34 loc; loc.SetIdentity(); loc.SetTranslation(surfacePosition); loc.SetRotation33(OrthoNormalVector(surfaceNormal)); IParticleEmitter* pEffect = pParticleEffect->Spawn(false, loc); if(pEffect) { pEffect->AddRef(); pBurnPoint->m_effect = pEffect; const ParticleParams& particleParams = pParticleEffect->GetParticleParams(); pBurnPoint->m_attachType = particleParams.eAttachType; pBurnPoint->m_attachForm = particleParams.eAttachForm; } UpdateBurnEffect(pBurnPoint); } UpdateBurnEffect(pBurnPoint); }
//----------------------------------------------- //This function is only executed on the server void CC4Projectile::Stick(EventPhysCollision *pCollision) { assert(pCollision); int trgId = 1; IPhysicalEntity *pTarget = pCollision->pEntity[trgId]; if(pTarget == GetEntity()->GetPhysics()) { trgId = 0; pTarget = pCollision->pEntity[trgId]; } //Do not stick to breakable glass if(ISurfaceType *pSurfaceType = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceType(pCollision->idmat[trgId])) { if(pSurfaceType->GetBreakability()==1) { m_notStick = true; return; } } IEntity *pTargetEntity = pTarget ? gEnv->pEntitySystem->GetEntityFromPhysics(pTarget) : 0; if(pTarget && (!pTargetEntity || (pTargetEntity->GetId() != m_ownerId))) { //Special cases if(pTargetEntity) { //Stick to actors using a character attachment CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTargetEntity->GetId())); //Not in MP if(pActor && gEnv->bMultiplayer) { m_notStick = true; return; } if(pActor && pActor->GetHealth()>0) { if(pActor->GetActorSpecies()!=eGCT_HUMAN) { m_notStick = true; return; } if(StickToCharacter(true,pTargetEntity)) { GetGameObject()->SetAspectProfile(eEA_Physics, ePT_None); m_stuck = true; } m_notStick = true; return; } //Do not stick to small objects... if(!pActor) { pe_params_part pPart; pPart.ipart = 0; if(pTarget->GetParams(&pPart) && pPart.pPhysGeom && pPart.pPhysGeom->V<0.15f) { m_notStick = true; return; } } } else if(pTarget->GetType()==PE_LIVING) { m_notStick = true; return; } if(!pTargetEntity) StickToStaticObject(pCollision,pTarget); else { //Do not attach to items if(g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pTargetEntity->GetId())) { m_notStick = true; return; } Matrix34 mat = pTargetEntity->GetWorldTM(); mat.Invert(); Vec3 pos = mat.TransformPoint(pCollision->pt); mat.SetIdentity(); mat.SetRotation33(Matrix33::CreateOrientation(-pCollision->n,GetEntity()->GetWorldTM().TransformVector(Vec3(0,0,1)),gf_PI)); mat.SetTranslation(pos); //Dephysicalize and stick GetGameObject()->SetAspectProfile(eEA_Physics, ePT_None); StickToEntity(pTargetEntity,mat); if(gEnv->bMultiplayer) { Quat rot(Matrix33::CreateOrientation(-pCollision->n,GetEntity()->GetWorldTM().TransformVector(Vec3(0,0,1)),gf_PI*0.5f)); GetGameObject()->InvokeRMI(CC4Projectile::ClStickToEntity(),ProjectileStickToEntity(pTargetEntity->GetId(),pos,rot),eRMI_ToAllClients); } } m_stuck = true; } }