//returns true if the bbox described by other intersects with this one public bool isOverlappedWith(InvertedAABBox2D other) { return !((other.Top() > this.Bottom()) || (other.Bottom() < this.Top()) || (other.Left() > this.Right()) || (other.Right() < this.Left())); }
//returns true if the bbox described by other intersects with this one public bool isOverlappedWith(InvertedAABBox2D other) { return(!((other.Top() > this.Bottom()) || (other.Bottom() < this.Top()) || (other.Left() > this.Right()) || (other.Right() < this.Left()))); }
public Cell(Vector2D topleft, Vector2D botright) { BBox = new InvertedAABBox2D(topleft, botright); Members = new List<MovingEntity>(); }
//----------------------- CalculateNeighbors ---------------------------- // // This must be called to create the collection of neighbors. This method // examines each cell within range of the target, If the // cells contain entities then they are tested to see if they are situated // within the target's neighborhood region. If they are they are added to // neighbor list //------------------------------------------------------------------------ public void CalculateNeighbors(Vector2D TargetPos, double QueryRadius) { //create the query box that is the bounding box of the target's query area InvertedAABBox2D QueryBox = new InvertedAABBox2D(TargetPos - new Vector2D(QueryRadius, QueryRadius), TargetPos + new Vector2D(QueryRadius, QueryRadius)); m_Neighbors.Clear(); Double dblDoubleRadius = QueryRadius * QueryRadius; //iterate through each cell and test to see if its bounding box overlaps //with the query box. If it does and it also contains entities then make further proximity tests. foreach (Cell curCell in m_Cells) { if ((curCell.Members.Count != 0) && curCell.BBox.isOverlappedWith(QueryBox)) { //add any entities found within query radius to the neighbor list foreach (MovingEntity objEntity in curCell.Members) { if (Vector2D.Vec2DDistanceSq(objEntity.Pos, TargetPos) < dblDoubleRadius) { m_Neighbors.Add(objEntity); } } } } // next cell }
private void renderBox(InvertedAABBox2D objBox, Graphics objGraphics, Pen objPen) { objGraphics.DrawLine(objPen, (int)objBox.Left(), (int)objBox.Top(), (int)objBox.Right(), (int)objBox.Top()); objGraphics.DrawLine(objPen, (int)objBox.Left(), (int)objBox.Bottom(), (int)objBox.Right(), (int)objBox.Bottom()); objGraphics.DrawLine(objPen, (int)objBox.Left(), (int)objBox.Top(), (int)objBox.Left(), (int)objBox.Bottom()); objGraphics.DrawLine(objPen, (int)objBox.Right(), (int)objBox.Top(), (int)objBox.Right(), (int)objBox.Bottom()); }
public void Render(Graphics objGraphics) { if (isFollowPathOn()) { MovingEntity objSharkie = getVehicleByID(m_intSharkieID); RenderPath2D(objSharkie.Steering().GetPath(), objGraphics, objPathPen); } foreach (MovingEntity objVehicle in m_Vehicles) { Pen objDrawPen = objVehiclePen; if (isPursuitOn() && (objVehicle.ID() == m_intVictimID)) { objDrawPen = objTargetPen; } if (m_blnNonePenetrationOn) { List<MovingEntity> ListTouched = MovingEntity.EnforceNonPenetrationConstraint(objVehicle, m_Vehicles); if (ListTouched.Count > 0) { if (objVehicle.ID() == m_intSharkieID) { objDrawPen = objRedPen; } else { objDrawPen = objDarkPen; } } } RenderVehicle(objVehicle, objGraphics, objDrawPen); if (m_blnRenderAids) { if ((objVehicle.ID() == m_intSharkieID)) { Vector2D vecForce = (Vector2D)(objVehicle.Steering().Force() / SteerParams.Instance.SteeringForceTweaker); vecForce.X = (vecForce.X * 2) * objVehicle.Scale().X; vecForce.Y = (vecForce.Y * 2) * objVehicle.Scale().Y; objGraphics.DrawLine(objRedPen, (PointF)objVehicle.Pos, (PointF)(objVehicle.Pos + vecForce)); objGraphics.DrawEllipse(objVehiclePen, (int)(objVehicle.Pos.X - SteerParams.Instance.ViewDistance), (int)(objVehicle.Pos.Y - SteerParams.Instance.ViewDistance), (int)SteerParams.Instance.ViewDistance * 2, (int)SteerParams.Instance.ViewDistance * 2); renderDetectionBox(objVehicle, objGraphics, objVehiclePen); } else if ((objVehicle.ID() == m_intVictimID) && GameWorld.Instance.SpacePartitioningOn && isPursuitOn()) { InvertedAABBox2D box = new InvertedAABBox2D(objVehicle.Pos - new Vector2D(SteerParams.Instance.ViewDistance, SteerParams.Instance.ViewDistance), objVehicle.Pos + new Vector2D(SteerParams.Instance.ViewDistance, SteerParams.Instance.ViewDistance)); renderBox(box, objGraphics, objTargetPen); GameWorld.Instance.CellSpaces.CalculateNeighbors(objVehicle.Pos, SteerParams.Instance.ViewDistance); foreach (MovingEntity objNeighbour in GameWorld.Instance.CellSpaces.ListOfNeighbours()) { if (objNeighbour.ID() != m_intSharkieID) { RenderObstacle(objNeighbour, objGraphics, objGrayPen); } } objGraphics.DrawEllipse(objGrayPen, (int)(objVehicle.Pos.X - SteerParams.Instance.ViewDistance), (int)(objVehicle.Pos.Y - SteerParams.Instance.ViewDistance), (int)SteerParams.Instance.ViewDistance * 2, (int)SteerParams.Instance.ViewDistance * 2); } } } if (GameWorld.Instance.SpacePartitioningOn) { foreach (Cell objCell in m_pCellSpace.ListOfCells()) { renderCell(objCell, objGraphics, objCellPen, true); } } foreach (Wall2D objWall in m_Walls) { RenderWall2D(objWall, objGraphics, objWallPen, true); } foreach (BaseGameEntity objObs in m_Obstacles) { RenderObstacle(objObs, objGraphics, objObstaclePen); } if (!isPursuitOn() && !isFollowPathOn()) { RenderTarget(GameWorld.Instance.TargetPos, objGraphics, objTargetPen); } }