Beispiel #1
0
void CHeadBobMgr::Update()
{
	// Don't allow head bobbing or canting to update when paused...

	if( g_pGameClientShell->IsGamePaused() )
		return;

	CMoveMgr* pMoveMgr = g_pPlayerMgr->GetMoveMgr();
	if (!pMoveMgr) return;

	// We check CanDoFootstep instead of on ground since CanDoFootstep
	// handles stairs much better...

	if ( (!g_pPlayerMgr->IsSpectatorMode() && g_pPlayerMgr->IsFirstPerson() && pMoveMgr->CanDoFootstep() &&
		 g_pPlayerMgr->IsPlayerMovementAllowed() && pMoveMgr->GetAllowMovement()) ||
		 pMoveMgr->GetVehicleMgr()->IsVehiclePhysics() )
	{
		UpdateHeadBob();
		UpdateHeadCant();
	}
}
Beispiel #2
0
void CHeadBobMgr::UpdateHeadCant()
{
	CMoveMgr* pMoveMgr = g_pPlayerMgr->GetMoveMgr();
	if (!pMoveMgr) return;

	CVehicleMgr* pVehicleMgr = pMoveMgr->GetVehicleMgr();
	if (!pVehicleMgr) return;

	LTBOOL bVehicleTurning	= pVehicleMgr->IsTurning();
	int    nVehicleTurnDir	= pVehicleMgr->GetTurnDirection();

	CantType eCantType = eCantNone;
	LTFLOAT fMaxCant = 0.0f, fCantRate = 0.0f;
	
	if (bVehicleTurning && pMoveMgr->CanDoFootstep())
	{
		eCantType = nVehicleTurnDir > 0 ? eCantRight : eCantLeft;
	}


	fMaxCant = DEG2RAD(g_vtMaxVehicleHeadCant.GetFloat());
	LTFLOAT fMinCant = fMaxCant * 0.25f;

	LTFLOAT fRoll = LimitToPosNegPi( g_pPlayerMgr->GetRoll() - pVehicleMgr->GetVehicleContourRoll() );

	switch (eCantType)
	{
		case eCantRight :
		{
			if (fRoll > 0.0f)
			{
				fCantRate = g_vtVehicleHeadCantDownRate.GetFloat();
			}
			else
			{
				fCantRate = g_vtVehicleHeadCantUpRate.GetFloat();
			}
		}
		break;
		case eCantLeft :
		{
			if (fRoll < 0.0f)
			{
				fCantRate = g_vtVehicleHeadCantDownRate.GetFloat();
			}
			else
			{
				fCantRate = g_vtVehicleHeadCantUpRate.GetFloat();
			}
		}
		break;
		case eCantNone:
		{
			fCantRate = g_vtVehicleHeadCantDownRate.GetFloat();
		}
		break;

		default :
		break;
	}

	if (fabs(fRoll) < fMinCant)
	{
		fCantRate *= 0.5f;
	}

	// This frame time is used since unlike ClientDE::GetFrameTime() the
	// max value is controlled by the game...

	LTFLOAT fFrameTime = g_pGameClientShell->GetFrameTime();

	LTFLOAT fDelta = fCantRate * fFrameTime;

	switch (eCantType)
	{
		case eCantRight :
		{
			fRoll -= fDelta;

			if (fRoll < -fMaxCant)
			{
				fRoll = -fMaxCant;
			}
		}
		break;

		case eCantLeft :
		{
			fRoll += fDelta;

			if (fRoll > fMaxCant)
			{
				fRoll = fMaxCant;
			}
		}
		break;

		case eCantNone:
		default :
		{
			// We are not canting so move us toward zero...

			if (fRoll != 0.0f)
			{
				if (fRoll < 0.0f)
				{
					fRoll += fDelta;

					if (fRoll > 0.0f)
					{
						fRoll = 0.0f;
					}
				}
				else
				{
					fRoll -= fDelta;

					if (fRoll < 0.0f)
					{
						fRoll = 0.0f;
					}
				}
 			}
		}
		break;
	}

	// Let the vehicle mgr adjust the value...

	pVehicleMgr->AdjustCameraRoll(fRoll);

	// Set the new value...

	g_pPlayerMgr->SetRoll(fRoll);
}
Beispiel #3
0
void CHeadBobMgr::UpdateHeadBob()
{
	CMoveMgr* pMoveMgr = g_pPlayerMgr->GetMoveMgr();
	if (!pMoveMgr) return;

    LTBOOL bZoomed = g_pPlayerMgr->IsZoomed();

    uint32 dwPlayerFlags = g_pPlayerMgr->GetPlayerFlags();

	// This frame time is used since unlike ClientDE::GetFrameTime() the
	// max value is controlled by the game...

    LTFLOAT fFrameTime = g_pGameClientShell->GetFrameTime();

    LTFLOAT fTime      = g_pLTClient->GetTime();
    LTBOOL bRunning    = (LTBOOL) !!(dwPlayerFlags & BC_CFLG_RUN);
    LTFLOAT fMoveDist  = pMoveMgr->GetVelocity().Mag() * fFrameTime;

    LTBOOL bFootstep = LTFALSE;
	LTBOOL bLeftFoot = LTFALSE;
    LTFLOAT fPace = 0.0f;

	if (pMoveMgr->GetVehicleMgr()->IsVehiclePhysics())
	{
		fPace = MATH_CIRCLE * g_vtVehiclePaceAdjust.GetFloat();
	}
    else if (bRunning)
	{
		fPace = MATH_CIRCLE * g_vtRunPaceAdjust.GetFloat();
	}
	else
	{
		fPace = MATH_CIRCLE * g_vtWalkPaceAdjust.GetFloat();
	}

	// Make sure bob phase and sway phase start at the right values...

	if (m_fBobAmp == 0.0f)
	{
		m_fBobPhase  = 0.0f;
		m_fSwayPhase = 0.0f;
	}
	else  // Normal processing...
	{
		// Bob phase should be between MATH_PI and MATH_CIRCLE so that the
		// sin(m_fBobPhase) is always between -1 and 0...

		m_fBobPhase += (fFrameTime * fPace);

		if (m_fBobPhase > MATH_CIRCLE)
		{
			m_fBobPhase -= MATH_PI;
		}
		else if (m_fBobPhase < MATH_PI)
		{
			m_fBobPhase += MATH_PI;
		}

		m_fSwayPhase += (fFrameTime * fPace);

		if (m_fSwayPhase > MATH_CIRCLE)
		{
			m_fSwayPhase -= MATH_CIRCLE;
		}
	}


	// See if it is time to play a footstep sound...

	if ((m_fSwayPhase > MATH_CIRCLE * 0.25f) &&
		(m_fSwayPhase <= MATH_CIRCLE * 0.75f))
	{
		if (s_bCanDoLeftFootstep)
		{
			bLeftFoot = LTFALSE;
            bFootstep = LTTRUE;
            s_bCanDoLeftFootstep = LTFALSE;
            s_bCanDoRightFootstep = LTTRUE;
		}
	}
	else if (m_fSwayPhase > MATH_CIRCLE * 0.75f)
	{
		if (s_bCanDoRightFootstep)
		{
			bLeftFoot = LTTRUE;
            bFootstep = LTTRUE;
            s_bCanDoLeftFootstep = LTTRUE;
            s_bCanDoRightFootstep = LTFALSE;
		}
	}


    LTBOOL bMoving = LTFALSE;
    LTFLOAT t;

	uint32 dwTestFlags = (BC_CFLG_MOVING); // | BC_CFLG_DUCK);
	if (fMoveDist > 0.1f)
	{
		bMoving = !!(dwPlayerFlags & dwTestFlags);
	}


	// If we're not moving, decay the head bob...

	if (!bMoving)
	{
		s_fBobStartTime = -1.0f;

		if (s_fBobDecayStartTime < 0.0f)
		{
			// Calculate what the current bobamp percent is...

			t = (1.0f - m_fBobAmp / g_vtMaxBobAmp.GetFloat());

			s_fBobDecayStartTime = fTime - (g_vtBobDecayTime.GetFloat() * t);
		}

        LTFLOAT fDur = (fTime - s_fBobDecayStartTime);
		if (fDur <= g_vtBobDecayTime.GetFloat())
		{
			t = fDur / g_vtBobDecayTime.GetFloat();	// 0 to 1
			t = WaveFn_SlowOff(t);
			t = 1.0f - t;				// 1 to 0

			m_fBobAmp = t * g_vtMaxBobAmp.GetFloat();

			if (m_fBobAmp < 0.0f)
			{
				m_fBobAmp = 0.0f;
			}
		}
		else
		{
			m_fBobAmp = 0.0f;
		}
	}
	else  // We're moving...
	{
		s_fBobDecayStartTime = -1.0f;

		// If we just started bobing, ramp up the bob...

		if (s_fBobStartTime < 0.0f)
		{
			// Calculate what the current bobamp percent is...

			t = m_fBobAmp / g_vtMaxBobAmp.GetFloat();

			s_fBobStartTime = fTime - (g_vtBobDecayTime.GetFloat() * t);
		}

        LTFLOAT fDur = (fTime - s_fBobStartTime);
		if (fDur <= g_vtBobDecayTime.GetFloat())
		{
			t = fDur / g_vtBobDecayTime.GetFloat();	// 0 to 1
			t = WaveFn_SlowOn(t);

			m_fBobAmp = t * g_vtMaxBobAmp.GetFloat();

			if (m_fBobAmp > g_vtMaxBobAmp.GetFloat())
			{
				m_fBobAmp = g_vtMaxBobAmp.GetFloat();
			}
		}
		else
		{
			m_fBobAmp = g_vtMaxBobAmp.GetFloat();
		}
	}


	// Update the bob...

	if (!bZoomed)
	{
		m_fBobHeight = g_vtBobV.GetFloat() * m_fBobAmp * (float)sin(m_fBobPhase);
	}


	// Update the weapon model bobbing...

	IClientWeaponBase *pClientWeapon = g_pPlayerMgr->GetCurrentClientWeapon();
	if ( pClientWeapon && !bZoomed )
	{
		LTFLOAT fSwayHeight = g_vtSwayV.GetFloat() * m_fBobAmp * (float)sin(m_fSwayPhase * 2);
		LTFLOAT fSwayWidth  = g_vtSwayH.GetFloat() * m_fBobAmp * (float)sin(m_fSwayPhase - (MATH_PI/3));

		// No weapon bob if vehicle mode...

		if (pMoveMgr->GetVehicleMgr()->IsVehiclePhysics())
		{
			fSwayWidth = fSwayHeight = 0.0f;
		}

		fSwayHeight *= g_vtWeaponSway.GetFloat();
		fSwayWidth *= g_vtWeaponSway.GetFloat();

		pClientWeapon->UpdateBob(fSwayWidth, fSwayHeight);
	}


	// Update the head cant...

	if (!bZoomed && !pMoveMgr->GetVehicleMgr()->IsVehiclePhysics())
	{
		LTFLOAT fRollAdjust = g_vtRollAdjust.GetFloat() * (float)sin(m_fSwayPhase);

		// Turn head bob up/down...

		fRollAdjust *= g_vtHeadBobAdjust.GetFloat();

		if (m_fBobAmp == 0.0f)
		{
			fRollAdjust = 0.0f;
		}

		g_pPlayerMgr->SetRoll(fRollAdjust);
	}


	// Play foot step sounds at the appropriate time...

	if (bMoving && bFootstep)
	{
		CCharacterFX* pCharFX = pMoveMgr->GetCharacterFX();
		if (pCharFX)
		{
			SurfaceType eSurf = pMoveMgr->GetStandingOnSurface();
			eSurf = (eSurf == ST_UNKNOWN ? pCharFX->GetLastSurface() : eSurf);

			LTVector vPos;
			g_pLTClient->GetObjectPos(pMoveMgr->GetObject(), &vPos);
			pCharFX->PlayMovementSound(vPos, eSurf, bLeftFoot);
		}
	}
}
Beispiel #4
0
void CFlashLightPlayer::GetLightPositions(LTVector& vStartPos, LTVector& vEndPos, LTVector& vUOffset, LTVector& vROffset)
{
	vStartPos.Init();
	vEndPos.Init();
	vUOffset.Init();
	vROffset.Init();

	CMoveMgr* pMoveMgr = g_pPlayerMgr->GetMoveMgr();
	if (!pMoveMgr) return;

	LTRotation rRot;

	if (pMoveMgr->GetVehicleMgr()->IsVehiclePhysics())
	{
		if (g_pPlayerMgr->IsFirstPerson())
		{
			pMoveMgr->GetVehicleMgr()->GetVehicleLightPosRot(vStartPos, rRot);
		}
		else // 3rd person vehicle
		{
			// Get light pos on 3rd-person vehicle...

			HLOCALOBJ hPlayerObj = g_pLTClient->GetClientObject();
			if (hPlayerObj)
			{
				g_pLTClient->GetObjectRotation(hPlayerObj, &rRot);
				g_pLTClient->GetObjectPos(hPlayerObj, &vStartPos);
			}
		}
	}
	else if (g_pPlayerMgr->IsFirstPerson())
	{
		HOBJECT hCamera = g_pPlayerMgr->GetCamera();
		if (!hCamera) return;

		g_pLTClient->GetObjectRotation(hCamera, &rRot);
		g_pLTClient->GetObjectPos(hCamera, &vStartPos);
	}
	else // 3rd person
	{
		// Get light pos from 3rd-person model...

		HLOCALOBJ hPlayerObj = g_pLTClient->GetClientObject();
		if (hPlayerObj)
		{
			// g_pLTClient->GetObjectRotation(hPlayerObj, &rRot);
			// g_pLTClient->GetObjectPos(hPlayerObj, &vStartPos);

			HMODELSOCKET hSocket;
			if ( LT_OK == g_pModelLT->GetSocket(hPlayerObj, "LeftHand", hSocket) )
			{
				LTransform tf;

				if ( LT_OK == g_pModelLT->GetSocketTransform(hPlayerObj, hSocket, tf, LTTRUE) )
				{
					vStartPos = tf.m_Pos;
					rRot = tf.m_Rot;
				}
			}
		}
	}

	vEndPos = vStartPos + (rRot.Forward() * g_cvarFLLightOffsetForward.GetFloat());

  	if (g_pPlayerMgr->IsFirstPerson())
  	{
  		vROffset = (rRot.Right() * g_cvarFLLightOffsetRight.GetFloat());
  		vUOffset = (rRot.Up() * g_cvarFLLightOffsetUp.GetFloat());

		// Update the Start/End position to addjust for any offset...

		vEndPos += vROffset;
		vEndPos += vUOffset;

		vStartPos += vROffset;
		vStartPos += vUOffset;
  	}
}