📄 movemgr.cpp
字号:
m_pPhysicsLT->GetAcceleration(m_hObject, &vAccel);
// Get current velocity
m_pPhysicsLT->GetVelocity(m_hObject, &vMyVel);
DFLOAT fMyVelMag = VEC_MAG(vMyVel);
// BEGIN 10/6/98 Kevin additions ////////////////////////////////////
// KEVIN's ASSY ADDITIONS 1/9/99
m_fSwimVel = (m_dwControlFlags & CTRLFLAG_RUN) ? DEFAULT_SWIM_VEL : DEFAULT_SWIM_VEL/2.0f;
m_fLadderVel = (m_dwControlFlags & CTRLFLAG_RUN) ? DEFAULT_LADDER_VEL : DEFAULT_LADDER_VEL/2.0f;
fMoveVel = m_fMoveVel;
if (m_dwControlFlags & CTRLFLAG_RUN)
{
fMoveVel *= 1.5;
}
if (((m_dwControlFlags & CTRLFLAG_CROUCH) || m_bForcedCrouch) && !bFreeMovement)
{
fMoveVel /= 2;
}
// Use swim vel if all the way in water or on surface but not standing on something.
if( m_bBodyInLiquid )
fMaxMoveVel = m_fSwimVel;
// Use ladder velocity
else if( m_bBodyOnLadder )
fMaxMoveVel = m_fLadderVel;
// Use regular velocity
else
fMaxMoveVel = fMoveVel;
// Cap Velocity for joystick or other velocity related input device
{
fOrigMaxMoveVel = fMaxMoveVel;
DBOOL OverrideForwardBackward = ((m_dwControlFlags & CTRLFLAG_FORWARD) || (m_dwControlFlags & CTRLFLAG_BACKWARD));
DBOOL OverrideLeftRight = ((m_dwControlFlags & CTRLFLAG_STRAFELEFT) || (m_dwControlFlags & CTRLFLAG_STRAFERIGHT));
if ((m_bUseAxisForwardBackward || m_bUseAxisLeftRight) && !(OverrideForwardBackward && OverrideLeftRight))
{
float fLeftRightCap = fMaxMoveVel;
float fForwardBackwardCap = fMaxMoveVel;
if (m_bUseAxisForwardBackward && !OverrideForwardBackward)
{
fForwardBackwardCap = fMaxMoveVel * m_fAxisForwardBackwardVel;
}
if (m_bUseAxisLeftRight && !OverrideLeftRight)
{
fLeftRightCap = fMaxMoveVel * m_fAxisLeftRightVel;
}
fMaxMoveVel = (float)sqrt(fForwardBackwardCap*fForwardBackwardCap + fLeftRightCap*fLeftRightCap);
if (fMaxMoveVel > fOrigMaxMoveVel) fMaxMoveVel = fOrigMaxMoveVel;
}
}
fMaxMoveAccel = ( m_bBodyOnLadder ) ? fMaxMoveVel * fDragCoeff * 0.5f : fMaxMoveVel * fDragCoeff;
// KEVIN's ASSY ADDITIONS 1/9/99
if (!m_bBodyInLiquid) m_bSwimmingJump = DFALSE;
// Limit velocity when in certain containers...
if (m_bBodyOnLadder || m_bBodyOnConveyor)
{
if (fMyVelMag > m_fLadderVel)
{
VEC_NORM(vMyVel);
VEC_MULSCALAR(vMyVel, vMyVel, m_fLadderVel);
}
}
else if ( m_bBodyInLiquid && ( bHeadInLiquid || !m_bOnGround ))
{
if (fMyVelMag > m_fSwimVel)
{
VEC_NORM(vMyVel);
VEC_MULSCALAR(vMyVel, vMyVel, m_fSwimVel);
if (m_bSwimmingJump) // Keep setting jump speed until I jump out
vMyVel.y = m_fJumpVel * 0.75f;
}
}
// END 10/6/98 Kevin additions ////////////////////////////////////
DRotation myRot;
m_pClientShell->GetCameraRotation(&myRot);
m_pClientDE->SetObjectRotation(m_hObject, &myRot);
// See if dead
if (!IsDead())
{
// get the object's vectors
m_pClientDE->GetRotationVectors(&myRot, &vUp, &vRight, &vForward);
if (m_pClientShell->IsSpectatorMode())
{
// DVector vel;
// VEC_INIT(vel);
// m_pPhysicsLT->SetVelocity(m_hObject, &vel);
fMaxMoveAccel = 1.0f;
fMaxMoveVel = 500.0f;
}
else if (!bFreeMovement && !bInLiquid)
{
// Only want x and z components for movement
vRight.y = 0;
VEC_NORM(vRight)
vForward.y = 0;
VEC_NORM(vForward)
}
// Set acceleration based on player controls
// Move forward/backwards
if ((m_dwControlFlags & CTRLFLAG_FORWARD) && !m_bMovementBlocked)
{
fMoveAccel += fMaxMoveAccel;
bLateralMovement = DTRUE;
}
if ((m_dwControlFlags & CTRLFLAG_BACKWARD) && !m_bMovementBlocked)
{
fMoveAccel += -fMaxMoveAccel;
bLateralMovement = DTRUE;
}
/*
// set the movement for velocity axis
if (m_bUseAxisForwardBackward || m_bUseAxisLeftRight)
{
DVector vTemp;
// get current velocity
DVector velCurrent;
m_pPhysicsLT->GetVelocity(m_hObject, &velCurrent);
if (m_bUseAxisForwardBackward)
{
// figure out current velocity component forward
float fVelCurrentForward;
fVelCurrentForward = VEC_DOT(vForward, velCurrent);
// is joystick pointing forward?
if (m_fAxisForwardBackwardVel > m_fAxisForwardBackwardDeadZone)
{
// check if we are going to apply acceleration forward
if (fVelCurrentForward < (m_fAxisForwardBackwardVel * fOrigMaxMoveVel))
{
// VEC_MULSCALAR(vTemp, vForward, fMoveAccel);
// VEC_ADD(vAccel, vAccel, vTemp);
fMoveAccel += fMaxMoveAccel;
}
}
// is joystick pointing backward?
else if (m_fAxisForwardBackwardVel < -m_fAxisForwardBackwardDeadZone)
{
// check if we are going to apply acceleration backward
if (fVelCurrentForward > (m_fAxisForwardBackwardVel * fOrigMaxMoveVel))
{
// VEC_MULSCALAR(vTemp, vForward, -fMoveAccel);
// VEC_ADD(vAccel, vAccel, vTemp);
fMoveAccel -= fMaxMoveAccel;
}
}
}
if (m_bUseAxisLeftRight)
{
// figure out current velocity component to the right
float fVelCurrentRight;
fVelCurrentRight = VEC_DOT(vRight, velCurrent);
// is joystick pointing right?
if (m_fAxisLeftRightVel > m_fAxisLeftRightDeadZone)
{
// check if we are going to apply acceleration right
if (fVelCurrentRight < (m_fAxisLeftRightVel * fOrigMaxMoveVel))
{
// VEC_MULSCALAR(vTemp, vRight, fMoveAccel);
// VEC_ADD(vAccel, vAccel, vTemp);
fStrafeAccel += +fMaxMoveAccel;
bLateralMovement = DTRUE;
}
}
// is joystick pointing left?
else if (m_fAxisLeftRightVel < -m_fAxisLeftRightDeadZone)
{
// check if we are going to apply acceleration left
if (fVelCurrentRight > (m_fAxisLeftRightVel * fOrigMaxMoveVel))
{
// VEC_MULSCALAR(vTemp, vRight, -fMoveAccel);
// VEC_ADD(vAccel, vAccel, vTemp);
fStrafeAccel += -fMaxMoveAccel;
bLateralMovement = DTRUE;
}
}
}
}
*/
if (!(m_pClientShell->GetCDataFlags() & CDATA_MOUSEAIMING) && !m_bMovementBlocked)
{
fMaxMoveAccel *= 2; // [blg] allow a little more acceleration when moving with the mouse
fMoveAccel += -(fMouseAxis1) * fMaxMoveAccel * 10.0f; // [blg] 01/25/99 turned mouse movement back on
m_dwControlFlags |= CTRLFLAG_FORWARD;
bLateralMovement = DTRUE;
}
if (fMoveAccel > fMaxMoveAccel)
fMoveAccel = fMaxMoveAccel;
else if (fMoveAccel < -fMaxMoveAccel)
fMoveAccel = -fMaxMoveAccel;
VEC_MULSCALAR(vForward, vForward, fMoveAccel)
VEC_ADD(vAccel, vAccel, vForward)
// Strafe.. Check for strafe modifier first
if (m_dwControlFlags & CTRLFLAG_STRAFE)
{
if (m_dwControlFlags & CTRLFLAG_LEFT)
fStrafeAccel += -fMaxMoveAccel;
if (m_dwControlFlags & CTRLFLAG_RIGHT)
fStrafeAccel += fMaxMoveAccel;
fStrafeAccel += (fMouseAxis0) * fMaxMoveAccel * 4.0f; // [blg] 01/25/99 turned mouse movement back on
bLateralMovement = DTRUE;
}
// Check individual strafe commands
if (m_dwControlFlags & CTRLFLAG_STRAFELEFT)
{
fStrafeAccel += -fMaxMoveAccel;
bLateralMovement = DTRUE;
}
if (m_dwControlFlags & CTRLFLAG_STRAFERIGHT)
{
fStrafeAccel += fMaxMoveAccel;
bLateralMovement = DTRUE;
}
if (fStrafeAccel > fMaxMoveAccel)
fStrafeAccel = fMaxMoveAccel;
else if (fStrafeAccel < -fMaxMoveAccel)
fStrafeAccel = -fMaxMoveAccel;
VEC_MULSCALAR(vRight, vRight, fStrafeAccel)
VEC_ADD(vAccel, vAccel, vRight)
// tone down run-strafing, but not too much.
DFLOAT fAccelMag = VEC_MAG(vAccel);
DFLOAT fMaxRunStrafeAccel = (DFLOAT)sqrt((fMaxMoveAccel * fMaxMoveAccel) * 2);
if (fAccelMag > fMaxRunStrafeAccel)
{
VEC_MULSCALAR(vAccel, vAccel, (fMaxRunStrafeAccel/fAccelMag));
}
DBOOL bSteep = DFALSE;
if (!m_pClientShell->IsSpectatorMode() && !m_bMovementBlocked)
{
// Make sure the slope isn't too steep to climb or jump up (prevent jump-skip)
if (m_bOnGround && !bFreeMovement)
{
// If standing on something, tilt the acceleration so it's aligned with
// the surface.
DVector &v = collisionInfo.m_Plane.m_Normal;
if ((v.z + v.x) > v.y) // Check for slope > 45 degrees
{
vAccel.y -= 4000.0f; // Just to make sure I slide down
bSteep = DTRUE;
}
else
{
TiltVectorToPlane(&vAccel, &collisionInfo.m_Plane.m_Normal);
}
}
// See if we just broke the surface of water...
if ((IsLiquid(m_eLastContainerCode) && !bHeadInLiquid) && !m_bOnGround && !m_bBodyOnLadder)
{
m_bSwimmingOnSurface = DTRUE;
}
else if (bHeadInLiquid) // See if we went back under...
{
m_bSwimmingOnSurface = DFALSE;
m_bCanSwimJump = DTRUE;
}
// See if we landed (after falling)...
if (!bFreeMovement && m_bFalling && m_bOnGround)
{
/* // See if we should play a landing sound
if ((m_fMaxFallPos - m_fMinFallPos) > 56.0f && !m_bPowerupActivated[PU_INCORPOREAL])
{
char szSound[MAX_CS_FILENAME_LEN+1];
if (GetLandingSound(szSound))
{
PlayPlayerSound(szSound, 200.0f, 70, DFALSE, SOUNDPRIORITY_LOW);
}
}
*/
m_startFall = -1.0;
}
else if (bFreeMovement)
{
m_startFall = -1.0;
}
// now update m_bFalling
m_bFalling = m_bOnGround ? DFALSE : DTRUE;
/* if (m_bFalling)
{
if (m_startFall < 0)
{
m_startFall = m_pClientDE->GetTime();
m_fMinFallPos = m_fMaxFallPos = vMyPos.y;
}
else
{
if (vMyPos.y > m_fMaxFallPos)
m_fMaxFallPos = vMyPos.y;
if (vMyPos.y < m_fMinFallPos)
m_fMinFallPos = vMyPos.y;
}
}
*/
// Jumping
if (m_dwControlFlags & CTRLFLAG_JUMP)
{
// If we are in a container that supports free movement, see if we are
// moving up or down...
if (bFreeMovement)
{
vAccel.y += fMaxMoveAccel;
// m_bLastJumpCommand = DFALSE;
}
else if (!m_bLastJumpCommand)
{
// BEGIN 10/5/98 Kevin additions ////////////////////////////////////
// Handling jumping out of water...
if (m_bBodyInLiquid && !bHeadInLiquid)
{
if (m_bCanSwimJump)
{
m_bSwimmingJump = DTRUE;
m_bCanSwimJump = DFALSE;
}
// If our head is out of the liquid and we're standing on the
// ground, let us jump out of the water...
else if (m_bOnGround)
{
m_bSwimmingJump = DTRUE;
}
if (m_bSwimmingJump)
{
m_bSwimmingOnSurface = DFALSE;
vMyVel.y += m_fJumpVel * 0.75f;
m_bLastJumpCommand = DTRUE;
m_bOnGround = DFALSE;
bFreeMovement = DFALSE;
}
}
else if (m_bOnGround && !bSteep)
{
if (m_bForcedCrouch)
vMyVel.y += m_fJumpVel * 0.75f;
else
vMyVel.y += m_fJumpVel;
// Play the jump sound
g_pBloodClientShell->GetVoiceMgr()->PlayEventSound(g_pBloodClientShell->GetCharacter(), VME_JUMP);
m_bLastJumpCommand = DTRUE;
m_bOnGround = DFALSE;
}
}
}
else
m_bLastJumpCommand = DFALSE;
// Crouching
if (m_dwControlFlags & CTRLFLAG_CROUCH)
{
if ((bInLiquid || bFreeMovement) && !m_bOnGround)
{
vAccel.y -= fMaxMoveAccel;
}
else
{
m_bLastCrouchCommand = DTRUE;
m_bForcedCrouch = DTRUE;
}
}
else // Stand up again
{
m_bLastCrouchCommand = DFALSE;
}
}
}
// Calculate drag for in-air movement, we want air movement consistent
// with ground movement. fDragCoeff needs to be the same as the object's
// friction coefficient.
DVector vAirVel;
// No air friction in liquid
// if( !m_bBodyInLiquid )
if( !m_bBodyInLiquid && !m_bBodyOnLadder && !m_bBodyOnConveyor )
{
VEC_COPY(vAirVel, vMyVel);
// Apply drag to y when going down, but not going up.
if (!m_bOnGround)
{
// Don't add friction if we are jumping up
if (vAirVel.y >= 0.0f )
vAirVel.y = 0.0f;
else
{
vAirVel.y = DCLAMP(vAirVel.y/2.0f, -25.0f, 0.0f);
}
}
DFLOAT fVel = VEC_MAGSQR(vAirVel);
// if (!bFreeMovement && !m_bOnGround && fVel > 0.01f)
if (!bFreeMovement && fVel > 0.01f )
{
DFLOAT fDragAccel = fDragCoeff;
VEC_MULSCALAR(vAirVel, vAirVel, -fDragAccel);
VEC_ADD(vAccel, vAccel, vAirVel);
}
}
if (!m_pClientShell->IsSpectatorMode())
{
// ADDED BY ANDY 9-20-98
if(m_bSlowMode)
{
VEC_MULSCALAR(vMyVel, vMyVel, 0.5f);
if(m_pClientDE->GetTime() > m_fSlowTime)
m_bSlowMode = DFALSE;
}
// Cap horizontal velcity at max to make sure.
DFLOAT fYVel = vMyVel.y;
vMyVel.y = 0.0f;
DFLOAT fMag = VEC_MAG(vMyVel);
fMaxMoveVel = (DFLOAT)sqrt(fMaxMoveVel * fMaxMoveVel * 2);
if (fMag > fMaxMoveVel)
{
fMag = fMaxMoveVel / fMag;
VEC_MULSCALAR(vMyVel, vMyVel, fMag);
}
vMyVel.y = fYVel;
m_pPhysicsLT->SetVelocity(m_hObject, &vMyVel);
}
else // m_bSpectatorMode
{
if (bLateralMovement)
{
VEC_NORM(vAccel);
VEC_MULSCALAR(vAccel, vAccel, fMaxMoveVel);
}
else
{
VEC_INIT(vAccel);
}
m_pPhysicsLT->SetVelocity(m_hObject, &vAccel);
}
if (m_bLastJumpCommand && vMyVel.y > 0 && vAccel.y > 0)
vAccel.y = 0;
m_pPhysicsLT->SetAcceleration(m_hObject, &vAccel);
// Reset these value
m_bBodyInLiquid = DFALSE;
m_bBodyOnLadder = DFALSE;
m_bBodyOnConveyor = DFALSE;
m_eLastContainerCode = m_pClientShell->GetCurContainerCode();
}
void CMoveMgr::UpdatePushers()
{
DLink *pCur, *pNext;
Pusher *pPusher;
DVector myPos, pushVec, vel;
float dist, velocity;
CollisionInfo info;
ClientIntersectQuery iQuery;
ClientIntersectInfo iInfo;
if(!m_hObject || !m_pClientDE || !m_pPhysicsLT)
return;
//frameTime = m_pClientDE->GetFrameTime();
m_pClientDE->GetObjectPos(m_hObject, &myPos);
for(pCur=m_Pushers.m_pNext; pCur != &m_Pushers; pCur=pNext)
{
pNext = pCur->m_pNext;
pPusher = (Pusher*)pCur->m_pData;
pPusher->m_Delay -= m_FrameTime;
if(pPusher->m_Delay <= 0.0f)
{
pPusher->m_TimeLeft -= m_FrameTime;
if(pPusher->m_TimeLeft <= 0.0f)
{
// Expired..
dl_Remove(&pPusher->m_Link);
delete pPusher;
}
else
{
// Are we within range?
dist = VEC_DIST(pPusher->m_Pos, myPos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -