update cl_entities?

This commit is contained in:
Daniel Wolf 2020-03-09 01:11:53 -04:00
parent e952dfe401
commit ef14f634ef
No known key found for this signature in database
GPG Key ID: E8FEA551AA478F9A
7 changed files with 225 additions and 22 deletions

View File

@ -29,7 +29,7 @@ list(APPEND CMAKE_PREFIX_PATH /usr/local)
# -Wall -> More warnings
# -fno-strict-aliasing -> Quake 2 is far away from strict aliasing
# -fwrapv -> Make signed integer overflows defined
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -fno-strict-aliasing -fwrapv")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -fno-strict-aliasing -fwrapv -Werror=implicit-function-declaration")
# Switch of some annoying warnings
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")

View File

@ -664,6 +664,13 @@ AdaptFov(float fov, float w, float h)
return (atanf(tanf(fov / 360.0f * pi) * (w / h * 0.75f)) / pi * 360.0f);
}
void CL_ProjectSource (vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result)
{
result[0] = point[0] + forward[0] * distance[0] + right[0] * distance[1];
result[1] = point[1] + forward[1] * distance[0] + right[1] * distance[1];
result[2] = point[2] + forward[2] * distance[0] + right[2] * distance[1] + distance[2];
}
/*
* Sets cl.refdef view values
*/
@ -741,27 +748,64 @@ CL_CalcViewValues(void)
/* if not running a demo or on a locked frame, add the local angle movement */
if (cl.frame.playerstate.pmove.pm_type < PM_DEAD)
{
/* use predicted values */
for (i = 0; i < 3; i++)
if (vr_enabled->value)
{
cl.refdef.viewangles[i] = cl.predicted_angles[i];
VectorAdd(cl.viewangles, cl.bodyangles, cl.refdef.viewangles);
cl.refdef.viewangles[YAW] += cl.predicted_angles[YAW] - cl.aimangles[YAW];
for (i=0 ; i<3 ; i++)
{
cl.refdef.aimangles[i] = cl.predicted_angles[i] + LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
}
} else {
for (i=0 ; i<3 ; i++)
{
cl.refdef.aimangles[i] = cl.refdef.viewangles[i] =
cl.predicted_angles[i] + LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
}
}
/* use predicted values */
// for (i = 0; i < 3; i++)
// {
// cl.refdef.viewangles[i] = cl.predicted_angles[i];
// }
}
else
{
/* just use interpolated values */
for (i = 0; i < 3; i++)
vec3_t temp = {0, 0, 0};
cl.bodyangles[PITCH] = 0;
VectorCopy(cl.bodyangles,cl.aimangles);
VectorSet(cl.aimdelta,0,0,0);
VectorSet(cl.viewangles,0,0,0);
if (vr_enabled->value)
{
cl.refdef.viewangles[i] = LerpAngle(ops->viewangles[i],
ps->viewangles[i], lerp);
VR_GetOrientation(cl.refdef.viewangles);
for (i=0 ; i<3 ; i++)
{
cl.refdef.aimangles[i] = temp[i] = LerpAngle (ops->viewangles[i], ps->viewangles[i], lerp);
cl.refdef.aimangles[i] += LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
}
cl.refdef.viewangles[YAW] += temp[YAW];
} else {
for (i = 0 ; i<3 ; i++) {
cl.refdef.aimangles[i] = cl.refdef.viewangles[i] =
LerpAngle (ops->viewangles[i], ps->viewangles[i], lerp) + LerpAngle (ops->kick_angles[i], ps->kick_angles[i], lerp);
}
}
/* just use interpolated values */
// for (i = 0; i < 3; i++)
// {
// cl.refdef.viewangles[i] = LerpAngle(ops->viewangles[i],
// ps->viewangles[i], lerp);
// }
}
for (i = 0; i < 3; i++)
{
cl.refdef.viewangles[i] += LerpAngle(ops->kick_angles[i],
ps->kick_angles[i], lerp);
}
// for (i = 0; i < 3; i++)
// {
// cl.refdef.viewangles[i] += LerpAngle(ops->kick_angles[i],
// ps->kick_angles[i], lerp);
// }
AngleVectors(cl.refdef.viewangles, cl.v_forward, cl.v_right, cl.v_up);
@ -784,6 +828,39 @@ CL_CalcViewValues(void)
/* add the weapon */
CL_AddViewWeapon(ps, ops);
//if (vr_enabled->value)
{
vec3_t forward, right, distance;
vec3_t gun_origin;
vec3_t gun_angles;
trace_t trace;
int32_t i;
static const vec3_t handoffsets[3] = {
{8,8,-8},
{8,-8,-8},
{8,0,-8}
};
for (i = 0; i < 3; i++)
{
gun_origin[i] = cl.refdef.vieworg[i] + ops->gunoffset[i]
+ cl.lerpfrac * (ps->gunoffset[i] - ops->gunoffset[i]);
}
VectorCopy(cl.refdef.aimangles, gun_angles);
AngleVectors(gun_angles,forward,right,NULL);
VectorCopy(handoffsets[(int32_t)hand->value], distance);
CL_ProjectSource(gun_origin,distance,forward,right,cl.refdef.aimstart);
VectorMA(cl.refdef.aimstart,8192,forward,distance);
trace = CL_PMSurfaceTrace(cl.playernum + 1, cl.refdef.aimstart,NULL,NULL,distance,MASK_SHOT | MASK_OPAQUE);
VectorCopy(trace.endpos,cl.refdef.aimend);
}
}
/*

View File

@ -161,6 +161,82 @@ CL_ClipMoveToEntities(vec3_t start, vec3_t mins, vec3_t maxs,
}
}
/*
====================
CL_ClipMoveToEntities2
Similar to above, but uses entnum as reference.
====================
*/
void CL_ClipMoveToEntities2 (int32_t entnum, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, trace_t *tr)
{
int32_t i, x, zd, zu;
trace_t trace;
int32_t headnode;
float *angles;
entity_state_t *ent;
int32_t num;
cmodel_t *cmodel;
vec3_t bmins, bmaxs;
for (i=0 ; i<cl.frame.num_entities ; i++)
{
num = (cl.frame.parse_entities + i)&(MAX_PARSE_ENTITIES-1);
ent = &cl_parse_entities[num];
if (!ent->solid)
continue;
// Don't clip against the passed entity number
if (ent->number == entnum)
continue;
if (ent->solid == 31)
{ // special value for bmodel
cmodel = cl.model_clip[ent->modelindex];
if (!cmodel)
continue;
headnode = cmodel->headnode;
angles = ent->angles;
}
else
{ // encoded bbox
x = 8*(ent->solid & 31);
zd = 8*((ent->solid>>5) & 31);
zu = 8*((ent->solid>>10) & 63) - 32;
bmins[0] = bmins[1] = -x;
bmaxs[0] = bmaxs[1] = x;
bmins[2] = -zd;
bmaxs[2] = zu;
headnode = CM_HeadnodeForBox (bmins, bmaxs);
angles = vec3_origin; // boxes don't rotate
}
if (tr->allsolid)
return;
trace = CM_TransformedBoxTrace (start, end,
mins, maxs, headnode, MASK_PLAYERSOLID,
ent->origin, angles);
if (trace.allsolid || trace.startsolid ||
trace.fraction < tr->fraction)
{
trace.ent = (struct edict_s *)ent;
if (tr->startsolid)
{
*tr = trace;
tr->startsolid = true;
}
else
*tr = trace;
}
else if (trace.startsolid)
tr->startsolid = true;
}
}
trace_t
CL_PMTrace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
{
@ -180,6 +256,33 @@ CL_PMTrace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
return t;
}
//Knightmare added- this can check using masks, good for checking surface flags
// also checks for bmodels
/*
================
CL_PMSurfaceTrace
================
*/
trace_t CL_PMSurfaceTrace (int32_t playernum, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int32_t contentmask)
{
trace_t t;
if (!mins)
mins = vec3_origin;
if (!maxs)
maxs = vec3_origin;
// check against world
t = CM_BoxTrace (start, end, mins, maxs, 0, contentmask);
if (t.fraction < 1.0)
t.ent = (struct edict_s *)1;
// check all other solid models
CL_ClipMoveToEntities2 (playernum, start, mins, maxs, end, &t);
return t;
}
int
CL_PMpointcontents(vec3_t point)
{

View File

@ -4,7 +4,6 @@
#define CVAR_CLIENT CVAR_ARCHIVE
#define SCR_CenterAlert SCR_CenterPrint
extern float ClampCvar( float min, float max, float value );
extern cvar_t * hand;
void Cvar_SetInteger( const char * var_name, int32_t integer )
{

View File

@ -315,6 +315,7 @@ extern cvar_t *cl_vwep;
extern cvar_t *horplus;
extern cvar_t *cin_force43;
extern cvar_t *vid_fullscreen;
extern cvar_t * hand;
typedef struct
{
@ -547,4 +548,8 @@ void CL_DrawInventory (void);
void CL_PredictMovement (void);
trace_t CL_PMTrace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end);
trace_t CL_PMSurfaceTrace (int32_t playernum, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int32_t contentmask);
void CL_ProjectSource (vec3_t point, vec3_t distance, vec3_t forward, vec3_t right, vec3_t result);
void ThumbstickMove(usercmd_t *cmd, vec3_t leftPos, vec3_t rightPos, qboolean vr);
#endif

View File

@ -98,6 +98,12 @@ typedef struct {
float fov_x, fov_y;
float vieworg[3];
float viewangles[3];
//VR
float aimangles[3];
float aimstart[3];
float aimend[3];
float blend[4]; /* rgba 0-1 full screen blend */
float time; /* time is used to auto animate */
int rdflags; /* RDF_UNDERWATER, etc */

View File

@ -218,6 +218,27 @@ void VectorInverse(vec3_t v);
void VectorScale(vec3_t in, vec_t scale, vec3_t out);
int Q_log2(int val);
#define QuatCopy(a,b) (b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3])
#define QuatClear(a) (a[1]=a[2]=a[3]=0,a[0]=1)
#define QuatNegate(a,b) (b[0]=-a[0],b[1]=-a[1],b[2]=-a[2],b[3]=-a[3])
#define QuatSet(v, w, x, y, z) (v[0] = (w), v[1]=(x), v[2]=(y), v[3]=(z))
#define QuatMagnitude(a) sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3])
#define QuatScale(a,b,c) (c[0]=a[0]*b,c[1]=a[1]*b,c[2]=a[2]*b,c[3]=a[3]*b)
#define QuatConjugate(a,b) (b[0] = a[0], b[1]=-a[1],b[2]=-a[2],b[3]=-a[3])
void AngleClamp(vec_t *angle);
void VectorClamp(vec3_t angles);
void QuatNormalize(vec4_t quat);
void QuatMultiply(vec4_t q1, vec4_t q2, vec4_t out);
void QuatInverse(vec4_t q1, vec4_t out);
void QuatDifference(vec4_t q1, vec4_t q2, vec4_t out);
void LerpQuat(vec4_t q1, vec4_t q2, vec_t fraction, vec4_t out);
void SlerpQuat(vec4_t q1, vec4_t q2, vec_t fraction, vec4_t out);
void QuatToEuler(vec4_t q, vec3_t e);
void EulerToQuat(vec3_t in, vec4_t out);
void QuatToRotation(vec4_t q, float out[4][4]);
void R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3]);
void R_ConcatTransforms(float in1[3][4], float in2[3][4], float out[3][4]);
@ -250,14 +271,6 @@ void RotatePointAroundVector(vec3_t dst,
const vec3_t point,
float degrees);
#define QuatCopy(a,b) (b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3])
#define QuatClear(a) (a[1]=a[2]=a[3]=0,a[0]=1)
#define QuatNegate(a,b) (b[0]=-a[0],b[1]=-a[1],b[2]=-a[2],b[3]=-a[3])
#define QuatSet(v, w, x, y, z) (v[0] = (w), v[1]=(x), v[2]=(y), v[3]=(z))
#define QuatMagnitude(a) sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3])
#define QuatScale(a,b,c) (c[0]=a[0]*b,c[1]=a[1]*b,c[2]=a[2]*b,c[3]=a[3]*b)
#define QuatConjugate(a,b) (b[0] = a[0], b[1]=-a[1],b[2]=-a[2],b[3]=-a[3])
/* ============================================= */
char *COM_SkipPath(char *pathname);