/// <summary> /// Draw Axes /// </summary> /// <param name="graphics"></param> protected void DrawAxes(Graphics.Graphics graphics) { float axesLength = 256.0f; GL.LineWidth(5.0f); graphics.DrawLine(Vector3.Zero, Vector3.UnitX * axesLength, Graphics.Graphics.LineType.LineNormal, Color.Red); graphics.DrawLine(Vector3.Zero, Vector3.UnitY * axesLength, Graphics.Graphics.LineType.LineNormal, Color.Green); graphics.DrawLine(Vector3.Zero, Vector3.UnitZ * axesLength, Graphics.Graphics.LineType.LineNormal, Color.Blue); GL.LineWidth(1.0f); }
/// <summary> /// Draw center /// </summary> /// <param name="graphics"></param> /// <param name="solid"></param> /// <param name="color"></param> private void DrawCenter(Graphics.Graphics graphics, MapObject solid, Color color) { // create this viewport base vectors float halfIndicitorSize = 5f * Viewport.Zoom; Matrix4 viewportMatrix = Viewport.Camera.GetWorldMatrix().ClearTranslation(); Vector3 horizontalVector = viewportMatrix.Row0.Xyz * halfIndicitorSize; Vector3 verticalVector = viewportMatrix.Row1.Xyz * halfIndicitorSize; // draw center x Vector3 center = solid.Bounds.Center; Vector3 diagonalOne = (-horizontalVector + verticalVector).Normalized() * halfIndicitorSize; Vector3 diagonalTwo = (-horizontalVector - verticalVector).Normalized() * halfIndicitorSize; graphics.DrawLine(center - diagonalOne, center + diagonalOne, RuneGear.Graphics.Graphics.LineType.LineNormal, color); graphics.DrawLine(center - diagonalTwo, center + diagonalTwo, RuneGear.Graphics.Graphics.LineType.LineNormal, color); }
/// <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> /// 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(); }