public void RemoveObject(ViewableObject viewable) { if (!this.viewableObjects.ContainsKey(viewable.Name)) { return; } int idx = this.viewableObjects.IndexOfKey(viewable.Name); this.viewableObjects.Remove(viewable.Name); if (viewable.QuadTreeNodes.Count > 0) { viewable.QuadTreeNodes.Clear(); } this.viewableObjects.RemoveAt(idx); if (this.northeastNode != null) { this.northeastNode.RemoveObject(viewable); } if (this.northwestNode != null) { this.northwestNode.RemoveObject(viewable); } if (this.southeastNode != null) { this.southeastNode.RemoveObject(viewable); } if (this.southwestNode != null) { this.southwestNode.RemoveObject(viewable); } }
public void AddObject(ViewableObject viewable) { if (!viewable.IsInsideRectangle(this.quadBounds)) { return; } if (this.viewableObjects.ContainsKey(viewable.Name)) { return; } this.viewableObjects.Add(viewable.Name, viewable); viewable.QuadTreeNodes.Add(this); if (this.northeastNode != null && viewable.IsInsideRectangle(this.northeastNode.Bounds)) { this.northeastNode.AddObject(viewable); } if (this.northwestNode != null && viewable.IsInsideRectangle(this.northwestNode.Bounds)) { this.northwestNode.AddObject(viewable); } if (this.southeastNode != null && viewable.IsInsideRectangle(this.southeastNode.Bounds)) { this.southeastNode.AddObject(viewable); } if (this.southwestNode != null && viewable.IsInsideRectangle(this.southwestNode.Bounds)) { this.southwestNode.AddObject(viewable); } }
/// <summary> /// Gets the cull state of a viewable object. /// </summary> /// <param name="viewableObject">The object to get the cull state for.</param> /// <returns></returns> public CullState GetCullState(ViewableObject viewableObject) { if (viewableObject == null) { throw new ArgumentNullException("viewableObject"); } CullState state; state = GetCullState(viewableObject.Position, viewableObject.BoundingRadius); return(state); }
/// <summary> /// Gets the distance from a the camera to a viewable object. /// </summary> /// <param name="viewableObject"></param> /// <returns></returns> public float GetDistanceFrom(ViewableObject viewableObject) { if (viewableObject == null) { throw new ArgumentNullException("viewableObject"); } float distance; distance = Plane.DotCoordinate(this.frustumPlanes[3], viewableObject.Position); distance += this.nearPlaneDistance; return(distance); }
public void Update(ViewableObject viewableObject) { bool _needReset = false; foreach (QuadTreeNode node in viewableObject.QuadTreeNodes) { if (!viewableObject.IsInsideRectangle(node.Bounds)) { //there's at least 1 object that's no longer in //the view. Need a reset. _needReset = true; break; } } if (_needReset) { BaseNode.RemoveObject(viewableObject); BaseNode.AddObject(viewableObject); } }
public virtual bool HasCollidedWith(ViewableObject otherObject) { return(false); }