public Measurement GetMeasurement(Vector2 startWorldCoord, Vector2 endWorldCood)
        {
            Vector2 start = new Vector2(
                utils.GetWorldToContextX(startWorldCoord.x),
                utils.GetWorldToContextY(startWorldCoord.y)
                );

            Vector2 end = new Vector2(
                utils.GetWorldToContextX(endWorldCood.x),
                utils.GetWorldToContextY(endWorldCood.y)
                );

            Measurement measurement = new Measurement();

            measurement.x = start.x;
            measurement.y = start.y;
            float yDiff = end.y - start.y;
            float xDiff = end.x - start.x;

            measurement.h      = Mathf.Abs(yDiff);
            measurement.w      = Mathf.Abs(xDiff);
            measurement.angle  = Mathf.Atan2(yDiff, xDiff) * 180.0f / Mathf.PI;
            measurement.length = Mathf.Sqrt(Mathf.Pow(yDiff, 2) + Mathf.Pow(xDiff, 2));

            return(measurement);
        }
Example #2
0
        void DrawVRulers()
        {
            drawing.DrawTexture(resources.rulerVBg, 0, 0, stripBgSize, (int)viewPixelFrame.height);

            float camSize = contextInfo.editorCameraSize / contextInfo.scale.y;
            float rawSegmentUnitHeight = scaleTable[GetScaleKey(camSize)].cap;
            float segmentUnitHeight    = rawSegmentUnitHeight * contextInfo.scale.y;

            float startingBotUnit = viewUnitFrame.botLeft.y - segmentUnitHeight;

            startingBotUnit = startingBotUnit - (startingBotUnit % segmentUnitHeight);

            float endingTopUnit = viewUnitFrame.topLeft.y + segmentUnitHeight;

            endingTopUnit = endingTopUnit - (endingTopUnit % segmentUnitHeight);

            startingBotUnit += contextInfo.origin.y % segmentUnitHeight;;

            float runningUnit     = startingBotUnit;
            float runningPixel    = viewPixelFrame.height - utils.GetWorldToScreenPixelCoord(new Vector3(viewUnitFrame.topLeft.x, runningUnit)).y;
            float runningPixelCap = viewPixelFrame.height - utils.GetWorldToScreenPixelCoord(new Vector3(viewUnitFrame.topLeft.x, runningUnit + segmentUnitHeight)).y;
            float innerSlicesDist = (runningPixelCap - runningPixel) / 4f;

            while (runningUnit < endingTopUnit)
            {
                // Draw main coord
                DrawHLine(viewPixelFrame.topLeft.x, runningPixel, stripHiSize, resources.rulerLinePixel);
                string virtualYCoord = FormatNumber(utils.GetWorldToContextY(runningUnit), camSize);
                DrawHLineLabel(virtualYCoord.ToString(), viewPixelFrame.topLeft.x + hLineLabelXOffset, runningPixel + hLineLabelYOffset);

                // Draw slices
                runningPixel += innerSlicesDist;
                DrawHLine(viewPixelFrame.topLeft.x + stripLowOffset, runningPixel, stripLowSize, resources.rulerLinePixel);
                runningPixel += innerSlicesDist;
                DrawHLine(viewPixelFrame.topLeft.x + stripMidOffset, runningPixel, stripMidSize, resources.rulerLinePixel);
                runningPixel += innerSlicesDist;
                DrawHLine(viewPixelFrame.topLeft.x + stripLowOffset, runningPixel, stripLowSize, resources.rulerLinePixel);

                // Move to next segment
                runningUnit += segmentUnitHeight;
                runningPixel = viewPixelFrame.height - utils.GetWorldToScreenPixelCoord(new Vector3(viewUnitFrame.topLeft.x, runningUnit)).y;
            }
        }
        void CompleteGuideCreation()
        {
            if (creatingHGuide)
            {
                if (state.snapGuideToInt)
                {
                    int contextY = Mathf.RoundToInt(utils.GetWorldToContextY(liveGuide.y));
                    liveGuide.y = utils.GetContextToWorldY(contextY);
                }

                // pure zero is reserved for logical testing
                if (liveGuide.y == 0)
                {
                    liveGuide.y = Globals.FALSE_ZERO;
                }

                state.hGuides.Add(liveGuide.y.ToString());
            }
            else
            {
                if (state.snapGuideToInt)
                {
                    int contextX = Mathf.RoundToInt(utils.GetWorldToContextX(liveGuide.x));
                    liveGuide.x = utils.GetContextToWorldX(contextX);
                }

                // pure zero is reserved for logical testing
                if (liveGuide.x == 0)
                {
                    liveGuide.x = Globals.FALSE_ZERO;
                }

                state.vGuides.Add(liveGuide.x.ToString());
            }

            liveGuide           = Vector2.zero;
            creatingHGuide      = false;
            creatingVGuide      = false;
            state.displayGuides = true;
            utils.RepaintEditorWindow();
        }
Example #4
0
        public void DrawCoords()
        {
            drawing.BeginGUIArea(displayCoordXOffset, displayCoordYOffset, viewPixelFrame.width, viewPixelFrame.height);
            drawing.BeginGUIVertical();

            if (measure.IsMeasureToolActive())
            {
                ExecDrawMeasureAlert();
            }

            if (state.displayCoords)
            {
                List <Transform> transforms = R2DC_Selection.Instance.GetSelection();
                for (int i = 0; i < transforms.Count; i++)
                {
                    Transform transform = transforms[i];

                    if (transform == null)
                    {
                        // selection must be dirty
                        R2DC_Selection.Instance.UpdateSelection();
                        return;
                    }

                    ExecDrawCoord(transform.name, transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
                }
            }

            // live guides
            Vector2 liveGuide = guides.liveGuide;

            if (liveGuide.x != 0)
            {
                float x = utils.GetWorldToContextX(liveGuide.x);
                if (state.snapGuideToInt)
                {
                    x = Mathf.RoundToInt(x);
                }
                ExecDrawCoord(R2DD_Lang.guide, x, 0, 0);
            }
            else if (liveGuide.y != 0)
            {
                float y = utils.GetWorldToContextY(liveGuide.y);
                if (state.snapGuideToInt)
                {
                    y = Mathf.RoundToInt(y);
                }
                ExecDrawCoord(R2DD_Lang.guide, 0, y, 0);
            }
            else
            {
                // hover guides
                Vector2 hoverGuide = guides.hoverGuide;
                if (hoverGuide.x != 0)
                {
                    float x = utils.GetWorldToContextX(hoverGuide.x);
                    if (x == Globals.FALSE_ZERO)
                    {
                        x = 0;
                    }
                    ExecDrawCoord(R2DD_Lang.guide, x, 0, 0);
                }
                else if (hoverGuide.y != 0)
                {
                    float y = utils.GetWorldToContextY(hoverGuide.y);
                    if (y == Globals.FALSE_ZERO)
                    {
                        y = 0;
                    }
                    ExecDrawCoord(R2DD_Lang.guide, 0, y, 0);
                }
            }

            drawing.EndGUIVertical();
            drawing.EndGUIArea();
        }