public override void OnRender(Graphics.Graphics graphics, BaseViewport viewport) { BaseViewportCamera camera = viewport.Camera; Matrix4 vpMatrix4 = camera.GetViewMatrix() * camera.GetProjMatrix(); SolidRenderOperation render = new SolidRenderOperation { Viewport = viewport, Graphics = graphics }; // Draw all solids if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Enable(EnableCap.DepthTest); } graphics.BeginDraw(vpMatrix4); foreach (MapObject mapObject in controller.SceneDocument) { if (mapObject.Selected) { continue; } mapObject.PerformOperation(render); } controller.Selection?.PerformOperation(render); graphics.EndDraw(); if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Disable(EnableCap.DepthTest); } // Draw white wireframesolid on top of selection // only in Solid rendermode graphics.BeginDraw(vpMatrix4); if (viewport.RenderMode == BaseViewport.RenderModes.SOLID || viewport.RenderMode == BaseViewport.RenderModes.TEXTURED) { Color color = viewport.RenderMode == BaseViewport.RenderModes.TEXTURED ? Color.Yellow : Color.White; DoSolidAction(controller.Selection, (solid) => { graphics.DrawWireframeSolid(solid, color); }); } graphics.EndDraw(); // draw handles and blanket on top of everything else RenderAllVertexHandles(graphics, viewport); RenderBlanket(graphics, viewport); }
private void RenderCrosshair(Graphics.Graphics graphics) { // render cross if captured the mouse if (CapturedMouse) { graphics.BeginDraw(MathExtensions.CreateOrthographicLH(mWidth, mHeight, 0, 1.0f)); graphics.DrawSolidRectangle(Vector3.UnitX * -CROSS_SIZE + -Vector3.UnitY, Vector3.UnitX * CROSS_SIZE + -Vector3.UnitY, Vector3.UnitX * CROSS_SIZE + Vector3.UnitY, Vector3.UnitX * -CROSS_SIZE + Vector3.UnitY, Color.White); graphics.DrawSolidRectangle(Vector3.UnitY * -CROSS_SIZE + -Vector3.UnitX, Vector3.UnitY * -CROSS_SIZE + Vector3.UnitX, Vector3.UnitY * CROSS_SIZE + Vector3.UnitX, Vector3.UnitY * CROSS_SIZE + -Vector3.UnitX, Color.White); graphics.EndDraw(); } }
/// <summary> /// Renders a overlay for the viewport /// </summary> /// <param name="graphics"></param> protected virtual void RenderOverlay(Graphics.Graphics graphics) { Color overlayColor = SystemColors.Control; Vector3 pointOne = new Vector3(OVERLAY_GAP, OVERLAY_GAP, 0); Vector3 pointTwo = new Vector3(mWidth - OVERLAY_GAP, OVERLAY_GAP, 0); Vector3 pointThree = new Vector3(mWidth - OVERLAY_GAP, mHeight - OVERLAY_GAP, 0); Vector3 pointFour = new Vector3(OVERLAY_GAP, mHeight - OVERLAY_GAP, 0); graphics.BeginDraw(Matrix4.CreateOrthographicOffCenter(0, mWidth, mHeight, 0, 0, 1)); graphics.DrawLine(pointOne, pointTwo, Graphics.Graphics.LineType.LineNormal, overlayColor); graphics.DrawLine(pointTwo, pointThree, Graphics.Graphics.LineType.LineNormal, overlayColor); graphics.DrawLine(pointThree, pointFour, Graphics.Graphics.LineType.LineNormal, overlayColor); graphics.DrawLine(pointFour, pointOne, Graphics.Graphics.LineType.LineNormal, overlayColor); graphics.EndDraw(); }
/// <summary> /// Only draw for the current viewport that is doing the action /// </summary> /// <param name="graphics"></param> /// <param name="viewport"></param> private void RenderBlanket(Graphics.Graphics graphics, BaseViewport viewport) { if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE && coverBlanket.HasVolume2D && currentActionViewport == viewport.ViewportType) { Vector3 bottomLeft = new Vector3(coverBlanket.Min.X, coverBlanket.Min.Y, 0); Vector3 bottomRight = new Vector3(coverBlanket.Max.X, coverBlanket.Min.Y, 0); Vector3 topRight = new Vector3(coverBlanket.Max.X, coverBlanket.Max.Y, 0); Vector3 topLeft = new Vector3(coverBlanket.Min.X, coverBlanket.Max.Y, 0); graphics.BeginDraw(Matrix4.CreateOrthographicOffCenter(0, viewport.Width, viewport.Height, 0, 0, 1)); //Color blanketColor = Color.FromArgb(64, Color.LightSkyBlue); //renderer.DrawSolidRectangle(topLeft, topRight, bottomRight, bottomLeft, blanketColor); // TODO FIX winding....??!?!?!? graphics.DrawRectangle(bottomLeft, bottomRight, topRight, topLeft, Graphics.Graphics.LineType.LineDashed, Color.DeepSkyBlue); graphics.EndDraw(); } }
public override void OnRender(Graphics.Graphics graphics, BaseViewport viewport) { BaseViewportCamera camera = viewport.Camera; SolidRenderOperation render = new SolidRenderOperation { Viewport = viewport, Graphics = graphics }; // Draw all solid if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Enable(EnableCap.DepthTest); } graphics.BeginDraw(camera.GetViewMatrix() * camera.GetProjMatrix()); foreach (MapObject mapObject in controller.SceneDocument) { if (mapObject.Selected) { continue; } mapObject.PerformOperation(render); } controller.Selection?.PerformOperation(render); graphics.EndDraw(); if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Disable(EnableCap.DepthTest); } }
/// <summary> /// Renders the grid on the viewport /// </summary> /// <param name="graphics"></param> private void DrawGrid(Graphics.Graphics graphics) { Matrix4 translationViewMatrix = mCamera.GetViewMatrix().ClearRotation(); Matrix4 viewProjMatrix = translationViewMatrix * mCamera.GetProjMatrix(); // get info from the settings Color minorGridColor = controller.EditorSettings.GetColor("minorGridColor"); Color majorGridColor = controller.EditorSettings.GetColor("majorGridColor"); Color originGridColor = controller.EditorSettings.GetColor("originGridColor"); int hideLinesLower = controller.EditorSettings.HideLinesLower; int majorLineEvery = controller.EditorSettings.MajorLineEvery; int gridDim = 1 << 14; // 16384 dimensions float[] bounds = { float.MaxValue, float.MaxValue, -float.MaxValue, -float.MaxValue }; Vector3[] worldExtends = new Vector3[4]; // hide lines if grid is smaller than specified number int gridSize = mGridSizeInPixels; while ((gridSize / mCamera.Zoom) < hideLinesLower) { gridSize *= majorLineEvery; } // get the 4 world space corner points if (!ViewportToGridPlane(0, 0, GetGridPlane(), ref worldExtends[0])) { return; } if (!ViewportToGridPlane(mWidth, 0, GetGridPlane(), ref worldExtends[1])) { return; } if (!ViewportToGridPlane(mWidth, mHeight, GetGridPlane(), ref worldExtends[2])) { return; } if (!ViewportToGridPlane(0, mHeight, GetGridPlane(), ref worldExtends[3])) { return; } // get bounding box for (int i = 0; i < 4; i++) { // convert to default space (x,y) Matrix4 fromGridMatrix = mCamera.GetViewMatrix().ClearTranslation(); worldExtends[i] = worldExtends[i].TransformL(fromGridMatrix); if (worldExtends[i].X < bounds[0]) { bounds[0] = worldExtends[i].X; } if (worldExtends[i].Y < bounds[1]) { bounds[1] = worldExtends[i].Y; } if (worldExtends[i].X > bounds[2]) { bounds[2] = worldExtends[i].X; } if (worldExtends[i].Y > bounds[3]) { bounds[3] = worldExtends[i].Y; } } float gridWidth = bounds[2] - bounds[0]; // max.x - min.x float gridHeight = bounds[3] - bounds[1]; // max.y - min.y int gridCountX = (int)gridWidth / gridSize + 4; int gridCountY = (int)gridHeight / gridSize + 4; int gridStartX = (int)bounds[0] / gridSize - 1; int gridStartY = (int)bounds[1] / gridSize - 1; // Set line start and line end in world space coordinates float lineStartX = gridStartX * gridSize; float lineStartY = gridStartY * gridSize; float lineEndX = (gridStartX + (gridCountX - 1)) * gridSize; float lineEndY = (gridStartY + (gridCountY - 1)) * gridSize; // keep line start and line end inside the grid dimensions lineStartX = (lineStartX < -gridDim) ? -gridDim : lineStartX; lineStartY = (lineStartY < -gridDim) ? -gridDim : lineStartY; lineEndX = (lineEndX > gridDim) ? gridDim : lineEndX; lineEndY = (lineEndY > gridDim) ? gridDim : lineEndY; // make sure we have anything to render if (gridCountX + gridCountY <= 0) { return; } // start drawing the grid graphics.BeginDraw(viewProjMatrix); // the grid lines are ordered as minor, major, origin for (int lineType = 0; lineType < 3; lineType++) { Color lineColor = minorGridColor; if (lineType == 1) { lineColor = majorGridColor; } else if (lineType == 2) { lineColor = originGridColor; } // draw horizontal lines first for (int i = gridStartY; i < gridStartY + gridCountY; ++i) { // skip lines that are out of bound if (i * gridSize < -gridDim || i * gridSize > gridDim) { continue; } // skip any line that don't match the line type we're adding if (lineType == 0 && (i == 0 || (i % majorLineEvery) == 0)) { continue; } else if (lineType == 1 && (i == 0 || (i % majorLineEvery) != 0)) { continue; } else if (lineType == 2 && i != 0) { continue; } // draw the line graphics.DrawLine(new Vector3(lineStartX, (float)i * gridSize, 0.0f), new Vector3(lineEndX, (float)i * gridSize, 0.0f), Graphics.Graphics.LineType.LineNormal, lineColor); } // draw horizontal lines first for (int i = gridStartX; i < gridStartX + gridCountX; ++i) { // skip lines that are out of bound if (i * gridSize < -gridDim || i * gridSize > gridDim) { continue; } // skip any line that don't match the line type we're adding if (lineType == 0 && (i == 0 || (i % majorLineEvery) == 0)) { continue; } else if (lineType == 1 && (i == 0 || (i % majorLineEvery) != 0)) { continue; } else if (lineType == 2 && i != 0) { continue; } // draw the line graphics.DrawLine(new Vector3((float)i * gridSize, lineStartY, 0.0f), new Vector3((float)i * gridSize, lineEndY, 0.0f), Graphics.Graphics.LineType.LineNormal, lineColor); } } graphics.EndDraw(); }
public override void OnRender(Graphics.Graphics graphics, BaseViewport viewport) { BaseViewportCamera camera = viewport.Camera; RubberBand rubberband = controller.RubberBand; SolidRenderOperation render = new SolidRenderOperation { Viewport = viewport, Graphics = graphics }; // Draw all solids if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Enable(EnableCap.DepthTest); } graphics.BeginDraw(camera.GetViewMatrix() * camera.GetProjMatrix()); foreach (MapObject mapObject in controller.SceneDocument) { if (mapObject.Selected) { continue; } mapObject.PerformOperation(render); } controller.Selection?.PerformOperation(render); // only in orthographic viewport if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE) { // draw rubberband if (rubberband.Bounds.HasVolume2D) { graphics.DrawWireframeAabb(rubberband.Bounds, Graphics.Graphics.LineType.LineDashed, rubberband.Color, rubberband.Transformation, viewport.Zoom); } else { // draw "rubberband" for the selection graphics.DrawWireframeAabb(controller.Selection?.Bounds, Graphics.Graphics.LineType.LineDashed, viewport.RenderMode == BaseViewport.RenderModes.SOLID ? Color.Yellow : Color.Red, Matrix4.Identity, viewport.Zoom); } // draw grabhandles for selection if (controller.RubberBand.ShowGrabhandles) { SolidGrabHandles handles = controller.RubberBand.Handles; Matrix4 viewportMatrix = viewport.Camera.GetWorldMatrix().ClearTranslation(); handles.CreateHandles(controller.Selection, viewportMatrix, viewport.Zoom); handles.Render(graphics); } } graphics.EndDraw(); if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { GL.Disable(EnableCap.DepthTest); } }
private void RenderAllVertexHandles(Graphics.Graphics graphics, BaseViewport viewport) { int nearDepth = 1; int farDepth = 0; //TODO check why this is neccessary if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE) { nearDepth = 0; farDepth = 1; } // handle vertices are already in NDC space when send to the graphicscard GL.Clear(ClearBufferMask.DepthBufferBit); GL.DepthRange(nearDepth, farDepth); GL.Enable(EnableCap.DepthTest); graphics.BeginDraw(Matrix4.Identity); Vector3 handleDimensions = new Vector3((float)HandleSize / viewport.Width, (float)HandleSize / viewport.Height, 0.0f); Matrix4 vpMatrix = viewport.Camera.GetViewMatrix() * viewport.Camera.GetProjMatrix(); Handle handle = new Handle(); List <Handle> selectedHandles = new List <Handle>(); // create handles and draw non selected handles DoSolidAction(controller.Selection, (solid) => { int index = 0; foreach (Vector3 position in solid.VertexPositions) { Vector4 vec4Pos = new Vector4(position, 1.0f) * vpMatrix; Vector3 pos = vec4Pos.Xyz / vec4Pos.W; handle.BottomLeft = pos + (-Vector3.UnitX - Vector3.UnitY) * handleDimensions; handle.BottomRight = pos + (Vector3.UnitX - Vector3.UnitY) * handleDimensions; handle.TopRight = pos + (Vector3.UnitX + Vector3.UnitY) * handleDimensions; handle.TopLeft = pos + (-Vector3.UnitX + Vector3.UnitY) * handleDimensions; if (solid.SelectedVertices.Contains(index)) { selectedHandles.Add(handle); index++; continue; } index++; graphics.DrawSolidRectangle(handle.BottomLeft, handle.BottomRight, handle.TopRight, handle.TopLeft, Color.White); graphics.DrawRectangle(handle.BottomLeft, handle.BottomRight, handle.TopRight, handle.TopLeft, Graphics.Graphics.LineType.LineNormal, Color.Black); } }); graphics.EndDraw(); GL.Clear(ClearBufferMask.DepthBufferBit); graphics.BeginDraw(Matrix4.Identity); //draw selected handles foreach (Handle selectedHandle in selectedHandles) { graphics.DrawSolidRectangle(selectedHandle.BottomLeft, selectedHandle.BottomRight, selectedHandle.TopRight, selectedHandle.TopLeft, Color.Red); graphics.DrawRectangle(selectedHandle.BottomLeft, selectedHandle.BottomRight, selectedHandle.TopRight, selectedHandle.TopLeft, Graphics.Graphics.LineType.LineNormal, Color.Black); } graphics.EndDraw(); GL.Disable(EnableCap.DepthTest); GL.DepthRange(farDepth, nearDepth); }