/// <summary> /// Renders the lane splint /// </summary> /// <param name="g"></param> /// <param name="t"></param> /// <remarks>TODO: set lane spline</remarks> public void Render(System.Drawing.Graphics g, WorldTransform t) { Color c = DrawingUtility.ColorArbiterLaneSpline; if (DrawingUtility.DisplayArbiterLanes) { Coordinates cp = t.GetWorldPoint(new PointF(t.ScreenSize.Width / 2, t.ScreenSize.Height / 2)); Coordinates lp = this.LanePath().GetClosestPoint(cp).Location; string s = this.LaneId.ToString(); DrawingUtility.DrawControlLabel(lp, Color.DarkBlue, s, ContentAlignment.MiddleCenter, ControlPointStyle.None, g, t); } bool displayPolygon = false; switch (this.LaneId.Number) { case 1: displayPolygon = DrawingUtility.DisplayArbiterLanePolygon1; break; case 2: displayPolygon = DrawingUtility.DisplayArbiterLanePolygon2; break; case 3: displayPolygon = DrawingUtility.DisplayArbiterLanePolygon3; break; case 4: displayPolygon = DrawingUtility.DisplayArbiterLanePolygon4; break; } if (displayPolygon && this.LanePolygon != null) { // show intersection polygon HatchBrush hBrush1 = new HatchBrush(HatchStyle.ForwardDiagonal, DrawingUtility.ColorArbiterLanePolygon, Color.White); // populate polygon List <PointF> polyPoints = new List <PointF>(); foreach (Coordinates lpp in this.LanePolygon.points) { polyPoints.Add(DrawingUtility.ToPointF(lpp)); } // draw poly and fill g.FillPolygon(hBrush1, polyPoints.ToArray()); DrawingUtility.DrawControlPolygon(this.LanePolygon, DrawingUtility.ColorArbiterLanePolygon, System.Drawing.Drawing2D.DashStyle.Solid, g, t); } if (DrawingUtility.DisplayArbiterLanePath) { DrawingUtility.DrawControlLine(this.laneLinePath, g, t, new Pen(Color.MediumVioletRed), Color.MediumVioletRed); } }
public void Render(System.Drawing.Graphics g, WorldTransform t) { // default color Color c = DrawingUtility.ColorSimObstacles; // check selection if (this.selected == SelectionType.SingleSelected) { c = DrawingUtility.ColorSimSelectedObstacle; } else if (this.isBlockage) { c = DrawingUtility.ColorSimObstacleBlockage; } // draw box // width of drawing float penWidth = nomPixelWidth / t.Scale; // body rectangle RectangleF bodyRect = new RectangleF((float)(-(float)this.Width / 2), (-(float)this.Length / 2), (float)Width, (float)Length); // body transformation matrix Matrix bodyTrans = new Matrix(); bodyTrans.Rotate((float)(this.Heading.ToDegrees() - 90)); bodyTrans.Translate((float)Position.X, (float)Position.Y, MatrixOrder.Append); // save original world transformation matrix Matrix origTrans = g.Transform.Clone(); bodyTrans.Multiply(g.Transform, MatrixOrder.Append); // set the new transform g.Transform = bodyTrans; // make a new pen and draw obstacle body using (Pen p = new Pen(c, penWidth)) { g.DrawRectangle(p, bodyRect.X, bodyRect.Y, bodyRect.Width, bodyRect.Height); } // return to normal transformation g.Transform = origTrans; // draw id if (DrawingUtility.DrawSimObstacleIds) { DrawingUtility.DrawControlLabel(this.Position, c, this.ObstacleId.ToString(), ContentAlignment.MiddleCenter, ControlPointStyle.SmallX, g, t); } else { DrawingUtility.DrawControlPoint(this.Position, c, null, ContentAlignment.MiddleCenter, ControlPointStyle.SmallX, g, t); } }
public void Render(System.Drawing.Graphics g, WorldTransform t) { // width of drawing float penWidth = nomPixelWidth / t.Scale; // body rectangle RectangleF bodyRect = new RectangleF((float)(-this.Width / 2), -rearOffset, (float)Width, (float)Length); // body transformation matrix Matrix bodyTrans = new Matrix(); bodyTrans.Rotate((float)(this.Heading.ToDegrees() - 90)); bodyTrans.Translate((float)Position.X, (float)Position.Y, MatrixOrder.Append); // save original world transformation matrix Matrix origTrans = g.Transform.Clone(); bodyTrans.Multiply(g.Transform, MatrixOrder.Append); // set the new transform g.Transform = bodyTrans; // make a new pen and draw wheels using (Pen p = new Pen(color, penWidth)) { DrawRectangle(g, p, bodyRect); // build the transform for the rear wheels // do the left wheel Matrix wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-wheelOffset, 0, MatrixOrder.Prepend); g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(wheelOffset, 0, MatrixOrder.Prepend); g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); // do the front wheels // do the left wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(-wheelOffset, wheelbase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectL); DrawRectangle(g, p, wheelRectL); // do the right wheel wheelTransform = bodyTrans.Clone(); wheelTransform.Translate(wheelOffset, wheelbase, MatrixOrder.Prepend); wheelTransform.Rotate(steeringAngle * 180 / (float)Math.PI, MatrixOrder.Prepend); g.Transform = wheelTransform; g.FillRectangle(Brushes.White, wheelRectR); DrawRectangle(g, p, wheelRectR); } // return to normal transformation g.Transform = origTrans; // draw car center point DrawingUtility.DrawControlPoint(this.Position, this.color, null, ContentAlignment.MiddleCenter, ControlPointStyle.LargeX, g, t); // check if should draw id if (DrawingUtility.DrawSimCarId) { // get length double idOffset = this.Length / 2; if (this.RearAxleType == RearAxleType.Center) { idOffset = this.Length / 3; } // get label position Coordinates labelPosition = this.Position + this.Heading.Normalize(idOffset); // draw label DrawingUtility.DrawControlLabel(labelPosition, this.color, this.Id, ContentAlignment.MiddleCenter, ControlPointStyle.None, g, t); } }