ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/oct.C
Revision: 1.7
Committed: Mon Oct 4 02:06:57 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +15 -7 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include <cstdlib>
2    
3     #include "oct.h"
4 root 1.2 #include "entity.h"
5    
6 root 1.3 octant world(0, 0);
7 root 1.2
8 root 1.3 octant::octant (octant *parent, int subindex)
9 root 1.2 : parent(parent)
10     {
11     for (fill = 8; fill--; )
12     sub[fill] = 0;
13    
14 root 1.3 if (parent)
15     {
16     extent = (parent->extent + 1) >> 1;
17     orig = parent->orig;
18     orig.offset (subindex, extent);
19     }
20     else
21     {
22     extent = MAXEXTENT;
23     orig.x = orig.y = orig.z = SOFFS_MIN;
24     }
25 root 1.2 }
26    
27     octant::~octant ()
28     {
29     for (fill = 8; fill--; )
30     delete sub[fill];
31     }
32    
33 root 1.4 static bool overlap (const sector &o1, uoffs ea, const sector &o2, const box &bbox)
34     {
35     sector a2;
36    
37     ea /= 2;
38    
39     a2.x = o1.x + ea;
40     a2.y = o1.y + ea;
41     a2.z = o1.z + ea;
42    
43     sector b2;
44     sector eb;
45    
46 root 1.7 b2.x = o2.x + bbox.a.x;
47     b2.y = o2.y + bbox.a.y;
48     b2.z = o2.z + bbox.a.z;
49    
50     eb.x = (bbox.b.x - bbox.a.x) / 2;
51     eb.y = (bbox.b.y - bbox.a.y) / 2;
52     eb.z = (bbox.b.z - bbox.a.z) / 2;
53 root 1.4
54     b2.x += eb.x;
55     b2.y += eb.y;
56     b2.z += eb.z;
57    
58     return abs (a2.x - b2.x) <= ea + eb.x
59     && abs (a2.y - b2.y) <= ea + eb.y
60     && abs (a2.z - b2.z) <= ea + eb.z;
61     }
62    
63 root 1.6 void octant::add (entity_base *e)
64 root 1.2 {
65 root 1.4 printf ("OCTANT %d,%d,%d+%d\n", orig.x, orig.y, orig.z, extent);
66 root 1.7
67     box bbox = translate (e->bbox, e->orig, orig);
68    
69     #if 0
70     uoffs size = max (abs (bbox.b.x - bbox.a.x),
71     abs (bbox.b.y - bbox.a.y),
72     abs (bbox.b.z - bbox.a.z));
73     #endif
74 root 1.3
75 root 1.6 if (overlap (orig, extent, e->orig, e->bbox))
76 root 1.4 {
77     printf ("overlap, add\n");
78     push_back (e);
79     e->o.push_back (this);
80 root 1.5
81     #if 0
82     uoffs extent2 = extent / 2;
83     for (int si = 8; i--; )
84     {
85 root 1.6 e->orig sub = orig;
86 root 1.5 sub.offset (si, extent2);
87 root 1.6 if (overlap (sub, extent2, e->orig, e->bbox))
88 root 1.5 {
89     }
90     #endif
91 root 1.4 }
92     else
93     printf ("no overlap\n");
94 root 1.2 }
95 root 1.1
96     void octant::remove (entity_base *e)
97     {
98     }
99    
100 root 1.4 void octant::draw (draw_context &ctx)
101 root 1.1 {
102 root 1.2 for (iterator i = end (); i-- != begin (); )
103 root 1.5 (*i)->display (ctx);
104 root 1.1 }
105 root 1.2