void SetupDir()
        {
            switch (followType)
            {
            case FollowType.Transform:
                mainRigidbody.isKinematic = true;
                break;

            case FollowType.Rigidbody:
                mainRigidbody.constraints = RigidbodyConstraints.None;
                if (lockInactiveAxis)
                {
                    mainRigidbody.constraints = AxisUtil.GetRigidbodyConstraints(axis, Axis.None);
                }

                if (lockInverse)
                {
                    mainRigidbody.constraints |= RigidbodyConstraints.FreezeRotation;
                }
                break;

            case FollowType.Joint:
                mainRigidbody.constraints = RigidbodyConstraints.None;
                if (lockInactiveAxis)
                {
                    mainRigidbody.constraints = AxisUtil.GetRigidbodyConstraints(axis, Axis.None);
                }

                if (lockInverse)
                {
                    mainRigidbody.constraints |= RigidbodyConstraints.FreezeRotation;
                }
                break;
            }
        }
Example #2
0
            private void CreatePlaneMesh()
            {
                // Create the grid plane as a combination of 4 quadrants. This allows us to draw them differently
                // depending on various factors e.g. camera position.

                // Each quadrant can be defined by a min and a max point. Each quadrant is labeled below for reference.
                //
                // min ----------------- a axis
                //     |   Q   |   W   |
                //     -----------------    <- center point is grid origin (0, 0, 0)
                //     |   E   |   R   |
                //     -----------------
                // b axis			   max

                GridPoint aAxisOriginOffset = -1 * GridPoint.Scale(m_gridData.gridOrigin, AxisUtil.GetVector(aAxis));
                GridPoint bAxisOriginOffset = -1 * GridPoint.Scale(m_gridData.gridOrigin, AxisUtil.GetVector(bAxis));

                GridPoint aAxisMaxOffset = m_gridData.GridPositionToGridPoint(AxisUtil.GetVector(aAxis) * m_gridData.gridSize) + aAxisOriginOffset;
                GridPoint bAxisMaxOffset = m_gridData.GridPositionToGridPoint(AxisUtil.GetVector(bAxis) * m_gridData.gridSize) + bAxisOriginOffset;

                GridPoint qMin = aAxisOriginOffset + bAxisOriginOffset;
                GridPoint wMin = bAxisOriginOffset;
                GridPoint eMin = aAxisOriginOffset;
                GridPoint rMin = GridPoint.zero;
                GridPoint qMax = rMin;
                GridPoint wMax = aAxisMaxOffset;
                GridPoint eMax = bAxisMaxOffset;
                GridPoint rMax = aAxisMaxOffset + bAxisMaxOffset;

                CreateMeshQuadrant(Quadrant.Q, qMin, qMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.W, wMin, wMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.E, eMin, eMax, aAxis, bAxis);
                CreateMeshQuadrant(Quadrant.R, rMin, rMax, aAxis, bAxis);
            }
Example #3
0
            private void DrawSelectionPlaneReferenceLines(Quadrant quadrant, Transform transform)
            {
                Color originalColor = Handles.color;
                Color lineColor     = GridSettings.instance.planeReferenceStyle == ReferenceLineStyle.SingleColor ?
                                      GridSettings.instance.planeReferenceColor : GetAxisColor(m_axis);

                lineColor.a   = 1f;
                Handles.color = lineColor;

                Vector3 gridPosition = m_gridData.WorldToGridPosition(transform.position);

                float aStart = ((quadrant & Quadrant.QE) != 0) ? -m_gridData.gridOrigin.GetComponent(aAxis) : 0f;
                float bStart = ((quadrant & Quadrant.QW) != 0) ? -m_gridData.gridOrigin.GetComponent(bAxis) : 0f;
                float aEnd   = ((quadrant & Quadrant.QE) != 0) ? 0f : m_gridData.gridSize - m_gridData.gridOrigin.GetComponent(aAxis);
                float bEnd   = ((quadrant & Quadrant.QW) != 0) ? 0f : m_gridData.gridSize - m_gridData.gridOrigin.GetComponent(bAxis);

                Vector3 start = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(aAxis) * aStart;
                Vector3 end   = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(aAxis) * aEnd;

                Handles.DrawLine(start, end);

                start = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(bAxis) * bStart;
                end   = gridPosition.GetComponentVector(m_axis) + AxisUtil.GetVector(bAxis) * bEnd;
                Handles.DrawLine(start, end);

                Handles.color = originalColor;
            }
Example #4
0
            private void DrawSelectionAxisReferenceLines(Transform transform)
            {
                Color originalColor = Handles.color;
                Color lineColor     = GridSettings.instance.axisReferenceStyle == ReferenceLineStyle.SingleColor ?
                                      GridSettings.instance.axisReferenceColor : GetAxisColor(m_axis);

                lineColor.a   = 1f;
                Handles.color = lineColor;

                Vector3 gridPosition  = m_gridData.WorldToGridPosition(transform.position);
                Vector3 planePosition = Vector3.Scale(gridPosition, Vector3.one - AxisUtil.GetVector(m_axis));

                if (!Mathf.Approximately(gridPosition.GetComponent(aAxis), 0f) &&
                    !Mathf.Approximately(gridPosition.GetComponent(bAxis), 0f))
                {
                    Handles.DrawLine(gridPosition, planePosition);
                }

                Handles.color = originalColor;
            }
Example #5
0
            private void CreateMeshQuadrant(Quadrant quadrant, GridPoint minGridPoint, GridPoint maxGridPoint, Axis aAxis, Axis bAxis)
            {
                if ((minGridPoint.x == maxGridPoint.x && m_axis != Axis.X) ||
                    (minGridPoint.y == maxGridPoint.y && m_axis != Axis.Y) ||
                    (minGridPoint.z == maxGridPoint.z && m_axis != Axis.Z))
                {
                    // one or more dimensions has 0 area, nothing to draw!
                    // note that components for this axis should be the same since that's the level we're drawing the plane at.
                    return;
                }

                Color minorColor;
                Color majorColor;

                int aMin = minGridPoint.GetComponent(aAxis);
                int bMin = minGridPoint.GetComponent(bAxis);
                int aMax = maxGridPoint.GetComponent(aAxis);
                int bMax = maxGridPoint.GetComponent(bAxis);

                minorColor   = GetAxisColor(m_axis);
                majorColor   = minorColor;
                majorColor.a = GridSettings.instance.majorLineOpacity;

                GridPoint startA = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint startB = GridPoint.Scale(minGridPoint, AxisUtil.GetVector(bAxis));
                GridPoint endA   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(aAxis));
                GridPoint endB   = GridPoint.Scale(maxGridPoint, AxisUtil.GetVector(bAxis));

                MeshBuilder gridBuilder = new MeshBuilder();

                Vector3 aAxisVector = AxisUtil.GetVector(aAxis);
                Vector3 bAxisVector = AxisUtil.GetVector(bAxis);

                int line = aMin;

                for (int a = aMin; a < aMax + 1; ++a)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint aPoint = m_gridData.GridPositionToGridPoint(a * aAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(aPoint + startB);
                    Vector3   end    = m_gridData.GridPointToGridPosition(aPoint + endB);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                line = bMin;
                for (int b = bMin; b < bMax + 1; ++b)
                {
                    Color color = (line % GridSettings.instance.majorLineSpacing) == 0 ? majorColor : minorColor;
                    ++line;

                    GridPoint bPoint = m_gridData.GridPositionToGridPoint(b * bAxisVector);
                    Vector3   start  = m_gridData.GridPointToGridPosition(bPoint + startA);
                    Vector3   end    = m_gridData.GridPointToGridPosition(bPoint + endA);

                    gridBuilder.AddVertex(start, color);
                    gridBuilder.AddVertex(end, color);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 2);
                    gridBuilder.AddIndex(gridBuilder.vertexCount - 1);
                }

                m_quadrantGrids.Add(quadrant, gridBuilder);


                // add outlines
                {
                    MeshBuilder outlineBuilder = new MeshBuilder();

                    Color color = GridSettings.instance.unfocusedColor;

                    Vector3 a = m_gridData.GridPointToGridPosition(startA + startB);
                    Vector3 b = m_gridData.GridPointToGridPosition(startA + endB);
                    Vector3 c = m_gridData.GridPointToGridPosition(endA + endB);
                    Vector3 d = m_gridData.GridPointToGridPosition(endA + startB);

                    outlineBuilder.AddVertex(a, color);
                    outlineBuilder.AddVertex(b, color);
                    outlineBuilder.AddVertex(c, color);
                    outlineBuilder.AddVertex(d, color);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 3);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 2);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);

                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 1);
                    outlineBuilder.AddIndex(outlineBuilder.vertexCount - 4);

                    m_quadrantOutlines.Add(quadrant, outlineBuilder);
                }
            }
Example #6
0
        /// <summary>
        /// Calculates the auto interval.
        /// </summary>
        protected void CalculateAutoInterval()
        {
            _isIntervalCountZero = false;
            bool isZoomig = false;

            if (CheckType())
            {
                if (ZoomCoefficient < 1 || (ZoomOffset > 0 && ZoomCoefficient < 1))
                {
                    MMinValue = ActualMinvalue + ZoomOffset * (ActualMaxvalue - ActualMinvalue);;
                    MMaxValue = MMinValue + ZoomCoefficient * (ActualMaxvalue - ActualMinvalue);
                    if (MMinValue < ActualMinvalue)
                    {
                        MMaxValue = MMaxValue + (ActualMinvalue - MMinValue);
                        MMinValue = ActualMinvalue;
                    }

                    if (MMaxValue > ActualMaxvalue)
                    {
                        MMinValue = MMinValue - (MMaxValue - ActualMaxvalue);
                        MMaxValue = ActualMaxvalue;
                    }
                    MStartValue = MMinValue;
                    isZoomig    = true;
                }
                else
                {
                    MMaxValue   = ActualMaxvalue;
                    MMinValue   = ActualMinvalue;
                    MStartValue = ActualMinvalue;
                }
                if (this.Interval == null)
                {
                    switch (ActualType)
                    {
                    case ActualType.Double:
                        //m_MinValue = Math.Floor(m_MinValue);
                        this.MInterval = (int)AxisUtil.CalculateInetrval(MMinValue, MMaxValue, MIntervalCount);
                        //m_MaxValue = m_MinValue + (m_IntervalCount * this.m_Interval);
                        break;

                    case ActualType.DateTime:
                        this.MInterval = (MMaxValue - MMinValue) / MIntervalCount;
                        break;

                    default:
                        break;
                    }

                    this.MInterval = (MMaxValue - MMinValue) / MIntervalCount;
                }
                else if (!isZoomig)
                {
                    switch (ActualType)
                    {
                    case ActualType.Double:
                        this.MIntervalCount = (int)Math.Abs((MMaxValue - MMinValue) / MInterval);
                        double tempMax = (this.MIntervalCount * this.MInterval) + MMinValue;
                        if (tempMax >= this.MMaxValue)
                        {
                            this.MMaxValue = tempMax;
                        }
                        if (tempMax < this.MMaxValue)
                        {
                            this.MMaxValue = tempMax + this.MInterval;
                            MIntervalCount++;
                        }

                        break;

                    case ActualType.DateTime:
                        this.MIntervalCount = (int)Math.Abs((MMaxValue - MMinValue) / MInterval);
                        break;

                    default:
                        break;
                    }
                    if (MIntervalCount < 1)
                    {
                        _isIntervalCountZero = true;
                    }
                    MIntervalCount = (MIntervalCount > 0) ? MIntervalCount : 1;
                }

                //if ((m_MinValue >= m_startValue + m_Interval))
                //    m_startValue = m_MinValue + (m_MinValue % m_Interval);
            }
            else
            {
                if (this.Interval == null)
                {
                    this.MInterval = 1;
                    MStartValue    = MMinValue;
                }
                else
                {
                    MIntervalCount = (int)(((int)MMaxValue - (int)MMinValue) / (int)MInterval);
                    double tempMax = (this.MIntervalCount * this.MInterval) + MMinValue;
                    if (tempMax >= this.MMaxValue)
                    {
                        this.MMaxValue = tempMax;
                    }
                    else
                    if (tempMax < this.MMaxValue)
                    {
                        this.MMaxValue = tempMax + this.MInterval;
                        MIntervalCount++;
                    }
                    if ((MMinValue >= MStartValue + MInterval))
                    {
                        MStartValue = MStartValue + MInterval;
                    }
                }
                this.MIntervalCount = (int)Math.Abs(((int)MMaxValue - (int)MMinValue) / (int)MInterval);
                MIntervalCount      = (MIntervalCount > 0) ? MIntervalCount : 1;
                if (MIntervalCount < 1)
                {
                    _isIntervalCountZero = true;
                }
            }

            RefreshSeries();
            if (this.Chart != null && this.Chart.Containers != null && this.Chart.Containers.AxisLinesconatiner != null)
            {
                this.Chart.Containers.AxisLinesconatiner.Refresh();
            }
        }