Ejemplo n.º 1
0
Vec3 CCameraPolar::GetDir() const
{
	Vec3 vDir = Vec3Constants<float>::fVec3_OneY;

	//assume normalized vector and compute coordinates
	float fSinPitch = cry_sinf(m_fPitch);
	vDir.x = -cry_sinf(m_fYaw) * fSinPitch;
	vDir.y = cry_cosf(m_fYaw) * fSinPitch;
	vDir.z = cry_cosf(m_fPitch);

	//directions have to be normalized
	CRY_ASSERT(fabsf(vDir.len() - 1.0f) < g_fCamError);

	return vDir;
}
Ejemplo n.º 2
0
void CAutoAimManager::DrawDisc(const Vec3& center, Vec3 axis, float innerRadius, float outerRadius, const ColorB& innerColor, const ColorB& outerColor)
{
	axis.NormalizeSafe(Vec3Constants<float>::fVec3_OneZ);
	Vec3 u = ((axis * Vec3Constants<float>::fVec3_OneZ) > 0.5f) ? Vec3Constants<float>::fVec3_OneY : Vec3Constants<float>::fVec3_OneZ;
	Vec3 v = u.cross(axis);
	u = v.cross(axis);

	float sides = cry_ceilf(3.0f * (float)g_PI * outerRadius);
	//sides = 20.0f;
	float step = (sides > 0.0f) ? 1.0f / sides : 1.0f;
	for (float i = 0.0f; i < 0.99f; i += step)
	{
		float a0 = i * 2.0f * (float)g_PI;
		float a1 = (i+step) * 2.0f * (float)g_PI;
		Vec3 i0 = center + innerRadius * (u*cry_cosf(a0) + v*cry_sinf(a0));
		Vec3 i1 = center + innerRadius * (u*cry_cosf(a1) + v*cry_sinf(a1));
		Vec3 o0 = center + outerRadius * (u*cry_cosf(a0) + v*cry_sinf(a0));
		Vec3 o1 = center + outerRadius * (u*cry_cosf(a1) + v*cry_sinf(a1));
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawTriangle(i0, innerColor, i1, innerColor, o1, outerColor);
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawTriangle(i0, innerColor, o1, outerColor, o0, outerColor);
	}
}
Ejemplo n.º 3
0
void CFlock::GetDefaultBoidsContext( SBoidContext &bc )
{
	ZeroStruct(bc);
	bc.MinHeight = MIN_FLIGHT_HEIGHT;
	bc.MaxHeight = MAX_FLIGHT_HEIGHT;

	bc.MaxAttractDistance = MAX_ATTRACT_DISTANCE;
	bc.MinAttractDistance = MIN_ATTRACT_DISTANCE;

	bc.MaxSpeed = MAX_SPEED;
	bc.MinSpeed = MIN_SPEED;

	bc.factorAlignment = ALIGNMENT_FACTOR;
	bc.factorCohesion = COHESION_FACTOR;
	bc.factorSeparation = SEPARATION_FACTOR;

	bc.factorAttractToOrigin = ORIGIN_ATTRACT_FACTOR;
	bc.factorKeepHeight = DESIRED_HEIGHT_FACTOR;
	bc.factorAvoidLand = AVOID_LAND_FACTOR;

	bc.MaxAnimationSpeed = MAX_ANIMATION_SPEED;

	bc.followPlayer = false;
	bc.avoidObstacles = true;
	bc.noLanding = false;
	bc.bAvoidWater = true;

	bc.cosFovAngle = cry_cosf(125.0f*gf_PI/180.0f);
	bc.maxVisibleDistance = 300;

	bc.boidScale = 5;

	bc.fSmoothFactor = 0;
	bc.fMaxTurnRatio = 0;
	bc.vEntitySlotOffset.Set(0,0,0);

	bc.attractionPoint.Set(0,0,0);

	bc.fWalkToIdleDuration = WALK_TO_IDLE_DURATION;

	bc.fOnGroundIdleDurationMin = ON_GROUND_IDLE_DURATION_MIN;
	bc.fOnGroundIdleDurationMax = ON_GROUND_IDLE_DURATION_MAX;

	bc.fOnGroundWalkDurationMin = ON_GROUND_WALK_DURATION_MIN;
	bc.fOnGroundWalkDurationMax = ON_GROUND_WALK_DURATION_MAX;
}
Ejemplo n.º 4
0
void CBirdsFlock::UpdateLandingPoints()
{
	int numPoints = m_boids.size()*3 /2;
	if(m_LandingPoints.size() < (size_t) numPoints )
	{
		if(!m_landCollisionInfo.IsRequestingRayCast())
		{
			float maxradius = m_bc.fSpawnRadius *0.6f;
			Vec3 origin(m_bc.flockPos);
			float angle = Boid::Frand()*gf_PI;
			float radius = (Boid::Frand()+1)/2 * maxradius;

			origin += Vec3(cry_cosf(angle)*radius, cry_sinf(angle)*radius, 5.f);

			Vec3 vDir = Vec3(0,0,-10);
			m_landCollisionInfo.QueueRaycast(m_pEntity->GetId(),origin,vDir,&m_landCollisionCallback);
		}
	}
}
Ejemplo n.º 5
0
bool SkillKill::IsGotYourBackKill(CPlayer* pShooterPlayer, CPlayer* pTargetPlayer)
{
    //To use the new actor manager stuff when merged back to postalpha
    const float maxDistSq = sqr(g_pGameCVars->g_gotYourBackKill_targetDistFromFriendly);
    const float fovRange = cry_cosf(DEG2RAD(g_pGameCVars->g_gotYourBackKill_FOVRange));

    IActorIteratorPtr pActorIterator = g_pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();

    Vec3 targetLocation = pTargetPlayer->GetEntity()->GetWorldPos();
    SMovementState targetMovementState;
    pTargetPlayer->GetMovementController()->GetMovementState(targetMovementState);

    Vec3 targetAimDirection = targetMovementState.aimDirection;

    while(CActor* pActor = static_cast<CActor*>(pActorIterator->Next()))
        {
            if(pActor != pShooterPlayer && !pActor->IsDead() && pShooterPlayer->IsFriendlyEntity(pActor->GetEntityId()))
                {
                    Vec3 actorLocation = pActor->GetEntity()->GetWorldPos();
                    Vec3 distance = actorLocation - targetLocation;

                    if(distance.GetLengthSquared() < maxDistSq)
                        {
                            distance.Normalize();
                            if(distance.Dot(targetAimDirection) > fovRange)
                                {
                                    SMovementState actorMovementState;
                                    pActor->GetMovementController()->GetMovementState(actorMovementState);
                                    Vec3 actorAimDirection = actorMovementState.aimDirection;

                                    if(actorAimDirection.Dot(-distance) < fovRange)
                                        {
                                            return true;
                                        }
                                }
                        }
                }
        }

    return false;
}
Ejemplo n.º 6
0
void CClaymore::Update(SEntityUpdateContext &ctx, int updateSlot)
{
	CProjectile::Update(ctx, updateSlot);

	bool debug = (g_pGameCVars->g_debugMines != 0);

	if(gEnv->bServer)
	{
		if(m_armed)
		{
			CGameRules* pGR = g_pGame->GetGameRules();
			if(pGR)
			{
				for(std::list<EntityId>::iterator it = m_targetList.begin(); it != m_targetList.end(); ++it)
				{
					IEntity* pEntity = gEnv->pEntitySystem->GetEntity(*it);
					if(!pEntity) continue;
						
					// if this is a team game, claymores aren't set off by their own team...
					if(pGR->GetTeamCount() > 0 && (m_teamId != 0 && pGR->GetTeam(pEntity->GetId()) == m_teamId))
						continue;

					// otherwise, not set off by the player who dropped them.
					if(pGR->GetTeamCount() == 0 && m_ownerId == pEntity->GetId())
						continue;
					
					IPhysicalEntity *pPhysics = pEntity->GetPhysics();
					if(pPhysics)
					{
						pe_status_dynamics physStatus;
						if(0 != pPhysics->GetStatus(&physStatus) && physStatus.v.GetLengthSquared() > 0.01f)
						{
							// now check angle between this claymore and approaching object
							//	to see if it is within the angular range m_triggerAngle.
							//	If it is, then check distance is less than m_triggerRange,
							//	and also check line-of-sight between the two entities.
							IRenderAuxGeom * pRAG = gEnv->pRenderer->GetIRenderAuxGeom();
							pRAG->SetRenderFlags( e_Mode3D | e_AlphaBlended | e_DrawInFrontOff | e_FillModeSolid | e_CullModeNone );

							AABB entityBBox;	
							pEntity->GetWorldBounds(entityBBox);

							if(debug)
							{
								pRAG->DrawAABB( entityBBox, true, ColorF(1,0,0,0.4f), eBBD_Faceted );
							}

							Vec3 enemyDir = entityBBox.GetCenter() - GetEntity()->GetPos();
							Vec3 checkDir = enemyDir; 
							checkDir.z = 0;
							float distanceSq = enemyDir.GetLengthSquared();

							// for players a simple distance check is fine, but for vehicles use a better intersection check
							//	so any corner of the vehicle going inside the zone sets off the claymore.
							static float playerRadius = 2.5f;
							bool inside = false;
							if(entityBBox.GetRadius() < playerRadius)
							{
								inside = (distanceSq < (m_triggerRadius * m_triggerRadius));
							}
							else
							{							
								static ray_hit hit;
								if(gEnv->pPhysicalWorld->CollideEntityWithBeam(pEntity->GetPhysics(), GetEntity()->GetWorldPos(), enemyDir, m_triggerRadius, &hit))
								{
									inside = true;
									enemyDir = hit.pt - GetEntity()->GetWorldPos();
								}
							}

							if(inside)
							{
								enemyDir.NormalizeSafe();
								checkDir.NormalizeSafe();
								float dotProd = checkDir.Dot(m_triggerDirection);

								if(debug)
								{
									pRAG->DrawLine(GetEntity()->GetPos(), ColorF(1,0,0,1), GetEntity()->GetPos() + Matrix33::CreateRotationZ(m_triggerAngle/2.0f)*m_triggerDirection*m_triggerRadius, ColorF(1,0,0,1), 5.0f);
									pRAG->DrawLine(GetEntity()->GetPos(), ColorF(1,0,0,1), GetEntity()->GetPos() + Matrix33::CreateRotationZ(-m_triggerAngle/2.0f)*m_triggerDirection*m_triggerRadius, ColorF(1,0,0,1), 5.0f);

									ColorF clr;
									clr.a = 0.3f;
									clr.b = 0.4f;
									clr.g = 0.1f;
									clr.r = 1.0f;
									pRAG->DrawLine(GetEntity()->GetPos(), clr, GetEntity()->GetPos() + (enemyDir * m_triggerRadius), clr, 5.0f);
								}

								if(dotProd > cry_cosf(m_triggerAngle/2.0f))
								{
									static const int objTypes = ent_all&(~ent_terrain);   
									static const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any;
									ray_hit hit;
									int col = gEnv->pPhysicalWorld->RayWorldIntersection(GetEntity()->GetPos(), (enemyDir * m_triggerRadius * 1.5f), objTypes, flags, &hit, 1, GetEntity()->GetPhysics());

									bool bang = false;
									if (!col)
										bang = true;
									else if (entityBBox.IsContainPoint(hit.pt))
										bang = true;
									else if (hit.pt.GetSquaredDistance(GetEntity()->GetWorldPos()) >= distanceSq)
										bang = true;
									if (bang)
									{
										// pass in the explosion normal, which is -m_triggerDirection
										Explode(true, false, Vec3(0,0,0), -m_triggerDirection);

										if(debug)
										{
											ColorF clr;
											clr.a = 0.3f;
											clr.g = 0.1f;
											clr.r = 1.0f;
											clr.b = 1.0f;
											pRAG->DrawLine(GetEntity()->GetPos(), clr, GetEntity()->GetPos() + (enemyDir * m_triggerRadius), clr, 5.0f);
										}
									}
								}
							}
						}
					}
				}
			}
		}
		else
		{
			m_timeToArm -= gEnv->pTimer->GetFrameTime();
			if(m_timeToArm <= 0.0f)
			{
				m_armed = true;

				IEntityTriggerProxy *pTriggerProxy = (IEntityTriggerProxy*)(GetEntity()->GetProxy(ENTITY_PROXY_TRIGGER));

				if (!pTriggerProxy)
				{
					GetEntity()->CreateProxy(ENTITY_PROXY_TRIGGER);
					pTriggerProxy = (IEntityTriggerProxy*)GetEntity()->GetProxy(ENTITY_PROXY_TRIGGER);
				}

				if(pTriggerProxy)
				{
					// create a trigger volume a couple of metres bigger than we need, to ensure we catch vehicles.
					//	Checks above will still make sure the entity is within the radius before detonating though.
					float radius = m_triggerRadius + 2.0f;
					AABB boundingBox = AABB(Vec3(-radius,-radius,-radius), Vec3(radius,radius,radius));
					pTriggerProxy->SetTriggerBounds(boundingBox);
				}
			}
		}
	}

	if(debug && m_armed)
	{
		IRenderAuxGeom * pRAG = gEnv->pRenderer->GetIRenderAuxGeom();
		ColorF clr;
		clr.a = 0.3f;
		clr.b = 0.4f;
		clr.g = 0.1f;
		clr.r = 1.0f;
		pRAG->SetRenderFlags( e_Mode3D | e_AlphaBlended | e_DrawInFrontOff | e_FillModeSolid | e_CullModeNone );
		pRAG->DrawCylinder(GetEntity()->GetPos(), Vec3(0, 0, 1), m_triggerRadius, m_triggerRadius * 2.0f, clr);
		Vec3 size(m_triggerRadius + 2.0f, m_triggerRadius + 2.0f, m_triggerRadius + 2.0f);
		AABB box(GetEntity()->GetPos() - size, GetEntity()->GetPos() + size);
		pRAG->DrawAABB(box, false, ColorF(0.1f, 0.1f, 0.1f, 0.1f), eBBD_Faceted);
		pRAG->DrawLine(GetEntity()->GetPos(), clr, GetEntity()->GetPos() + m_triggerDirection, clr, 5.0f);
	}
}
Ejemplo n.º 7
0
void CSpammer::UpdatePotentialTargets()
{
	const float minLockOnDistance = m_fireParams->spammerParams.minLockOnDistance;
	const float maxLockOnDistance = m_fireParams->spammerParams.maxLockOnDistance;
	const float maxAngleCos = cry_cosf(DEG2RAD(m_fireParams->spammerParams.targetingTolerance));

	const CAutoAimManager& autoAimManager = g_pGame->GetAutoAimManager();
	const TAutoaimTargets& aaTargets = autoAimManager.GetAutoAimTargets();
	const int targetCount = aaTargets.size();

	const Vec3 probableHit = Vec3Constants<float>::fVec3_Zero;
	const Vec3 weaponPos = GetWeaponPosition(probableHit);
	const Vec3 weaponFwd = GetWeaponDirection(weaponPos, probableHit);

	m_potentialTargets.Clear();

	CPlayerVisTable::SVisibilityParams queryTargetParams(0);
	const bool flat2DMode = m_fireParams->spammerParams.targetingFlatMode;

	for (int i = 0; i < targetCount; ++i)
	{
		const SAutoaimTarget& target = aaTargets[i];
		CRY_ASSERT(target.entityId != m_pWeapon->GetOwnerId());

		if (!target.HasFlagSet(eAATF_AIHostile))
			continue;

		IEntity* pTargetEntity = gEnv->pEntitySystem->GetEntity(target.entityId);
		if (!pTargetEntity)
			continue;
		CActor* pActor = target.pActorWeak.lock().get();

		AABB bounds;
		pTargetEntity->GetWorldBounds(bounds);
		Vec3 targetPos = bounds.GetCenter();
		Vec3 targetDistVec = (targetPos - weaponPos).normalized();
		float distance = targetPos.GetDistance(weaponPos);

		if (distance <= minLockOnDistance || distance >= maxLockOnDistance)
			continue;

		float alignment;
		if (!flat2DMode)
		{
			alignment = weaponFwd * targetDistVec;
		}
		else
		{
			const CCamera& viewCamera = gEnv->pSystem->GetViewCamera();
			if (!viewCamera.IsPointVisible(targetPos))
				continue;

			alignment = Vec3(weaponFwd.x, weaponFwd.y, 0.0f).GetNormalizedSafe() * Vec3(targetDistVec.x, targetDistVec.y, 0.0f).GetNormalizedSafe();
		}

		if (alignment <= maxAngleCos)
			continue;

		const SpammerTarget finalTargetInfo = GetVisibilityTestTarget(pTargetEntity, target.entityId, pActor, bounds);

		const int kAutoaimVisibilityLatency = 0;
		queryTargetParams.targetEntityId = finalTargetInfo.targetId;
		if (!g_pGame->GetPlayerVisTable()->CanLocalPlayerSee(queryTargetParams, kAutoaimVisibilityLatency))
			continue;

		float priority = 1.0f;
		priority *= finalTargetInfo.radius;
		priority /= m_targetsAssigned.GetNumLockOns(target.entityId)+1;
		const float m = 1.0f / (1.0f - maxAngleCos);
		priority *= m * alignment + (1.0f - m);
		priority *= 0.1f;
		priority = min(priority, 1.0f);

		m_potentialTargets.AddTarget(target.entityId, priority);
	}

	float n = 0.0f;
	size_t num = m_potentialTargets.m_potentialTargets.size();
	for (size_t i = 0; i < num; ++i)
	{
		n = max(n, m_potentialTargets.m_potentialTargets[i].m_probability);
	}
	m_potentialTargets.m_totalProbability = 0.0f;
	for (size_t i = 0; num && i < m_potentialTargets.m_potentialTargets.size(); ++i)
	{
		m_potentialTargets.m_potentialTargets[i].m_probability /= n + FLT_EPSILON;
		m_potentialTargets.m_totalProbability += m_potentialTargets.m_potentialTargets[i].m_probability;
	}
}
Ejemplo n.º 8
0
//--------------------------------------------------------------------------
void CIronSight::ZoomSway(float time, float &x, float &y)
{
	static bool  firing = false;

	bool wasFiring = firing;

	//Update while not firing...
	if(IFireMode *pFM = m_pWeapon->GetFireMode(m_pWeapon->GetCurrentFireMode()))
	{
		if(pFM->IsFiring())
			firing = true;
		else
			firing = false;
	}

	//Reset cycle after firing
	if(wasFiring && !firing)
		m_swayTime = m_pShared->zoomSway.stabilizeTime*(1.0f-m_pShared->zoomSway.scaleAfterFiring);

	m_swayCycle+=(0.3f*time);

	if(m_swayCycle>1.0f)
		m_swayCycle-=1.0f;

	//Just a simple sin/cos function
	float dtX = cry_sinf(m_swayCycle*gf_PI*4.0f);
	float dtY = -cry_cosf(m_swayCycle*gf_PI*2.0f);

	m_swayTime += time;

	//Strength scale
	float strengthScale = 1.0f;
	float stanceScale = 1.0f;

	if(CPlayer *pPlayer = static_cast<CPlayer *>(m_pWeapon->GetOwnerActor()))
	{
		if(SPlayerStats *pStats = static_cast<SPlayerStats *>(pPlayer->GetActorStats()))
			pStats->FPWeaponSwayOn = true;

		//Stance mods
		if(pPlayer->GetStance()==STANCE_CROUCH)
			stanceScale = m_pShared->zoomSway.crouchScale;
		else if(pPlayer->GetStance()==STANCE_PRONE)
			stanceScale = m_pShared->zoomSway.proneScale;
	}

	//Time factor
	float factor = m_pShared->zoomSway.minScale;
	float settleTime = m_pShared->zoomSway.stabilizeTime*m_pShared->zoomSway.strengthScaleTime;

	if(m_swayTime<settleTime)
	{
		factor = (settleTime-m_swayTime)/settleTime;

		if(factor<m_pShared->zoomSway.minScale)
			factor = m_pShared->zoomSway.minScale;
	}

	//Final displacement
	x = dtX*m_pShared->zoomSway.maxX*factor*strengthScale*stanceScale;
	y = dtY*m_pShared->zoomSway.maxY*factor*strengthScale*stanceScale;
}
void SBasicReplayMovementParams::SetDesiredLocalLocation2( ISkeletonAnim* pSkeletonAnim, const QuatT& desiredLocalLocation, float lookaheadTime, float fDeltaTime, float turnSpeedMultiplier)
{
	QuatT m_desiredLocalLocationQTX			= desiredLocalLocation;
	assert(m_desiredLocalLocationQTX.q.IsValid());
	f32 m_desiredArrivalDeltaTimeQTX		= lookaheadTime;
	f32 m_desiredTurnSpeedMultiplierQTX = turnSpeedMultiplier;

	uint32 NumAnimsInQueue = pSkeletonAnim->GetNumAnimsInFIFO(0);
	uint32 nMaxActiveInQueue=MAX_EXEC_QUEUE;	
	if (nMaxActiveInQueue>NumAnimsInQueue)
		nMaxActiveInQueue=NumAnimsInQueue;
	if (NumAnimsInQueue>nMaxActiveInQueue)
		NumAnimsInQueue=nMaxActiveInQueue;

	uint32 active=0;
	for (uint32 a=0; a<NumAnimsInQueue; a++)
	{
		CAnimation& anim = pSkeletonAnim->GetAnimFromFIFO(0,a);
		active += anim.IsActivated() ? 1 : 0;
	}

	if (active>nMaxActiveInQueue)
		active=nMaxActiveInQueue;
	nMaxActiveInQueue=active;


	const QuatT &rDesiredLocation = m_desiredLocalLocationQTX;

	const SParametricSampler *pLMG = NULL;
	for (int32 a=nMaxActiveInQueue-1; (a >= 0) && !pLMG; --a)
	{
		const CAnimation& anim = pSkeletonAnim->GetAnimFromFIFO(0,a);
		pLMG = anim.GetParametricSampler();
	}

	Vec3 dir = rDesiredLocation.q * FORWARD_DIRECTION;
	Vec2 predictedDir( dir.x, dir.y );

	float predictedAngle = RAD2DEG(atan2f(-predictedDir.x, predictedDir.y));
	float turnSpeed = m_desiredTurnSpeedMultiplierQTX * DEG2RAD(predictedAngle) / max(0.1f, m_desiredArrivalDeltaTimeQTX);
	float turnAngle = DEG2RAD(predictedAngle);

	Vec2 deltaVector(rDesiredLocation.t.x, rDesiredLocation.t.y);
	float deltaDist = deltaVector.GetLength();

	const float thresholdDistMin = 0.05f;
	const float thresholdDistMax = 0.15f;
	f32 uniform_scale = 1.0f;//m_pInstance->CCharInstance::GetUniformScale();

	float travelDistScale = CLAMP((deltaDist - thresholdDistMin) / (thresholdDistMax - thresholdDistMin), 0.0f, 1.0f);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TravelDistScale, travelDistScale/uniform_scale, fDeltaTime);

	Vec2 deltaDir = (deltaDist > 0.0f) ? (deltaVector / deltaDist) : Vec2(0,0);
	float deltaAngle = (deltaDir.x == 0.0f && deltaDir.y == 0.0f  ? 0.0f : RAD2DEG(atan2f(-deltaDir.x, deltaDir.y)) );
	float travelAngle = DEG2RAD(deltaAngle);

	// Update travel direction only if distance bigger (more secure) than thresholdDistMax.
	// Though, also update travel direction if distance is small enough to not have any visible effect (since distance scale is zero).
	bool initOnly = DO_INIT_ONLY_TEST && ((deltaDist > thresholdDistMin) && (deltaDist < thresholdDistMax));

	Vec2 newStrafe = Vec2(-cry_sinf(travelAngle), cry_cosf(travelAngle));
	if (pLMG) 
	{
		SmoothCD(m_desiredStrafeSmoothQTX, m_desiredStrafeSmoothRateQTX, fDeltaTime, newStrafe, 0.10f);
	}
	else 
	{
		//	CryFatalError("CryAnimation: no smooth");
		m_desiredStrafeSmoothQTX=newStrafe;
		m_desiredStrafeSmoothRateQTX.zero();
	}
	travelAngle=Ang3::CreateRadZ(Vec2(0,1),m_desiredStrafeSmoothQTX);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TravelAngle, travelAngle, fDeltaTime);

	float curvingFraction = 0.0f;

	if (pLMG)
	{
		SmoothCD(m_fDesiredTurnSpeedSmoothQTX, m_fDesiredTurnSpeedSmoothRateQTX, fDeltaTime, turnSpeed, 0.40f);
	}
	else
	{
		m_fDesiredTurnSpeedSmoothQTX=turnSpeed;
		m_fDesiredTurnSpeedSmoothRateQTX = 0.0f;
	}
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TurnSpeed, m_fDesiredTurnSpeedSmoothQTX, fDeltaTime);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TurnAngle, turnAngle, fDeltaTime);

	// Curving Distance	
	float div = cry_cosf(DEG2RAD(90.0f - predictedAngle));
	float curveRadius = (deltaDist / 2.0f);

	if( abs(div) > 0.0f )
		curveRadius = curveRadius / div;
	float circumference = curveRadius * 2.0f * gf_PI;
	float curveDist = circumference * (predictedAngle * 2.0f / 360.0f);
	curveDist = max(deltaDist, curveDist);

	// Travel Speed/Distance
	float travelDist = LERP(deltaDist, curveDist, curvingFraction);
	float travelSpeed = travelDist / max(0.1f, m_desiredArrivalDeltaTimeQTX);
	//travelDist *= travelDistScale;
	//travelSpeed *= travelDistScale;

	//	float fColDebug[4] = {1,0,0,1};
	//	g_pIRenderer->Draw2dLabel( 1,g_YLine, 2.6f, fColDebug, false,"qqqtravelSpeed: atime: %f", travelSpeed );	
	//	g_YLine+=26.0f;
	SmoothCD(m_fDesiredMoveSpeedSmoothQTX, m_fDesiredMoveSpeedSmoothRateQTX, fDeltaTime, travelSpeed, 0.04f);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TravelSpeed, m_fDesiredMoveSpeedSmoothQTX, fDeltaTime);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_TravelDist, travelDist, fDeltaTime);
	pSkeletonAnim->SetDesiredMotionParam(eMotionParamID_Scale, uniform_scale, fDeltaTime);
}
#include "GameCVars.h"
#include "Game.h"
#include "GameActions.h"
#include "Weapon.h"
#include "Melee.h"
#include "PlayerInput.h"

#include "StatsRecordingMgr.h"
#include "PlayerStateEvents.h"

#include "PlayerAnimation.h"
#include "PlayerCamera.h"

const float MAX_LEAN_ANGLE							= gf_PI * 0.33f;
const float LEAN_RATE										= 3.0f;
const float MIN_KICK_DP									= cry_cosf(DEG2RAD(60.0f));

class CPlayerSlideAction : public TPlayerAction
{
public:
	DEFINE_ACTION("PlayerSlide");

	CPlayerSlideAction(CPlayer &player, CSlideController& slideController)
		:	TPlayerAction(PP_PlayerActionUrgent, PlayerMannequin.fragmentIDs.slide, TAG_STATE_EMPTY, IAction::NoAutoBlendOut)
		, m_player(player)
		, m_slideController(&slideController)
		, m_leanFactor(0.0f)
		, m_kicking(false)
		, m_slideFragID(FRAGMENT_ID_INVALID)
		, m_slideFragTags(TAG_STATE_EMPTY)
	{
Ejemplo n.º 11
0
bool CScriptBind_Boids::ReadParamsTable(IScriptTable *pTable, struct SBoidContext &bc,SBoidsCreateContext &ctx )
{
	pTable->BeginSetGetChain();
	float fval;
	const char *str;

	ctx.models.clear();
	ctx.boidsCount = 0;
	pTable->GetValueChain( "count",ctx.boidsCount );
	if (pTable->GetValueChain( "model",str ))
	{
		ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model1",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model2",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model3",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "model4",str ))
	{
		if (str[0])
			ctx.models.push_back(str);
	}
	if (pTable->GetValueChain( "character",str ))
	{
		ctx.characterModel = str;
	}
	if (pTable->GetValueChain( "animation",str ))
	{
		ctx.animation = str;
	}

	pTable->GetValueChain( "behavior",bc.behavior );

	pTable->GetValueChain( "boid_mass",bc.fBoidMass);

	pTable->GetValueChain( "boid_size",bc.boidScale );
	pTable->GetValueChain( "boid_size_random",bc.boidRandomScale );
	pTable->GetValueChain( "min_height",bc.MinHeight );
	pTable->GetValueChain( "max_height",bc.MaxHeight );
	pTable->GetValueChain( "min_attract_distance",bc.MinAttractDistance );
	pTable->GetValueChain( "max_attract_distance",bc.MaxAttractDistance );
	
	if(bc.MinAttractDistance <=0.05f)
		bc.MinAttractDistance = 0.05f;
	if(bc.MaxAttractDistance <=bc.MinAttractDistance)
		bc.MaxAttractDistance =bc.MinAttractDistance +0.05f;

	pTable->GetValueChain( "min_speed",bc.MinSpeed );
	pTable->GetValueChain( "max_speed",bc.MaxSpeed );
	
	pTable->GetValueChain( "factor_align",bc.factorAlignment );
	pTable->GetValueChain( "factor_cohesion",bc.factorCohesion );
	pTable->GetValueChain( "factor_separation",bc.factorSeparation );
	pTable->GetValueChain( "factor_origin",bc.factorAttractToOrigin );
	pTable->GetValueChain( "factor_keep_height",bc.factorKeepHeight );
	pTable->GetValueChain( "factor_avoid_land",bc.factorAvoidLand );
	pTable->GetValueChain( "factor_random_accel",bc.factorRandomAccel );
	pTable->GetValueChain( "flight_time",bc.flightTime );
	pTable->GetValueChain( "factor_take_off",bc.factorTakeOff );
	pTable->GetValueChain( "land_deceleration_height",bc.landDecelerationHeight);

	pTable->GetValueChain( "max_anim_speed",bc.MaxAnimationSpeed );
	pTable->GetValueChain( "follow_player",bc.followPlayer );
	pTable->GetValueChain( "no_landing",bc.noLanding );
	pTable->GetValueChain( "start_on_ground",bc.bStartOnGround );
	pTable->GetValueChain( "avoid_water",bc.bAvoidWater );
	pTable->GetValueChain( "avoid_obstacles",bc.avoidObstacles );
	pTable->GetValueChain( "max_view_distance",bc.maxVisibleDistance );
	pTable->GetValueChain( "max_animation_distance",bc.animationMaxDistanceSq);
	bc.animationMaxDistanceSq *= bc.animationMaxDistanceSq;
	pTable->GetValueChain( "spawn_from_point", bc.bSpawnFromPoint );

	pTable->GetValueChain( "spawn_radius",bc.fSpawnRadius);
	//pTable->GetValueChain( "boid_radius",bc.fBoidRadius);
	pTable->GetValueChain( "gravity_at_death",bc.fGravity);
	pTable->GetValueChain( "boid_mass",bc.fBoidMass);
	if (pTable->GetValueChain( "fov_angle",fval ))
	{
		fval = fval/2.0f; // Half angle used for cos of fov.
		bc.cosFovAngle = cry_cosf(fval*gf_PI/180.0f);
	}

	SmartScriptTable groundTable;
	if (pTable->GetValueChain("ground",groundTable))
	{
		groundTable->BeginSetGetChain();
		groundTable->GetValueChain( "factor_align",bc.factorAlignmentGround );
		groundTable->GetValueChain( "factor_cohesion",bc.factorCohesionGround );
		groundTable->GetValueChain( "factor_separation",bc.factorSeparationGround );
		groundTable->GetValueChain( "factor_origin",bc.factorAttractToOriginGround );
		groundTable->GetValueChain( "walk_speed",bc.walkSpeed);
		groundTable->GetValueChain( "offset",bc.groundOffset);

		groundTable->EndSetGetChain();
	}

	SmartScriptTable sounds;
	if (pTable->GetValueChain("Sounds",sounds))
	{
		for (int i = 1; i < 100; i++)
		{
			str = "";
			if (sounds->GetAt(i,str))
			{
				bc.sounds.push_back(str);
			}
			else
				break;
		}
	}
	SmartScriptTable animations;
	if (pTable->GetValueChain("Animations",animations))
	{
		for (int i = 1; i < 100; i++)
		{
			str = "";
			if (animations->GetAt(i,str))
			{
				bc.animations.push_back(str);
			}
			else
				break;
		}
	}

	pTable->EndSetGetChain();

	return true;
}