コード例 #1
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL();

            double snappingRadians = MathHelper.Tau / numSnapPoints;
            var    clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World);

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                VertexStorage snapShape = new VertexStorage();
                snapShape.MoveTo(-10, 0);
                snapShape.LineTo(5, 7);
                snapShape.LineTo(5, -7);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = Color.Black;
                if (i == markToSnapTo)
                {
                    color = Color.Red;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
コード例 #2
0
        private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo)
        {
            var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale);

            double snappingRadians = MathHelper.Tau / numSnapPoints;

            for (int i = 0; i < numSnapPoints; i++)
            {
                double startAngle = i * snappingRadians + mouseAngle;

                var snapShape = new VertexStorage();
                var scale     = GuiWidget.DeviceScale;
                snapShape.MoveTo(-10 * scale, 0);
                snapShape.LineTo(5 * scale, 7 * scale);
                snapShape.LineTo(5 * scale, -7 * scale);
                snapShape.ClosePolygon();

                var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle));
                // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius);

                var color = theme.TextColor;
                if (i == markToSnapTo)
                {
                    color = theme.PrimaryAccentColor;
                }

                graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered);
            }
        }
コード例 #3
0
        private void DrawRotationCompass(IObject3D selectedItem, DrawGlContentEventArgs drawEventArgs)
        {
            if (InteractionContext.Scene.SelectedItem == null)
            {
                return;
            }

            double alphaValue = 1;

            if (!drawEventArgs.ZBuffered)
            {
                alphaValue = .3;
            }

            AxisAlignedBoundingBox currentSelectedBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);

            if (currentSelectedBounds.XSize > 100000)
            {
                // something is wrong the part is too big (probably in invalid selection)
                return;
            }
            Vector3 controlCenter  = GetControlCenter(selectedItem);
            Vector3 rotationCenter = GetRotationCenter(selectedItem, currentSelectedBounds);

            if (mouseDownInfo != null)
            {
                rotationCenter = mouseDownInfo.SelectedObjectRotationCenter;
                controlCenter  = mouseDownInfo.ControlCenter;
            }

            if (mouseMoveInfo != null)
            {
                double distBetweenPixelsWorldSpace = InteractionContext.World.GetWorldUnitsPerScreenPixelAtPosition(rotationCenter);

                double    radius;
                Matrix4X4 rotationCenterTransform = GetRotationTransform(selectedItem, out radius);

                double innerRadius        = radius + ringWidth / 2;
                double outerRadius        = innerRadius + ringWidth;
                double snappingMarkRadius = outerRadius + 20;

                double startBlue = 0;
                double endBlue   = MathHelper.Tau;

                double mouseAngle = 0;
                if (mouseMoveInfo != null)
                {
                    mouseAngle = mouseMoveInfo.AngleOfHit;
                }
                if (mouseDownInfo != null)
                {
                    mouseAngle = mouseDownInfo.AngleOfHit;
                }

                var graphics2DOpenGL = new Graphics2DOpenGL();

                if (mouseDownInfo != null || MouseOver)
                {
                    IVertexSource blueRing = new JoinPaths(new Arc(0, 0, outerRadius, outerRadius, startBlue, endBlue, Arc.Direction.CounterClockWise),
                                                           new Arc(0, 0, innerRadius, innerRadius, startBlue, endBlue, Arc.Direction.ClockWise));
                    graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, blueRing, new Color(Color.Blue, (int)(50 * alphaValue)), drawEventArgs.ZBuffered);
                    // tick 60 marks
                    DrawTickMarks(drawEventArgs, alphaValue, rotationCenterTransform, innerRadius, outerRadius, 60);
                }

                if (mouseDownInfo != null)
                {
                    double startRed = mouseDownInfo.AngleOfHit;
                    double endRed   = SnappedRotationAngle + mouseDownInfo.AngleOfHit;

                    if (!rotatingCW)
                    {
                        var temp = startRed;
                        startRed = endRed;
                        endRed   = temp;
                    }

                    IVertexSource redAngle = new JoinPaths(new Arc(0, 0, 0, 0, startRed, endRed, Arc.Direction.CounterClockWise),
                                                           new Arc(0, 0, innerRadius, innerRadius, startRed, endRed, Arc.Direction.ClockWise));
                    graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, redAngle, new Color(Color.Red, (int)(70 * alphaValue)), drawEventArgs.ZBuffered);

                    // draw a line to the mouse on the rotation circle
                    if (mouseMoveInfo != null && MouseDownOnControl)
                    {
                        Vector3 unitPosition  = new Vector3(Math.Cos(mouseMoveInfo.AngleOfHit), Math.Sin(mouseMoveInfo.AngleOfHit), 0);
                        Vector3 startPosition = Vector3Ex.Transform(unitPosition * innerRadius, rotationCenterTransform);
                        var     center        = Vector3Ex.Transform(Vector3.Zero, rotationCenterTransform);
                        if ((mouseMoveInfo.HitPosition - center).Length > rotationTransformScale * innerRadius)
                        {
                            InteractionContext.World.Render3DLine(startPosition, mouseMoveInfo.HitPosition, Color.Red, drawEventArgs.ZBuffered);
                        }

                        DrawSnappingMarks(drawEventArgs, mouseAngle, alphaValue, rotationCenterTransform, snappingMarkRadius, 5, numSnapPoints, GetSnapIndex(selectedItem, numSnapPoints));
                    }
                }
            }
        }