diff options
author | Tim Angus <tim@ngus.net> | 2001-12-01 14:03:50 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2001-12-01 14:03:50 +0000 |
commit | 749407ffc26c647c1faf675734559ab9fd8774fe (patch) | |
tree | a3600fd70839b58d83ade213f2ffd9e915a80989 /src | |
parent | 873486ba1f19554ded537504cc102e5d1476fa73 (diff) |
Tag based turrets
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_buildable.c | 65 | ||||
-rw-r--r-- | src/game/g_buildable.c | 30 |
2 files changed, 68 insertions, 27 deletions
diff --git a/src/cgame/cg_buildable.c b/src/cgame/cg_buildable.c index a91725fa..de0b1061 100644 --- a/src/cgame/cg_buildable.c +++ b/src/cgame/cg_buildable.c @@ -382,7 +382,6 @@ CG_Buildable void CG_Buildable( centity_t *cent ) { refEntity_t ent; - refEntity_t ent2; entityState_t *es; vec3_t angles; vec3_t forward, surfNormal, end, start, mins, maxs; @@ -442,29 +441,65 @@ void CG_Buildable( centity_t *cent ) CG_BuildableAnimation( cent, &ent.oldframe, &ent.frame, &ent.backlerp ); //turret barrel bit - if( cg_buildables[ es->modelindex ].models[ 1 ] != 0 ) + if( cg_buildables[ es->modelindex ].models[ 1 ] ) { - vec3_t turretOrigin; + refEntity_t turretBarrel; - memset( &ent2, 0, sizeof( ent2 ) ); + memset( &turretBarrel, 0, sizeof( turretBarrel ) ); - AnglesToAxis( es->angles2, ent2.axis ); + AnglesToAxis( es->angles2, turretBarrel.axis ); + + turretBarrel.hModel = cg_buildables[ es->modelindex ].models[ 1 ]; + VectorCopy( cent->lerpOrigin, turretBarrel.lightingOrigin ); + + CG_PositionRotatedEntityOnTag( &turretBarrel, &ent, ent.hModel, "tag_turret" ); + +/* AngleVectors( es->angles2, forward, NULL, NULL ); + VectorCopy( surfNormal, turretBarrel.axis[ 2 ] ); + ProjectPointOnPlane( turretBarrel.axis[ 0 ], forward, turretBarrel.axis[ 2 ] ); + + if( !VectorNormalize( turretBarrel.axis[ 0 ] ) ) + { + AngleVectors( es->angles2, NULL, NULL, forward ); + ProjectPointOnPlane( turretBarrel.axis[ 0 ], forward, turretBarrel.axis[ 2 ] ); + VectorNormalize( turretBarrel.axis[ 0 ] ); + } + + CrossProduct( turretBarrel.axis[ 0 ], turretBarrel.axis[ 2 ], turretBarrel.axis[ 1 ] ); + turretBarrel.axis[ 1 ][ 0 ] = -turretBarrel.axis[ 1 ][ 0 ]; + turretBarrel.axis[ 1 ][ 1 ] = -turretBarrel.axis[ 1 ][ 1 ]; + turretBarrel.axis[ 1 ][ 2 ] = -turretBarrel.axis[ 1 ][ 2 ];*/ + + turretBarrel.oldframe = ent.oldframe; + turretBarrel.frame = ent.frame; + turretBarrel.backlerp = ent.backlerp; - ent2.hModel = cg_buildables[ es->modelindex ].models[ 1 ]; + trap_R_AddRefEntityToScene( &turretBarrel ); + } - VectorCopy( cent->lerpOrigin, turretOrigin ); - turretOrigin[ 2 ] += 5; + //turret barrel bit + if( cg_buildables[ es->modelindex ].models[ 2 ] ) + { + refEntity_t turretBarrel; + vec3_t swivelAngles; - VectorCopy( turretOrigin, ent2.origin ); - VectorCopy( turretOrigin, ent2.oldorigin ); + memset( &turretBarrel, 0, sizeof( turretBarrel ) ); + + VectorCopy( es->angles2, swivelAngles ); + swivelAngles[ PITCH ] = 0.0f; + + AnglesToAxis( swivelAngles, turretBarrel.axis ); + + turretBarrel.hModel = cg_buildables[ es->modelindex ].models[ 1 ]; + VectorCopy( cent->lerpOrigin, turretBarrel.lightingOrigin ); - ent2.nonNormalizedAxes = qfalse; + CG_PositionRotatedEntityOnTag( &turretBarrel, &ent, ent.hModel, "tag_turret" ); - ent2.oldframe = ent.oldframe; - ent2.frame = ent.frame; - ent2.backlerp = ent.backlerp; + turretBarrel.oldframe = ent.oldframe; + turretBarrel.frame = ent.frame; + turretBarrel.backlerp = ent.backlerp; - trap_R_AddRefEntityToScene( &ent2 ); + trap_R_AddRefEntityToScene( &turretBarrel ); } // add to refresh list diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index 300f2ad7..41b6d4f9 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -1074,7 +1074,7 @@ Used by HDef1_Think to track enemy location */ qboolean hdef1_trackenemy( gentity_t *self ) { - vec3_t dirToTarget, angleToTarget, angularDiff, xNormal; + vec3_t dirToTarget, dttAdjusted, angleToTarget, angularDiff, xNormal; vec3_t refNormal = { 0.0f, 0.0f, 1.0f }; float temp, rotAngle; float distanceToTarget = BG_FindRangeForBuildable( self->s.modelindex ); @@ -1119,15 +1119,13 @@ qboolean hdef1_trackenemy( gentity_t *self ) CrossProduct( self->s.origin2, refNormal, xNormal ); VectorNormalize( xNormal ); rotAngle = RAD2DEG( acos( DotProduct( self->s.origin2, refNormal ) ) ); - RotatePointAroundVector( dirToTarget, xNormal, dirToTarget, -rotAngle ); + RotatePointAroundVector( dttAdjusted, xNormal, dirToTarget, rotAngle ); - vectoangles( dirToTarget, angleToTarget ); + vectoangles( dttAdjusted, angleToTarget ); angularDiff[ PITCH ] = AngleSubtract( self->s.angles2[ PITCH ], angleToTarget[ PITCH ] ); angularDiff[ YAW ] = AngleSubtract( self->s.angles2[ YAW ], angleToTarget[ YAW ] ); - G_Printf( "%f\n", angularDiff[ PITCH ] ); - //if not pointing at our target then move accordingly if( angularDiff[ PITCH ] < -HDEF1_ACCURACYTOLERANCE ) self->s.angles2[ PITCH ] += HDEF1_ANGULARSPEED; @@ -1154,9 +1152,9 @@ qboolean hdef1_trackenemy( gentity_t *self ) else self->s.angles2[ YAW ] = angleToTarget[ YAW ]; - AngleVectors( self->s.angles2, dirToTarget, NULL, NULL ); - RotatePointAroundVector( self->turretAim, xNormal, dirToTarget, rotAngle ); - vectoangles( self->turretAim, self->turretAim ); + AngleVectors( self->s.angles2, dttAdjusted, NULL, NULL ); + RotatePointAroundVector( dirToTarget, xNormal, dttAdjusted, -rotAngle ); + vectoangles( dirToTarget, self->turretAim ); //if pointing at our target return true if( abs( angleToTarget[ YAW ] - self->s.angles2[ YAW ] ) <= HDEF1_ACCURACYTOLERANCE && @@ -1179,14 +1177,20 @@ Used by HDef1_Think to track enemy location */ qboolean hdef2_trackenemy( gentity_t *self ) { - vec3_t dirToTarget, angleToTarget, angularDiff; - float temp; + vec3_t dirToTarget, dttAdjusted, angleToTarget, angularDiff, xNormal; + vec3_t refNormal = { 0.0f, 0.0f, 1.0f }; + float temp, rotAngle; VectorSubtract( self->enemy->s.pos.trBase, self->s.pos.trBase, dirToTarget ); VectorNormalize( dirToTarget ); - vectoangles( dirToTarget, angleToTarget ); + CrossProduct( self->s.origin2, refNormal, xNormal ); + VectorNormalize( xNormal ); + rotAngle = RAD2DEG( acos( DotProduct( self->s.origin2, refNormal ) ) ); + RotatePointAroundVector( dttAdjusted, xNormal, dirToTarget, rotAngle ); + + vectoangles( dttAdjusted, angleToTarget ); angularDiff[ PITCH ] = AngleSubtract( self->s.angles2[ PITCH ], angleToTarget[ PITCH ] ); angularDiff[ YAW ] = AngleSubtract( self->s.angles2[ YAW ], angleToTarget[ YAW ] ); @@ -1215,7 +1219,9 @@ qboolean hdef2_trackenemy( gentity_t *self ) else self->s.angles2[ YAW ] = angleToTarget[ YAW ]; - VectorCopy( self->s.angles2, self->turretAim ); + AngleVectors( self->s.angles2, dttAdjusted, NULL, NULL ); + RotatePointAroundVector( dirToTarget, xNormal, dttAdjusted, -rotAngle ); + vectoangles( dirToTarget, self->turretAim ); //if pointing at our target return true if( abs( angleToTarget[ YAW ] - self->s.angles2[ YAW ] ) <= HDEF2_ACCURACYTOLERANCE && |