ListBox3d Children(Box3D box) { ListBox3d l = newListBox3d(); l.count = 8; Box3D[] c = l.arr; for (int i = 0; i < 8; i++) { c[i] = newBox3d(); } float x = box.MinEdge[0]; float y = box.MinEdge[1]; float z = box.MinEdge[2]; float size = box.LengthX() / 2; c[0].Set(x, y, z, size); c[1].Set(x + size, y, z, size); c[2].Set(x, y, z + size, size); c[3].Set(x + size, y, z + size, size); c[4].Set(x, y + size, z, size); c[5].Set(x + size, y + size, z, size); c[6].Set(x, y + size, z + size, size); c[7].Set(x + size, y + size, z + size, size); return(l); }
ListBox3d newListBox3d() { ListBox3d l = listpool[listpool_i++]; l.count = 0; return(l); }
ListBox3d SearchPrivate(PredicateBox3D query, Box3D box) { if (box.LengthX() == 1) { ListBox3d l1 = newListBox3d(); l1.count = 1; l1.arr[0] = box; return(l1); } ListBox3d l = newListBox3d(); l.count = 0; ListBox3d children = Children(box); for (int k = 0; k < children.count; k++) { Box3D child = children.arr[k]; if (query.Hit(child)) { ListBox3d l2 = SearchPrivate(query, child); for (int i = 0; i < l2.count; i++) { Box3D n = l2.arr[i]; l.arr[l.count++] = n; } recycleListBox3d(l2); } } recycleListBox3d(children); return(l); }
public BlockPosSide[] LineIntersection(DelegateIsBlockEmpty isEmpty, DelegateGetBlockHeight getBlockHeight, Line3D line, IntRef retCount) { lCount = 0; currentLine = line; currentHit[0] = 0; currentHit[1] = 0; currentHit[2] = 0; ListBox3d l1 = Search(PredicateBox3DHit.Create(this)); for (int i = 0; i < l1.count; i++) { Box3D node = l1.arr[i]; float[] hit = currentHit; float x = node.MinEdge[0]; float y = node.MinEdge[2]; float z = node.MinEdge[1]; if (!isEmpty.IsBlockEmpty(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z))) { Box3D node2 = new Box3D(); node2.MinEdge = Vec3.CloneIt(node.MinEdge); node2.MaxEdge = Vec3.CloneIt(node.MaxEdge); node2.MaxEdge[1] = node2.MinEdge[1] + getBlockHeight.GetBlockHeight(platform.FloatToInt(x), platform.FloatToInt(y), platform.FloatToInt(z)); BlockPosSide b = new BlockPosSide(); float[] hit2 = new float[3]; float[] dir = new float[3]; dir[0] = line.End[0] - line.Start[0]; dir[1] = line.End[1] - line.Start[1]; dir[2] = line.End[2] - line.Start[2]; bool ishit = Intersection.HitBoundingBox(node2.MinEdge, node2.MaxEdge, line.Start, dir, hit2); if (ishit) { //hit2.pos = Vec3.FromValues(x, z, y); b.blockPos = Vec3.FromValues(platform.FloatToInt(x), platform.FloatToInt(z), platform.FloatToInt(y)); b.collisionPos = hit2; l[lCount++] = b; } } } BlockPosSide[] ll = new BlockPosSide[lCount]; for (int i = 0; i < lCount; i++) { ll[i] = l[i]; } retCount.value = lCount; return(ll); }
public BlockOctreeSearcher() { intersection = new Intersection(); pool = new Box3D[10000]; for (int i = 0; i < 10000; i++) { pool[i] = new Box3D(); } listpool = new ListBox3d[50]; for (int i = 0; i < 50; i++) { listpool[i] = new ListBox3d(); listpool[i].arr = new Box3D[1000]; } l = new BlockPosSide[1024]; lCount = 0; currentHit = new float[3]; }
void recycleListBox3d(ListBox3d l) { listpool_i--; listpool[listpool_i] = l; }