1 /*
2      PLIB - A Suite of Portable Game Libraries
3      Copyright (C) 1998,2002  Steve Baker
4 
5      This library is free software; you can redistribute it and/or
6      modify it under the terms of the GNU Library General Public
7      License as published by the Free Software Foundation; either
8      version 2 of the License, or (at your option) any later version.
9 
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      Library General Public License for more details.
14 
15      You should have received a copy of the GNU Library General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 
19      For further information visit http://plib.sourceforge.net
20 
21      $Id: ssgIsect.cxx 1719 2002-10-26 19:00:56Z sjbaker $
22 */
23 
24 
25 #include "ssgLocal.h"
26 
27 #define MAX_HITS  100
28 static ssgHit hitlist [ MAX_HITS ] ;
29 static int next_hit = 0 ;
30 static ssgEntity *pathlist [ SSG_MAXPATH ] ;
31 static int next_path = 0 ;
32 
33 int _ssgIsHotTest = FALSE ;
34 int _ssgIsLosTest = FALSE ;
35 
_ssgPushPath(ssgEntity * e)36 void _ssgPushPath ( ssgEntity *e )
37 {
38   if ( next_path + 1 >= SSG_MAXPATH )
39   {
40     next_path++ ;  /* So pop works! */
41     return ;
42   }
43 
44   pathlist [ next_path++ ] = e ;
45 }
46 
47 
_ssgPopPath()48 void _ssgPopPath ()
49 {
50   next_path-- ;
51 }
52 
53 
_ssgAddHit(ssgLeaf * l,int trinum,sgMat4 mat,sgVec4 pl)54 void _ssgAddHit ( ssgLeaf *l, int trinum, sgMat4 mat, sgVec4 pl )
55 {
56   if ( next_hit + 1 >= MAX_HITS )
57     return ;
58 
59   ssgHit *h = & hitlist [ next_hit++ ] ;
60 
61   h -> leaf = l ;
62   h -> triangle = trinum ;
63 
64   h -> num_entries = (next_path>=SSG_MAXPATH) ? SSG_MAXPATH : next_path ;
65   memcpy ( h -> path, pathlist, h->num_entries * sizeof ( ssgEntity * ) ) ;
66 
67   sgCopyMat4 ( h -> matrix, mat ) ;
68   sgCopyVec4 ( h -> plane, pl ) ;
69 }
70 
71 
ssgIsect(ssgBranch * root,sgSphere * s,sgMat4 mat,ssgHit ** results)72 int ssgIsect ( ssgBranch *root, sgSphere *s, sgMat4 mat, ssgHit **results )
73 {
74   _ssgIsHotTest = FALSE ;
75   _ssgIsLosTest = FALSE ;
76   next_hit  = 0 ;
77   next_path = 0 ;
78   root -> isect ( s, mat, TRUE ) ;
79   *results = & hitlist [ 0 ] ;
80   return next_hit ;
81 }
82 
83 
ssgHOT(ssgBranch * root,sgVec3 s,sgMat4 mat,ssgHit ** results)84 int ssgHOT ( ssgBranch *root, sgVec3 s, sgMat4 mat, ssgHit **results )
85 {
86   _ssgIsHotTest = TRUE ;
87   _ssgIsLosTest = FALSE ;
88   next_hit  = 0 ;
89   next_path = 0 ;
90   root -> hot ( s, mat, TRUE ) ;
91   *results = & hitlist [ 0 ] ;
92   return next_hit ;
93 }
94 
95 
ssgLOS(ssgBranch * root,sgVec3 s,sgMat4 mat,ssgHit ** results)96 int ssgLOS ( ssgBranch *root, sgVec3 s, sgMat4 mat, ssgHit **results )
97 {
98   _ssgIsHotTest = FALSE ;
99   _ssgIsLosTest = TRUE ;
100   next_hit  = 0 ;
101   next_path = 0 ;
102   root -> los ( s, mat, TRUE ) ;
103   *results = & hitlist [ 0 ] ;
104   return next_hit ;
105 }
106 
107 
108