home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char sccsid[] = "@(#)laser.c 1.1 92/05/28 SMI" ;
- /* from laser.c 1.3 90/05/02 SMI */
- #endif
-
- /*
- * Copyright (c) 1986 by Sun Microsystems, Inc.
- */
-
- /*
- * test all objects to see if they've been touched by the laser beam
- */
-
- #include <stdio.h>
- #include <math.h>
- #include "dstar.h"
- #include "object_types.h"
-
- #define LASER_THRESH2 (LASER_THRESH*LASER_THRESH)
-
-
- /*******
- *
- * test_object(object)
- *
- * check to see if the object lies along the laser beam, and how
- * close.
- *
- * given P0 is my position, P1 is the object's position and V is the
- * vector along the laser beam, then the point of closest approach, P, for
- * the laser beam to P1 is
- *
- * d = V * (P1-P0) (* = dot-product)
- * P = dV
- *
- * Note that since V is normalized, d is the distance from P0 to P.
- *
- ******/
-
-
-
- test_object(object)
- Object *object ;
- {
- Pt3d P, dP ;
- float d, dist ;
-
- dP.x = object->Posn.x - Me->Posn.x ;
- dP.y = object->Posn.y - Me->Posn.y ;
- dP.z = object->Posn.z - Me->Posn.z ;
-
- d = dP.x * Me->Pointing.x +
- dP.y * Me->Pointing.y +
- dP.z * Me->Pointing.z ;
-
- if (d < 0.0 || d > LASER_RANGE)
- return ;
-
- P.x = Me->Posn.x + d*Me->Pointing.x ;
- P.y = Me->Posn.y + d*Me->Pointing.y ;
- P.z = Me->Posn.z + d*Me->Pointing.z ;
-
- dist = (P.x - object->Posn.x) * (P.x - object->Posn.x) +
- (P.y - object->Posn.y) * (P.y - object->Posn.y) +
- (P.z - object->Posn.z) * (P.z - object->Posn.z) ;
-
- if(dist > LASER_THRESH2)
- return ;
-
-
- /* GOT IT! */
-
-
- net_blow_away(Me, object) ;
- }
-
-
-
-
- test_objects()
- {
- int i ;
- Object *object ;
-
- /* check enemy ships */
-
- object = &objects[0] ;
- for(i=0; i<MAX_OBJECTS; ++i)
- {
- if(object != Me &&
- (object->class == OBJ_PLAYER ||
- object->class == OBJ_MISSILE) &&
- object->status == OBJ_ACTIVE )
- {
- test_object(object) ;
- }
- ++object ;
- }
- }
-