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

# Content
1 #include <cstdlib>
2
3 #include "oct.h"
4 #include "entity.h"
5
6 octant world(0, 0);
7
8 octant::octant (octant *parent, int subindex)
9 : parent(parent)
10 {
11 for (fill = 8; fill--; )
12 sub[fill] = 0;
13
14 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 }
26
27 octant::~octant ()
28 {
29 for (fill = 8; fill--; )
30 delete sub[fill];
31 }
32
33 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 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
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 void octant::add (entity_base *e)
64 {
65 printf ("OCTANT %d,%d,%d+%d\n", orig.x, orig.y, orig.z, extent);
66
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
75 if (overlap (orig, extent, e->orig, e->bbox))
76 {
77 printf ("overlap, add\n");
78 push_back (e);
79 e->o.push_back (this);
80
81 #if 0
82 uoffs extent2 = extent / 2;
83 for (int si = 8; i--; )
84 {
85 e->orig sub = orig;
86 sub.offset (si, extent2);
87 if (overlap (sub, extent2, e->orig, e->bbox))
88 {
89 }
90 #endif
91 }
92 else
93 printf ("no overlap\n");
94 }
95
96 void octant::remove (entity_base *e)
97 {
98 }
99
100 void octant::draw (draw_context &ctx)
101 {
102 for (iterator i = end (); i-- != begin (); )
103 (*i)->display (ctx);
104 }
105