summaryrefslogtreecommitdiff
path: root/src/game/g_buildable.c
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2001-12-01 14:03:50 +0000
committerTim Angus <tim@ngus.net>2001-12-01 14:03:50 +0000
commit749407ffc26c647c1faf675734559ab9fd8774fe (patch)
treea3600fd70839b58d83ade213f2ffd9e915a80989 /src/game/g_buildable.c
parent873486ba1f19554ded537504cc102e5d1476fa73 (diff)
Tag based turrets
Diffstat (limited to 'src/game/g_buildable.c')
-rw-r--r--src/game/g_buildable.c30
1 files changed, 18 insertions, 12 deletions
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 &&