bool Intersects(Box other) { float test, test2; test = this.Center.X - (this.Size.X / 2.0f); test2 = other.Center.X - (other.Size.X / 2.0f); if ((test+Size.X < test2) || (test > test2+other.Size.X)) return false; test = this.Center.Y - (this.Size.Y / 2.0f); test2 = other.Center.Y - (other.Size.Y / 2.0f); if ((test+Size.Y < test2) || (test > test2+other.Size.Y)) return false; test = this.Center.Z - (this.Size.Z / 2.0f); test2 = other.Center.Z - (other.Size.Z / 2.0f); if ((test+Size.Z < test2) || (test > test2+other.Size.Z)) return false; return true; }
public Box(Box other) { _center = other._center; _size = other._size; _rotation = other._rotation; }
public bool IsAtTarget(Vector3 target, float tolerance) { Box shell = this.GetBoundingBox(false); Vector3 size = shell.Size; size.X += tolerance; size.Y += tolerance; size.Z += tolerance; shell = new Box(shell.Center, size); return shell.ContainsPoint(target); }
private Box CalculateBoundingBox() { // This method always recalcs the BB. To use the cached version, call BoundingBox. Box returnBox; List<Box> boundingBoxes = new List<Box>(); // lock m_parts and then _bbLock (leaf) when needed lock (m_parts) { PhysicsActor physActor = m_rootPart.PhysActor; if ((physActor != null) && (physActor.IsPhysical)) { // For physical objects, save the pos/rot used for BB calc. _bbPos = physActor.Position; _bbRot = physActor.Rotation; } foreach (SceneObjectPart part in m_parts.Values) { boundingBoxes.Add(part.BoundingBox); } lock (_bbLock) { // update _calculatedBoundingBox inside the lock _calculatedBoundingBox = Box.CalculateBoundingBox(boundingBoxes); returnBox = _calculatedBoundingBox; } } return returnBox; }
public void ClearBoundingBoxCache() { lock (_bbLock) { _calculatedBoundingBox = null; } }
private Box CalculateBoundingBox() { // This method always recalcs the BB. To use the cached version, call BoundingBox. Box returnBox; List<Box> boundingBoxes = new List<Box>(); PhysicsActor physActor = m_rootPart.PhysActor; if ((physActor != null) && (physActor.IsPhysical)) { // For physical objects, save the pos/rot used for BB calc. _bbPos = physActor.Position; _bbRot = physActor.Rotation; } m_childParts.ForEachPart((SceneObjectPart part) => { boundingBoxes.Add(part.BoundingBox); }); lock (_bbLock) { // update _calculatedBoundingBox inside the lock _calculatedBoundingBox = Box.CalculateBoundingBox(boundingBoxes); returnBox = _calculatedBoundingBox; } return returnBox; }