public unsafe void GetCornersUnsafe(Vector2I *corners) { corners.X = this.Min.X; corners.Y = this.Max.Y; corners[1].X = this.Max.X; corners[1].Y = this.Max.Y; corners[2].X = this.Max.X; corners[2].Y = this.Min.Y; corners[3].X = this.Min.X; corners[3].Y = this.Min.Y; corners[4].X = this.Min.X; corners[4].Y = this.Max.Y; corners[5].X = this.Max.X; corners[5].Y = this.Max.Y; corners[6].X = this.Max.X; corners[6].Y = this.Min.Y; corners[7].X = this.Min.X; corners[7].Y = this.Min.Y; }
public unsafe ContainmentType QueryHeight(ref BoundingBox query) { ContainmentType intersects; int num3; SEntry[] queryStack; SEntry entry; int y; int x; if (this.PruningTree == null) { return(ContainmentType.Intersects); } if ((m_queryStack == null) || (m_queryStack.Length < this.PruningTree.Length)) { m_queryStack = new SEntry[this.PruningTree.Length]; } if (query.Min.Z > this.Root.Max) { return(ContainmentType.Disjoint); } if (query.Max.Z < this.Root.Min) { return(ContainmentType.Contains); } if (query.Max.X < 0f) { goto TR_0003; } else if (query.Max.Y < 0f) { goto TR_0003; } else if ((query.Min.X <= 1f) && (query.Min.Y <= 1f)) { if (this.PruningTree.Length == 0) { return(ContainmentType.Intersects); } if (query.Max.X == 1.0) { query.Max.X = 1f; } if (query.Max.Y == 1.0) { query.Max.Y = 1f; } intersects = ContainmentType.Intersects; float num = Math.Max(query.Width, query.Height); if (num < this.m_pixelSizeFour) { ushort num6; Box2I boxi2 = new Box2I(ref query, (uint)this.Resolution); Vector2I *vectoriPtr1 = (Vector2I *)ref boxi2.Min; vectoriPtr1[0] -= 1; Vector2I *vectoriPtr2 = (Vector2I *)ref boxi2.Max; vectoriPtr2[0] += 1; boxi2.Intersect(ref this.m_bounds); int num4 = (int)(query.Min.Z * 65535f); int num5 = (int)(query.Max.Z * 65535f); this.GetValue(boxi2.Min.X, boxi2.Min.Y, out num6); if (num6 > num5) { intersects = ContainmentType.Contains; } else { if (num6 >= num4) { return(ContainmentType.Intersects); } intersects = ContainmentType.Disjoint; } int num7 = 0xffff; int num8 = 0; int y = boxi2.Min.Y; while (y <= boxi2.Max.Y) { int x = boxi2.Min.X; while (true) { if (x > boxi2.Max.X) { y++; break; } this.GetValue(x, y, out num6); if (num6 > num8) { num8 = num6; } if (num6 < num7) { num7 = num6; } x++; } } int num9 = num8 - num7; num9 += num9 >> 1; num7 -= num9; return((num4 <= (num8 + num9)) ? ((num5 >= num7) ? ContainmentType.Intersects : ContainmentType.Contains) : ContainmentType.Disjoint); } uint index = (uint)MathHelper.Clamp(Math.Log((double)(num * (this.Resolution / HeightmapNode.HEIGHTMAP_LEAF_SIZE))) / Math.Log((double)HeightmapNode.HEIGHTMAP_BRANCH_FACTOR), 0.0, (double)(this.PruningTree.Length - 1)); num3 = 0; queryStack = m_queryStack; Box2I other = new Box2I(Vector2I.Zero, new Vector2I(((int)this.PruningTree[index].Res) - 1)); queryStack[0].Bounds = new Box2I(ref query, this.PruningTree[index].Res); queryStack[0].Bounds.Intersect(ref other); queryStack[0].Next = queryStack[0].Bounds.Min; queryStack[0].Level = index; queryStack[0].Result = intersects; queryStack[0].Continue = false; } else { goto TR_0003; } goto TR_0035; TR_0003: return(ContainmentType.Disjoint); TR_001A: intersects = entry.Result; num3--; if (num3 >= 0) { queryStack[num3].Intersection = intersects; } goto TR_0035; TR_001E: x++; goto TR_002E; TR_0026: switch (entry.Intersection) { case ContainmentType.Disjoint: if (entry.Result != ContainmentType.Contains) { entry.Result = ContainmentType.Disjoint; goto TR_001E; } else { entry.Result = ContainmentType.Intersects; } break; case ContainmentType.Contains: if (entry.Result != ContainmentType.Disjoint) { entry.Result = ContainmentType.Contains; goto TR_001E; } else { entry.Result = ContainmentType.Intersects; } break; case ContainmentType.Intersects: entry.Result = ContainmentType.Intersects; break; default: goto TR_001E; } goto TR_001A; TR_002E: while (true) { if (x <= entry.Bounds.Max.X) { if (entry.Continue) { entry.Continue = false; x = entry.Next.X; goto TR_0026; } else { SEntry *entryPtr1 = (SEntry *)ref entry; entryPtr1->Intersection = this.PruningTree[entry.Level].Intersect(x, y, ref query); if (entry.Intersection != ContainmentType.Intersects) { goto TR_0026; } else { if (this.PruningTree[entry.Level].IsCellNotContained(x, y, ref query) && (entry.Level != 0)) { entry.Next = new Vector2I(x, y); entry.Continue = true; queryStack[num3] = entry; num3++; queryStack[num3] = new SEntry(ref query, this.PruningTree[((int)entry.Level) - 1].Res, new Vector2I(x, y), entry.Result, entry.Level - 1); break; } goto TR_0026; } } } else { y++; goto TR_0031; } break; } goto TR_0035; TR_0031: while (true) { if (y <= entry.Bounds.Max.Y) { x = entry.Bounds.Min.X; } else { goto TR_001A; } break; } goto TR_002E; TR_0035: while (true) { if (num3 == -1) { return(intersects); } entry = queryStack[num3]; y = entry.Next.Y; break; } goto TR_0031; }
public unsafe void GetBounds(ref BoundingBox query) { float num = Math.Max(query.Width, query.Height); if (((num >= this.m_pixelSizeFour) && (this.PruningTree != null)) && (this.PruningTree.Length != 0)) { double num2 = Math.Log((double)(((float)this.Resolution) / (num * HeightmapNode.HEIGHTMAP_LEAF_SIZE))) / Math.Log((double)HeightmapNode.HEIGHTMAP_BRANCH_FACTOR); uint index = ((uint)(this.PruningTree.Length - 1)) - ((uint)MathHelper.Clamp(num2, 0.0, (double)(this.PruningTree.Length - 1))); Box2I other = new Box2I(Vector2I.Zero, new Vector2I(((int)this.PruningTree[index].Res) - 1)); Box2I boxi2 = new Box2I(ref query, this.PruningTree[index].Res); boxi2.Intersect(ref other); query.Min.Z = float.PositiveInfinity; query.Max.Z = float.NegativeInfinity; int res = (int)this.PruningTree[index].Res; int y = boxi2.Min.Y; while (y <= boxi2.Max.Y) { int x = boxi2.Min.X; while (true) { if (x > boxi2.Max.X) { y++; break; } HeightmapNode node = this.PruningTree[index].Nodes[(y * res) + x]; if (query.Min.Z > node.Min) { query.Min.Z = node.Min; } if (query.Max.Z < node.Max) { query.Max.Z = node.Max; } x++; } } } else { ushort num5; Box2I boxi3 = new Box2I(ref query, (uint)this.Resolution); Vector2I *vectoriPtr1 = (Vector2I *)ref boxi3.Min; vectoriPtr1[0] -= 1; Vector2I *vectoriPtr2 = (Vector2I *)ref boxi3.Max; vectoriPtr2[0] += 1; boxi3.Intersect(ref this.m_bounds); this.GetValue(boxi3.Min.X, boxi3.Min.Y, out num5); int num6 = 0xffff; int num7 = 0; int y = boxi3.Min.Y; while (y <= boxi3.Max.Y) { int x = boxi3.Min.X; while (true) { if (x > boxi3.Max.X) { y++; break; } this.GetValue(x, y, out num5); if (num5 > num7) { num7 = num5; } if (num5 < num6) { num6 = num5; } x++; } } int num8 = ((num7 - num6) * 2) / 3; num7 += num8; num6 -= num8; query.Min.Z = num6 * 1.525902E-05f; query.Max.Z = num7 * 1.525902E-05f; } }