/// <summary> /// What happens when we paint /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { // clear the background e.Graphics.Clear(BackColor); // center on tracked vehicle if exists if (this.tracked != null) { // Get the offset. Point point = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); // get screen po of vehicle PointF screenCarPos = this.transform.GetScreenPoint(this.tracked.Position); // Calculate change in Position double deltaX = ((double)screenCarPos.X) - point.X; double deltaY = ((double)screenCarPos.Y) - point.Y; // Update the world Coordinates tempCenter = WorldTransform.CenterPoint; tempCenter.X += deltaX / WorldTransform.Scale; tempCenter.Y -= deltaY / WorldTransform.Scale; WorldTransform.CenterPoint = tempCenter; } // save the graphics state GraphicsState gs = e.Graphics.Save(); // set the drawing modes e.Graphics.SmoothingMode = SmoothingMode.HighQuality; e.Graphics.CompositingQuality = CompositingQuality.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.Bicubic; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // set the transform e.Graphics.Transform = transform.GetTransform(); // paint the display objects foreach (IDisplayObject obj in displayObjects) { // check if we should display the object if (obj.ShouldDraw()) { // render each object obj.Render(e.Graphics, transform); } } // render ai vehicle if (!this.DesignMode && this.aiVehicle != null && this.aiVehicle.State != null && this.aiVehicle.ShouldDraw()) { this.aiVehicle.Render(e.Graphics, transform); } // render ai information if (!this.DesignMode && RemoraCommon.aiInformation.ShouldDraw()) { RemoraCommon.aiInformation.Render(e.Graphics, transform); } // render current tool if (this.CurrentEditorTool != null && this.CurrentEditorTool.ShouldDraw()) { this.CurrentEditorTool.Render(e.Graphics, transform); } // render current tool if (this.SecondaryEditorTool != null && this.SecondaryEditorTool.ShouldDraw()) { this.SecondaryEditorTool.Render(e.Graphics, transform); } // restore the graphics state e.Graphics.Restore(gs); }
/// <summary> /// What happens when we paint /// </summary> /// <param name="e"></param> protected override void OnPaint(PaintEventArgs e) { // clear the background e.Graphics.Clear(BackColor); // center on tracked vehicle if exists if (this.tracked != null) { // Get the offset. Point point = new Point(this.ClientRectangle.Width / 2, this.ClientRectangle.Height / 2); // get screen po of vehicle PointF screenCarPos = this.transform.GetScreenPoint(this.tracked.Position); // Calculate change in Position double deltaX = ((double)screenCarPos.X) - point.X; double deltaY = ((double)screenCarPos.Y) - point.Y; // Update the world Coordinates tempCenter = WorldTransform.CenterPoint; tempCenter.X += deltaX / WorldTransform.Scale; tempCenter.Y -= deltaY / WorldTransform.Scale; WorldTransform.CenterPoint = tempCenter; } // save the graphics state GraphicsState gs = e.Graphics.Save(); // set the drawing modes e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; //.HighSpeed;//.HighQuality; e.Graphics.CompositingQuality = CompositingQuality.HighSpeed; //.HighQuality; e.Graphics.InterpolationMode = InterpolationMode.Bilinear; //.Bicubic; e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // set the transform e.Graphics.Transform = transform.GetTransform(); // paint the display objects foreach (IDisplayObject obj in displayObjects) { // check if we should display the object if (obj.ShouldDraw()) { // render each object obj.Render(e.Graphics, transform); } } // render ai vehicle if (!this.DesignMode && this.aiVehicle != null && this.aiVehicle.State != null && this.aiVehicle.ShouldDraw()) { this.aiVehicle.Render(e.Graphics, transform); } // render ai information if (!this.DesignMode && RemoraCommon.aiInformation.ShouldDraw()) { RemoraCommon.aiInformation.Render(e.Graphics, transform); } // render current tool if (!this.DesignMode && this.CurrentEditorTool != null && this.CurrentEditorTool.ShouldDraw()) { this.CurrentEditorTool.Render(e.Graphics, transform); } // render current tool if (!this.DesignMode && this.SecondaryEditorTool != null && this.SecondaryEditorTool.ShouldDraw()) { this.SecondaryEditorTool.Render(e.Graphics, transform); } // render observed vehicles if (!this.DesignMode && RemoraCommon.Communicator.GetObservedVehicles() != null) { SceneEstimatorTrackedClusterCollection setcc = RemoraCommon.Communicator.GetObservedVehicles(); for (int i = 0; i < setcc.clusters.Length; i++) { SensedVehicleDisplay svd = new SensedVehicleDisplay(setcc.clusters[i]); svd.Render(e.Graphics, this.WorldTransform); } } if (!this.DesignMode) { // render driver side sick VehicleState state = RemoraCommon.Communicator.GetVehicleState(); if (state != null) { Coordinates dvec = state.Front - state.Position; Coordinates driverVec = dvec.Rotate90(); SideObstacles dsobs = RemoraCommon.Communicator.GetSideObstacles(SideObstacleSide.Driver); if (dsobs != null) { foreach (SideObstacle so in dsobs.obstacles) { if (so.height > 0.7) { Coordinates cVec = state.Position + driverVec.Normalize(so.distance); DrawingUtility.DrawControlPoint(cVec, Color.Black, null, ContentAlignment.MiddleCenter, ControlPointStyle.LargeX, e.Graphics, this.WorldTransform); } } } // render driver side sick Coordinates pvec = state.Front - state.Position; Coordinates passVec = dvec.RotateM90(); SideObstacles psobs = RemoraCommon.Communicator.GetSideObstacles(SideObstacleSide.Passenger); if (psobs != null) { foreach (SideObstacle so in psobs.obstacles) { if (so.height > 0.7) { Coordinates cVec = state.Position + passVec.Normalize(so.distance); DrawingUtility.DrawControlPoint(cVec, Color.Black, null, ContentAlignment.MiddleCenter, ControlPointStyle.LargeX, e.Graphics, this.WorldTransform); } } } } } // render observed obstacles if (!this.DesignMode && RemoraCommon.Communicator.GetVehicleState() != null && RemoraCommon.RoadNetwork != null) { // set and render obstacleDisplay.untrackedClusters = RemoraCommon.Communicator.GetObservedObstacles(); obstacleDisplay.trackedClusters = RemoraCommon.Communicator.GetObservedVehicles(); obstacleDisplay.Render(e.Graphics, this.WorldTransform); } // restore the graphics state e.Graphics.Restore(gs); }