2021-07-19 06:36:19 +00:00
|
|
|
/*
|
2022-07-07 16:10:14 +00:00
|
|
|
* Copyright (c) 2016-2022 Vera Visions LLC.
|
2021-07-19 06:36:19 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2022-07-07 16:10:14 +00:00
|
|
|
*/
|
2021-07-19 06:36:19 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float m_flSpeed;
|
|
|
|
float m_flFracSin;
|
|
|
|
float m_flTime;
|
|
|
|
float m_flMove;
|
|
|
|
float m_flDelta;
|
|
|
|
int m_iCycle;
|
|
|
|
} g_camBobVars[4], *pCamBob;
|
|
|
|
|
|
|
|
/* tilts the camera for a head-bob like effect when moving */
|
|
|
|
void
|
|
|
|
Camera_RunBob(__inout vector camera_angle)
|
|
|
|
{
|
2021-08-01 06:53:21 +00:00
|
|
|
if (!autocvar(v_cambob, 1, "Enables bobbing effect for the first-person camera"))
|
2021-07-19 06:36:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int s = (float)getproperty(VF_ACTIVESEAT);
|
|
|
|
pCamBob = &g_camBobVars[s];
|
|
|
|
|
|
|
|
/* we don't really care about the vertical velocity */
|
|
|
|
vector speed = pSeat->m_vecPredictedVelocity;
|
|
|
|
speed[2] = 0.0f;
|
|
|
|
pCamBob->m_flSpeed = vlen(speed);
|
|
|
|
|
|
|
|
/* don't bother on low speeds */
|
|
|
|
if ( pCamBob->m_flSpeed < 5.0f ) {
|
|
|
|
pCamBob->m_flMove = 0.0f;
|
|
|
|
pCamBob->m_flTime = 0.0f; /* progress has halted, start anew */
|
|
|
|
return;
|
|
|
|
} else if (pSeat->m_ePlayer.flags & FL_ONGROUND) {
|
|
|
|
pCamBob->m_flMove = clframetime * (pCamBob->m_flSpeed * 0.01);
|
|
|
|
}
|
|
|
|
|
|
|
|
pCamBob->m_flTime = (pCamBob->m_flTime += pCamBob->m_flMove);
|
|
|
|
pCamBob->m_flFracSin = fabs(sin(pCamBob->m_flTime * M_PI));
|
|
|
|
pCamBob->m_iCycle = (int)pCamBob->m_flTime;
|
|
|
|
pCamBob->m_flDelta = (pCamBob->m_flFracSin * 0.0025f) * pCamBob->m_flSpeed;
|
|
|
|
|
|
|
|
camera_angle[0] += pCamBob->m_flDelta;
|
|
|
|
|
|
|
|
if (pCamBob->m_iCycle & 1) {
|
|
|
|
pCamBob->m_flDelta = -pCamBob->m_flDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
camera_angle[2] += pCamBob->m_flDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* applies a tilt to the camera for when we're strafing left to right */
|
2021-07-20 10:18:45 +00:00
|
|
|
void
|
2021-07-19 06:36:19 +00:00
|
|
|
Camera_StrafeRoll(__inout vector camera_angle)
|
|
|
|
{
|
2021-08-01 06:53:21 +00:00
|
|
|
if (!autocvar(v_camroll, 0, "Enables strafe-roll for the first-person camera"))
|
2021-07-19 06:36:19 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
float roll;
|
|
|
|
makevectors(camera_angle);
|
|
|
|
|
|
|
|
roll = dotproduct(pSeat->m_vecPredictedVelocity, v_right);
|
|
|
|
roll *= 0.015f;
|
|
|
|
|
|
|
|
camera_angle[2] += roll;
|
|
|
|
}
|