This repository has been archived on 2022-06-27. You can view files and clone it, but cannot push or open issues or pull requests.
Xash3DArchive/engine/client/cl_phys.c

121 lines
2.8 KiB
C
Raw Normal View History

2008-12-25 22:00:00 +01:00
//=======================================================================
// Copyright XashXT Group 2008 <20>
// cl_physics.c - client physic and prediction
//=======================================================================
2007-06-21 22:00:00 +02:00
2008-06-09 22:00:00 +02:00
#include "common.h"
2007-06-21 22:00:00 +02:00
#include "client.h"
2008-11-25 22:00:00 +01:00
#include "matrix_lib.h"
2008-08-30 22:00:00 +02:00
#include "const.h"
2009-11-26 22:00:00 +01:00
#include "pm_defs.h"
2008-12-25 22:00:00 +01:00
2009-01-11 22:00:00 +01:00
/*
================
CL_CheckVelocity
================
*/
void CL_CheckVelocity( edict_t *ent )
{
int i;
2009-11-26 22:00:00 +01:00
float maxvel;
maxvel = fabs( clgame.movevars.maxvelocity );
2009-01-11 22:00:00 +01:00
// bound velocity
for( i = 0; i < 3; i++ )
{
2009-11-26 22:00:00 +01:00
if( IS_NAN( ent->v.velocity[i] ))
2009-01-11 22:00:00 +01:00
{
2009-11-26 22:00:00 +01:00
MsgDev( D_INFO, "Got a NaN velocity on %s\n", STRING( ent->v.classname ));
2009-01-11 22:00:00 +01:00
ent->v.velocity[i] = 0;
}
2009-11-26 22:00:00 +01:00
if( IS_NAN( ent->v.origin[i] ))
2009-01-11 22:00:00 +01:00
{
2009-11-26 22:00:00 +01:00
MsgDev( D_INFO, "Got a NaN origin on %s\n", STRING( ent->v.classname ));
2009-01-11 22:00:00 +01:00
ent->v.origin[i] = 0;
}
}
2009-11-26 22:00:00 +01:00
if( VectorLength( ent->v.velocity ) > maxvel )
VectorScale( ent->v.velocity, maxvel / VectorLength( ent->v.velocity ), ent->v.velocity );
2009-01-11 22:00:00 +01:00
}
2008-07-30 22:00:00 +02:00
2009-01-23 22:00:00 +01:00
/*
=============
CL_CheckWater
=============
*/
bool CL_CheckWater( edict_t *ent )
{
int cont;
vec3_t point;
point[0] = ent->v.origin[0];
point[1] = ent->v.origin[1];
point[2] = ent->v.origin[2] + ent->v.mins[2] + 1;
ent->v.waterlevel = 0;
2009-11-26 22:00:00 +01:00
ent->v.watertype = CONTENTS_EMPTY;
2009-01-23 22:00:00 +01:00
cont = CL_PointContents( point );
2009-11-26 22:00:00 +01:00
if( cont <= CONTENTS_WATER )
2009-01-23 22:00:00 +01:00
{
ent->v.watertype = cont;
ent->v.waterlevel = 1;
2009-11-26 22:00:00 +01:00
point[2] = ent->v.origin[2] + (ent->v.mins[2] + ent->v.maxs[2]) * 0.5f;
if( CL_PointContents( point ) <= CONTENTS_WATER )
2009-01-23 22:00:00 +01:00
{
ent->v.waterlevel = 2;
point[2] = ent->v.origin[2] + ent->v.view_ofs[2];
2009-11-26 22:00:00 +01:00
if( CL_PointContents( point ) <= CONTENTS_WATER )
2009-01-23 22:00:00 +01:00
ent->v.waterlevel = 3;
}
2009-11-26 22:00:00 +01:00
if( cont <= CONTENTS_CURRENT_0 && cont >= CONTENTS_CURRENT_DOWN )
2008-07-03 22:00:00 +02:00
{
2009-11-26 22:00:00 +01:00
static vec3_t current_table[] =
{
{ 1, 0, 0 },
{ 0, 1, 0 },
{-1, 0, 0 },
{ 0, -1, 0 },
{ 0, 0, 1 },
{ 0, 0, -1}
};
float speed = 150.0f * ent->v.waterlevel / 3.0f;
float *dir = current_table[CONTENTS_CURRENT_0 - cont];
VectorMA( ent->v.basevelocity, speed, dir, ent->v.basevelocity );
2008-07-03 22:00:00 +02:00
}
2007-06-21 22:00:00 +02:00
}
2009-11-26 22:00:00 +01:00
return ent->v.waterlevel > 1;
2009-12-05 22:00:00 +01:00
}
/*
================
CL_UpdateBaseVelocity
================
*/
void CL_UpdateBaseVelocity( edict_t *ent )
{
if( ent->v.flags & FL_ONGROUND )
{
edict_t *groundentity = ent->v.groundentity;
if( CL_IsValidEdict( groundentity ))
{
// On conveyor belt that's moving?
if( groundentity->v.flags & FL_CONVEYOR )
{
vec3_t new_basevel;
VectorScale( groundentity->v.movedir, groundentity->v.speed, new_basevel );
if( ent->v.flags & FL_BASEVELOCITY )
VectorAdd( new_basevel, ent->v.basevelocity, new_basevel );
ent->v.flags |= FL_BASEVELOCITY;
VectorCopy( new_basevel, ent->v.basevelocity );
}
}
}
2009-11-26 22:00:00 +01:00
}