diff options
author | /dev/humancontroller <devhc@example.com> | 2014-07-13 21:04:41 +0200 |
---|---|---|
committer | /dev/humancontroller <devhc@example.com> | 2017-03-09 13:51:14 +0100 |
commit | 02f195684a11b0791c68ef9ffcfa714188ba6a9b (patch) | |
tree | 3abfab659f4b5585940f3ae5a134f42d28e54928 | |
parent | e9231cb1f09f479ae59ebf5a217b73634b65fc64 (diff) |
do not position buildables too far away from their game-specified origin; display buildables even in air
-rw-r--r-- | src/cgame/cg_buildable.c | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/src/cgame/cg_buildable.c b/src/cgame/cg_buildable.c index b859732e..2c85bfd7 100644 --- a/src/cgame/cg_buildable.c +++ b/src/cgame/cg_buildable.c @@ -575,7 +575,7 @@ static void CG_BuildableAnimation( centity_t *cent, int *old, int *now, float *b } } -#define TRACE_DEPTH 64.0f +#define TRACE_DEPTH 15.0f /* =============== @@ -587,9 +587,9 @@ static void CG_PositionAndOrientateBuildable( const vec3_t angles, const vec3_t const vec3_t mins, const vec3_t maxs, vec3_t outAxis[ 3 ], vec3_t outOrigin ) { - vec3_t forward, start, end; - trace_t tr, box_tr; - float mag, fraction; + vec3_t forward, end; + trace_t tr; + float fraction; AngleVectors( angles, forward, NULL, NULL ); VectorCopy( normal, outAxis[ 2 ] ); @@ -608,26 +608,19 @@ static void CG_PositionAndOrientateBuildable( const vec3_t angles, const vec3_t outAxis[ 1 ][ 2 ] = -outAxis[ 1 ][ 2 ]; VectorMA( inOrigin, -TRACE_DEPTH, normal, end ); - VectorMA( inOrigin, 1.0f, normal, start ); - // Take both capsule and box traces. If the capsule trace does not differ - // significantly from the box trace use it. This may cause buildables to be - // positioned *inside* the surface on which it is placed. This is intentional - - CG_CapTrace( &tr, start, mins, maxs, end, skipNumber, + CG_CapTrace( &tr, inOrigin, mins, maxs, end, skipNumber, CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); - CG_Trace( &box_tr, start, mins, maxs, end, skipNumber, - CONTENTS_SOLID | CONTENTS_PLAYERCLIP ); - - mag = Distance( tr.endpos, box_tr.endpos ); - fraction = tr.fraction; - - // this is either too far off of the bbox to be useful for gameplay purposes - // or the model is positioned in thin air anyways. - if( mag > 15.0f || tr.fraction == 1.0f ) - fraction = box_tr.fraction; + if( tr.startsolid ) + fraction = 0; + else if( tr.fraction == 1.0f ) + { + // this is either too far off of the bbox to be useful for gameplay purposes + // or the model is positioned in thin air anyways. + fraction = 0; + } VectorMA( inOrigin, fraction * -TRACE_DEPTH, normal, outOrigin ); } @@ -1318,10 +1311,6 @@ void CG_Buildable( centity_t *cent ) memset ( &ent, 0, sizeof( ent ) ); - VectorCopy( cent->lerpOrigin, ent.origin ); - VectorCopy( cent->lerpOrigin, ent.oldorigin ); - VectorCopy( cent->lerpOrigin, ent.lightingOrigin ); - VectorCopy( es->origin2, surfNormal ); VectorCopy( es->angles, angles ); @@ -1329,7 +1318,6 @@ void CG_Buildable( centity_t *cent ) if( es->pos.trType == TR_STATIONARY ) { - // Positioning a buildable involves potentially up to two traces, and // seeing as buildables rarely move, we cache the results and recalculate // only if the buildable moves or changes orientation if( VectorCompare( cent->buildableCache.cachedOrigin, cent->lerpOrigin ) && @@ -1342,7 +1330,7 @@ void CG_Buildable( centity_t *cent ) } else { - CG_PositionAndOrientateBuildable( angles, ent.origin, surfNormal, + CG_PositionAndOrientateBuildable( angles, cent->lerpOrigin, surfNormal, es->number, mins, maxs, ent.axis, ent.origin ); VectorCopy( ent.axis[ 0 ], cent->buildableCache.axis[ 0 ] ); @@ -1353,6 +1341,11 @@ void CG_Buildable( centity_t *cent ) VectorCopy( surfNormal, cent->buildableCache.cachedNormal ); } } + else + { + VectorCopy( cent->lerpOrigin, ent.origin ); + AnglesToAxis( cent->lerpAngles, ent.axis ); + } //offset on the Z axis if required VectorMA( ent.origin, BG_BuildableConfig( es->modelindex )->zOffset, surfNormal, ent.origin ); |