public static bool Contains(this BoundingBox3 me, BoundingBox3 other) { return me.Min.X <= other.Min.X && me.Min.Y <= other.Min.Y && me.Min.Z <= other.Min.Z && me.Max.X >= other.Max.X && me.Max.Y >= other.Max.Y && me.Max.Z >= other.Max.Z; }
public static bool Intersects(this BoundingBox3 me, BoundingBox3 other) { // test using SAT (separating axis theorem) float lx = Math.Abs(me.Center.X - other.Center.X); float sumx = (me.Size.X / 2.0f) + (other.Size.X / 2.0f); float ly = Math.Abs(me.Center.Y - other.Center.Y); float sumy = (me.Size.Y / 2.0f) + (other.Size.Y / 2.0f); float lz = Math.Abs(me.Center.Z - other.Center.Z); float sumz = (me.Size.Z / 2.0f) + (other.Size.Z / 2.0f); return (lx <= sumx && ly <= sumy && lz <= sumz); }
/// <summary> /// Gets the region of this area which is /// accessible to the player and other creatures. /// </summary> /// <returns> /// A <see cref="OEIShared.OEIMath.BoundingBox3"/> instance /// representing the boundaries of the player-accessible region. /// </returns> /// <remarks>Interior areas have no inaccessible region, /// and will return the bounds of the full area.</remarks> public override BoundingBox3 GetAccessibleRegion() { BoundingBox3 bounds = nwn2Area.GetBoundsOfArea(); if (nwn2Area.HasTerrain) { Vector3 min = new Vector3(bounds.Min.X + InaccessibleRegionWidth, bounds.Min.Y + InaccessibleRegionWidth, bounds.Min.Z); Vector3 max = new Vector3(bounds.Max.X + InaccessibleRegionWidth, bounds.Max.Y + InaccessibleRegionWidth, bounds.Max.Z); bounds = new BoundingBox3(min, max); } return(bounds); }
public bool Intersects(BoundingBox3 boundingBox) { Vec3 clampedLocation; if (center.x > boundingBox.max.x) { clampedLocation.x = boundingBox.max.x; } else if (center.x < boundingBox.min.x) { clampedLocation.x = boundingBox.min.x; } else { clampedLocation.x = center.x; } if (center.y > boundingBox.max.y) { clampedLocation.y = boundingBox.max.y; } else if (center.y < boundingBox.min.y) { clampedLocation.y = boundingBox.min.y; } else { clampedLocation.y = center.y; } if (center.z > boundingBox.max.z) { clampedLocation.z = boundingBox.max.z; } else if (center.z < boundingBox.min.z) { clampedLocation.z = boundingBox.min.z; } else { clampedLocation.z = center.z; } return(clampedLocation.DistanceSquared(center) <= (radius * radius)); }
void Draw(object sender, DrawingEventArgs e) { if (HeightFieldProperty.GetValue(null) == null) { return; } var dd = e.Drawer; var heightField = HeightFieldProperty.GetValue(null); float cs = (float)CellSize.GetValue(heightField); float ch = (float)CellHeight.GetValue(heightField); Array Spans = (Array)SpansProp.GetValue(heightField); BoundingBox3 bounds = (BoundingBox3)Bounds.GetValue(heightField); //var cpl = Core.Player.Location; var td = new Dictionary <Color, List <Vector3> >(); for (int y = 0; y < (int)NumCellsZ.GetValue(heightField); ++y) { for (int x = 0; x < (int)NumCellsX.GetValue(heightField); ++x) { float fx = bounds.Min.X + x * cs; float fz = bounds.Min.Z + y * cs; var c = GetCell.Invoke(heightField, new object[] { x, y }); // chf.GetCell(x, y); uint Index = (uint)CellIndexProp.GetValue(c); uint Count = (uint)CellCountProp.GetValue(c); for (uint i = Index, ni = Index + Count; i < ni; ++i) { var s = Spans.GetValue(i); var area = (byte)SpansAreaProp.GetValue(s); ushort bottom = (ushort)SpansBottomField.GetValue(s); Color color; if (area == 1) { color = Color.FromArgb(128, 128, 255, 64); } else if (area == 0) { color = Color.FromArgb(128, 0, 0, 64); } else { color = duIntToCol(area, 64); } float fy = bounds.Min.Y + (bottom + 1) * ch; if (!td.TryGetValue(color, out var tl)) { tl = new List <Vector3>(); td[color] = tl; } tl.AddRange(new[] { new Vector3(fx, fy, fz), new Vector3(fx, fy, fz + cs), new Vector3(fx + cs, fy, fz + cs), new Vector3(fx + cs, fy, fz + cs), new Vector3(fx + cs, fy, fz), new Vector3(fx, fy, fz) }); } } } foreach (var k in td) { dd.DrawTriangles(k.Value.ToArray(), k.Key); } }