mirror of
https://github.com/ReactionQuake3/reaction.git
synced 2024-11-11 15:52:30 +00:00
PHYSICS, Take 2
This commit is contained in:
parent
54a4a5cc72
commit
8f5e45feb3
2 changed files with 245 additions and 731 deletions
File diff suppressed because it is too large
Load diff
|
@ -5,6 +5,9 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// $Log$
|
||||
// Revision 1.12 2002/04/26 05:29:23 niceass
|
||||
// PHYSICS, Take 2
|
||||
//
|
||||
// Revision 1.11 2002/03/31 03:31:24 jbravo
|
||||
// Compiler warning cleanups
|
||||
//
|
||||
|
@ -29,6 +32,7 @@
|
|||
//
|
||||
// bg_slidemove.c -- part of bg_pmove functionality
|
||||
|
||||
|
||||
#include "q_shared.h"
|
||||
#include "bg_public.h"
|
||||
#include "bg_local.h"
|
||||
|
@ -41,42 +45,78 @@ output: origin, velocity, impacts, stairup boolean
|
|||
|
||||
*/
|
||||
|
||||
#define MIN_STEP_NORMAL 0.7 // can't step up onto very steep slopes
|
||||
#define MAX_CLIP_PLANES 5
|
||||
/*
|
||||
==================
|
||||
PM_SlideMove
|
||||
|
||||
void PM_StepSlideMove_ ( void ) {
|
||||
Returns qtrue if the velocity was clipped in some way
|
||||
==================
|
||||
*/
|
||||
#define MAX_CLIP_PLANES 5
|
||||
qboolean PM_SlideMove( qboolean gravity ) {
|
||||
int bumpcount, numbumps;
|
||||
vec3_t dir;
|
||||
float d;
|
||||
int numplanes;
|
||||
vec3_t planes[MAX_CLIP_PLANES];
|
||||
vec3_t primal_velocity;
|
||||
int i, j;
|
||||
trace_t trace;
|
||||
vec3_t clipVelocity;
|
||||
int i, j, k;
|
||||
trace_t trace;
|
||||
vec3_t end;
|
||||
float time_left;
|
||||
|
||||
numbumps = 4;
|
||||
numplanes = 0;
|
||||
time_left = pml.frametime;
|
||||
float into;
|
||||
vec3_t endVelocity;
|
||||
vec3_t endClipVelocity;
|
||||
|
||||
VectorCopy(pm->ps->velocity, primal_velocity);
|
||||
numbumps = 4;
|
||||
|
||||
for (bumpcount=0 ; bumpcount<numbumps ; bumpcount++) {
|
||||
VectorMA(pm->ps->origin, time_left, pm->ps->velocity, end);
|
||||
VectorCopy (pm->ps->velocity, primal_velocity);
|
||||
|
||||
pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemask);
|
||||
if ( gravity ) {
|
||||
VectorCopy( pm->ps->velocity, endVelocity );
|
||||
endVelocity[2] -= pm->ps->gravity * pml.frametime;
|
||||
pm->ps->velocity[2] = ( pm->ps->velocity[2] + endVelocity[2] ) * 0.5;
|
||||
primal_velocity[2] = endVelocity[2];
|
||||
/* if ( pml.groundPlane ) {
|
||||
// slide along the ground plane
|
||||
PM_ClipVelocity (pm->ps->velocity, pml.groundTrace.plane.normal,
|
||||
pm->ps->velocity, OVERCLIP );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
time_left = pml.frametime;
|
||||
|
||||
// never turn against the ground plane
|
||||
if ( pml.groundPlane ) {
|
||||
numplanes = 1;
|
||||
VectorCopy( pml.groundTrace.plane.normal, planes[0] );
|
||||
} else {
|
||||
numplanes = 0;
|
||||
}
|
||||
|
||||
// never turn against original velocity
|
||||
VectorNormalize2( pm->ps->velocity, planes[numplanes] );
|
||||
numplanes++;
|
||||
|
||||
for ( bumpcount=0 ; bumpcount < numbumps ; bumpcount++ ) {
|
||||
|
||||
// calculate position we are trying to move to
|
||||
VectorMA( pm->ps->origin, time_left, pm->ps->velocity, end );
|
||||
|
||||
// see if we can make it there
|
||||
pm->trace ( &trace, pm->ps->origin, pm->mins, pm->maxs, end, pm->ps->clientNum, pm->tracemask);
|
||||
|
||||
if (trace.allsolid) {
|
||||
// entity is completely trapped in another solid
|
||||
pm->ps->velocity[2] = 0; // don't build up falling damage, but allow sideways acceleration
|
||||
return; // qtrue;
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
if (trace.fraction > 0) {
|
||||
// actually covered some distance
|
||||
VectorCopy (trace.endpos, pm->ps->origin);
|
||||
numplanes = 0;
|
||||
}
|
||||
|
||||
if (trace.fraction == 1) {
|
||||
|
@ -91,44 +131,109 @@ void PM_StepSlideMove_ ( void ) {
|
|||
if (numplanes >= MAX_CLIP_PLANES) {
|
||||
// this shouldn't really happen
|
||||
VectorClear( pm->ps->velocity );
|
||||
break;
|
||||
return qtrue;
|
||||
}
|
||||
|
||||
VectorCopy (trace.plane.normal, planes[numplanes]);
|
||||
numplanes++;
|
||||
|
||||
for (i=0 ; i < numplanes ; i++)
|
||||
{
|
||||
PM_ClipVelocity(pm->ps->velocity, planes[i], pm->ps->velocity, OVERCLIP); //1.01);
|
||||
for (j = 0; j < numplanes; j++)
|
||||
if (DotProduct (pm->ps->velocity, planes[j]) < 0 && j != i) break;
|
||||
|
||||
// Get through all planes okay? Then stop clipping the velocity.
|
||||
if (j == numplanes) break;
|
||||
}
|
||||
|
||||
// Clipped velocity against all planes
|
||||
if (i == numplanes) {
|
||||
if (numplanes != 2) {
|
||||
VectorClear(pm->ps->velocity);
|
||||
//
|
||||
// if this is the same plane we hit before, nudge velocity
|
||||
// out along it, which fixes some epsilon issues with
|
||||
// non-axial planes
|
||||
//
|
||||
for ( i = 0 ; i < numplanes ; i++ ) {
|
||||
if ( DotProduct( trace.plane.normal, planes[i] ) > 0.99 ) {
|
||||
VectorAdd( trace.plane.normal, pm->ps->velocity, pm->ps->velocity );
|
||||
break;
|
||||
}
|
||||
else {
|
||||
CrossProduct (planes[0], planes[1], dir);
|
||||
d = DotProduct (dir, pm->ps->velocity);
|
||||
VectorScale (dir, d, pm->ps->velocity);
|
||||
}
|
||||
}
|
||||
if ( i < numplanes ) {
|
||||
continue;
|
||||
}
|
||||
VectorCopy (trace.plane.normal, planes[numplanes]);
|
||||
numplanes++;
|
||||
|
||||
if (DotProduct (pm->ps->velocity, primal_velocity) <= 0) {
|
||||
VectorClear(pm->ps->velocity);
|
||||
//
|
||||
// modify velocity so it parallels all of the clip planes
|
||||
//
|
||||
|
||||
// find a plane that it enters
|
||||
for ( i = 0 ; i < numplanes ; i++ ) {
|
||||
into = DotProduct( pm->ps->velocity, planes[i] );
|
||||
if ( into >= 0.1 ) {
|
||||
continue; // move doesn't interact with the plane
|
||||
}
|
||||
|
||||
// see how hard we are hitting things
|
||||
if ( -into > pml.impactSpeed ) {
|
||||
pml.impactSpeed = -into;
|
||||
}
|
||||
|
||||
// slide along the plane
|
||||
PM_ClipVelocity (pm->ps->velocity, planes[i], clipVelocity, OVERCLIP );
|
||||
|
||||
// slide along the plane
|
||||
PM_ClipVelocity (endVelocity, planes[i], endClipVelocity, OVERCLIP );
|
||||
|
||||
// see if there is a second plane that the new move enters
|
||||
for ( j = 0 ; j < numplanes ; j++ ) {
|
||||
if ( j == i ) {
|
||||
continue;
|
||||
}
|
||||
if ( DotProduct( clipVelocity, planes[j] ) >= 0.1 ) {
|
||||
continue; // move doesn't interact with the plane
|
||||
}
|
||||
|
||||
// try clipping the move to the plane
|
||||
PM_ClipVelocity( clipVelocity, planes[j], clipVelocity, OVERCLIP );
|
||||
PM_ClipVelocity( endClipVelocity, planes[j], endClipVelocity, OVERCLIP );
|
||||
|
||||
// see if it goes back into the first clip plane
|
||||
if ( DotProduct( clipVelocity, planes[i] ) >= 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// slide the original velocity along the crease
|
||||
CrossProduct (planes[i], planes[j], dir);
|
||||
VectorNormalize( dir );
|
||||
d = DotProduct( dir, pm->ps->velocity );
|
||||
VectorScale( dir, d, clipVelocity );
|
||||
|
||||
CrossProduct (planes[i], planes[j], dir);
|
||||
VectorNormalize( dir );
|
||||
d = DotProduct( dir, endVelocity );
|
||||
VectorScale( dir, d, endClipVelocity );
|
||||
|
||||
// see if there is a third plane the the new move enters
|
||||
for ( k = 0 ; k < numplanes ; k++ ) {
|
||||
if ( k == i || k == j ) {
|
||||
continue;
|
||||
}
|
||||
if ( DotProduct( clipVelocity, planes[k] ) >= 0.1 ) {
|
||||
continue; // move doesn't interact with the plane
|
||||
}
|
||||
|
||||
// stop dead at a tripple plane interaction
|
||||
VectorClear( pm->ps->velocity );
|
||||
return qtrue;
|
||||
}
|
||||
}
|
||||
|
||||
// if we have fixed all interactions, try another move
|
||||
VectorCopy( clipVelocity, pm->ps->velocity );
|
||||
VectorCopy( endClipVelocity, endVelocity );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (pm->ps->pm_time) {
|
||||
VectorCopy (primal_velocity, pm->ps->velocity);
|
||||
if ( gravity ) {
|
||||
VectorCopy( endVelocity, pm->ps->velocity );
|
||||
}
|
||||
|
||||
// don't change velocity if in a timer (FIXME: is this correct?)
|
||||
if ( pm->ps->pm_time ) {
|
||||
VectorCopy( primal_velocity, pm->ps->velocity );
|
||||
}
|
||||
|
||||
return ( bumpcount != 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -137,26 +242,32 @@ PM_StepSlideMove
|
|||
|
||||
==================
|
||||
*/
|
||||
|
||||
void PM_StepSlideMove ( qboolean gravity )
|
||||
{
|
||||
void PM_StepSlideMove( qboolean gravity ) {
|
||||
vec3_t start_o, start_v;
|
||||
vec3_t down_o, down_v;
|
||||
trace_t trace;
|
||||
float DistanceDown, DistanceUp;
|
||||
vec3_t up, down;
|
||||
|
||||
// use the step move
|
||||
/* vec3_t old_normal;
|
||||
float delta0;
|
||||
float delta1;
|
||||
float delta2; */
|
||||
vec3_t tmp_o;
|
||||
vec3_t tmp;
|
||||
|
||||
VectorCopy (pm->ps->origin, start_o);
|
||||
VectorCopy (pm->ps->velocity, start_v);
|
||||
|
||||
PM_StepSlideMove_ ();
|
||||
if ( PM_SlideMove( gravity ) == 0 ) {
|
||||
return; // we got exactly where we wanted to go first try
|
||||
}
|
||||
|
||||
/*
|
||||
VectorCopy(start_o, down);
|
||||
down[2] -= STEPSIZE;
|
||||
pm->trace (&trace, start_o, pm->mins, pm->maxs, down, pm->ps->clientNum, pm->tracemask);
|
||||
VectorSet(up, 0, 0, 1);
|
||||
|
||||
// never step up when you still have up velocity
|
||||
if ( pm->ps->velocity[2] > 0 && (trace.fraction == 1.0 ||
|
||||
DotProduct(trace.plane.normal, up) < 0.7)) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
VectorCopy (pm->ps->origin, down_o);
|
||||
VectorCopy (pm->ps->velocity, down_v);
|
||||
|
@ -164,60 +275,44 @@ void PM_StepSlideMove ( qboolean gravity )
|
|||
VectorCopy (start_o, up);
|
||||
up[2] += STEPSIZE;
|
||||
|
||||
// test the player position if they were a stepheight higher
|
||||
pm->trace (&trace, up, pm->mins, pm->maxs, up, pm->ps->clientNum, pm->tracemask);
|
||||
if (trace.allsolid) {
|
||||
return; // can't step up
|
||||
}
|
||||
if ( trace.allsolid ) return; // can't step up
|
||||
|
||||
// try sliding above
|
||||
// try slidemove from this position
|
||||
VectorCopy (up, pm->ps->origin);
|
||||
VectorCopy (start_v, pm->ps->velocity);
|
||||
|
||||
PM_StepSlideMove_ ();
|
||||
PM_SlideMove( gravity );
|
||||
|
||||
// push down the final amount
|
||||
VectorCopy (pm->ps->origin, down);
|
||||
down[2] -= STEPSIZE;
|
||||
pm->trace (&trace, pm->ps->origin, pm->mins, pm->maxs, down, pm->ps->clientNum, pm->tracemask);
|
||||
if (!trace.allsolid)
|
||||
{
|
||||
if ( !trace.allsolid ) {
|
||||
VectorCopy (trace.endpos, pm->ps->origin);
|
||||
}
|
||||
|
||||
VectorCopy(pm->ps->origin, up);
|
||||
|
||||
VectorSubtract(down_o, start_o, tmp_o);
|
||||
DistanceDown = tmp_o[0]*tmp_o[0] + tmp_o[1]*tmp_o[1];
|
||||
VectorSubtract(up, start_o, tmp_o);
|
||||
DistanceUp = tmp_o[0]*tmp_o[0] + tmp_o[1]*tmp_o[1];
|
||||
|
||||
//Com_Printf("%f ", trace.plane.normal[2]);
|
||||
if (DistanceDown > DistanceUp || trace.plane.normal[2] < MIN_STEP_NORMAL) {
|
||||
|
||||
if ( trace.plane.normal[2] < 0.7f) {
|
||||
VectorCopy (down_o, pm->ps->origin);
|
||||
VectorCopy (down_v, pm->ps->velocity);
|
||||
PM_ClipVelocity( pm->ps->velocity, trace.plane.normal, pm->ps->velocity, OVERCLIP );
|
||||
return;
|
||||
}
|
||||
// Flat/walking up:
|
||||
else {
|
||||
//!! Special case
|
||||
// if we were walking along a plane, then we need to copy the Z over
|
||||
pm->ps->velocity[2] = down_v[2];
|
||||
}
|
||||
|
||||
// NiceAss Move the origin up a little... Seems hackish but needed.
|
||||
VectorCopy(pm->ps->origin, tmp_o);
|
||||
tmp_o[2] += 0.01f;
|
||||
start_o[2] += 0.01f;
|
||||
|
||||
// if the trace can trace back to the original position directly, don't step
|
||||
pm->trace ( &trace, tmp_o, pm->mins, pm->maxs, start_o, pm->ps->clientNum, pm->tracemask);
|
||||
// If it didn't make it all the way..
|
||||
pm->ps->velocity[2] = down_v[2];
|
||||
|
||||
VectorCopy(pm->ps->origin, tmp);
|
||||
// NiceAss: nudge it up a little.
|
||||
tmp[2] += 0.1f;
|
||||
start_o[2] += 0.1f;
|
||||
|
||||
// if the down trace can trace back to the original position directly, don't step
|
||||
pm->trace( &trace, tmp, pm->mins, pm->maxs, start_o, pm->ps->clientNum, pm->tracemask);
|
||||
if ( trace.fraction != 1.0 ) {
|
||||
// use the step move
|
||||
float delta;
|
||||
|
||||
delta = tmp_o[2] - start_o[2];
|
||||
delta = pm->ps->origin[2] - start_o[2];
|
||||
if ( delta > 2 ) {
|
||||
if ( delta < 7 ) {
|
||||
PM_AddEvent( EV_STEP_4 );
|
||||
|
@ -230,7 +325,7 @@ void PM_StepSlideMove ( qboolean gravity )
|
|||
}
|
||||
}
|
||||
if ( pm->debugLevel ) {
|
||||
Com_Printf("%d:stepped\n", c_pmove);
|
||||
Com_Printf("%i:stepped\n", c_pmove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue