当前位置: 首页>>代码示例>>C#>>正文


C# Point2.Set方法代码示例

本文整理汇总了C#中Point2.Set方法的典型用法代码示例。如果您正苦于以下问题:C# Point2.Set方法的具体用法?C# Point2.Set怎么用?C# Point2.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Point2的用法示例。


在下文中一共展示了Point2.Set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Polygon

    public Polygon(PolygonRawData polygonRawData)
    {
        _closed = true;

        float area = 0;

        for (int i = 0; i < polygonRawData.Count; ++i)
        {
            Vector2 p1 = polygonRawData[i];
            Vector2 p2 = polygonRawData[i + 1];

            area += p1.x * p2.y - p2.x * p1.y;
        }

        if (area > 0)
        {
            polygonRawData.Reverse ();
        }

        //Debug.Log ("AREA " + area);

        Edge2 prevEdge = null;
        Point2 prevPt = null;
        Point2 currentPt = null;

        for (int i = 0; i < polygonRawData.Count - 1; ++i)
        {
            Vector2 rawPt = polygonRawData[i];

            if (currentPt == null)
            {
                //currentPt = new Point2 (rawPt);
                currentPt = new Point2 ();
                currentPt.Set(
                    rawPt.x,
                    rawPt.y);
            }

            Point2 nextPt = new Point2 (polygonRawData[i + 1]);

            if (i == polygonRawData.Count - 2 && polygonRawData.Count > 2)
            {
                nextPt = _points[0].GetPrevEdge ().GetPrevPoint2 ();
                //nextPt = (Point2)_points[0].GetPrevEdge ().GetPrevPoint2 ().Clone();
                //nextPt = new Point2();
                nextPt.Set(
                    _points[0].GetPrevEdge ().GetPrevPoint2 ().GetX(),
                    _points[0].GetPrevEdge ().GetPrevPoint2 ().GetY());
            }

            if (prevEdge == null)
            {
                if (prevPt == null)
                {
                    //prevPt = new Point2 (polygonRawData[i - 1]);
                    prevPt = new Point2 ();
                    prevPt.Set(
                        polygonRawData[i - 1].x,
                        polygonRawData[i - 1].y);
                }

                prevEdge = new Edge2 (prevPt, currentPt);
                prevPt.SetNextEdge (prevEdge);
            }

            Edge2 nextEdge = new Edge2 (currentPt, nextPt);
        //			if (i == polygonRawData.Count - 1)
        //			{
        //				nextEdge = _points[0].GetPrevEdge ();
        //			}

            currentPt.SetEdges (prevEdge, nextEdge);

            _points.Add (currentPt);
            _edges.Add (nextEdge);

            if (i == polygonRawData.Count - 2 && polygonRawData.Count >= 2)
            {
                nextPt.SetPrevEdge (nextEdge);
                _edges.Add (nextPt.GetNextEdge ());
                _points.Add (nextPt);
            }

            prevEdge = nextEdge;
            prevPt = currentPt;
            currentPt = nextPt;
        }

        if (_edges.Count == 2 && _points.Count == 2)
        {
            _points[0].SetPrevEdge (null);
            _points[1].SetNextEdge (null);
            _edges.RemoveAt (1);
        }

        UpdateBounds ();
    }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:97,代码来源:Polygon.cs

示例2: OnGUI

    protected void OnGUI()
    {
        // Get transformation matrix
        Matrix4x4 matrix = _planTransformation.GetMatrix ();

        GUI.depth = -10;

        // draw background image
        GUI.DrawTexture (_rectBackground, backgroundImage, ScaleMode.StretchToFill, false);
        //		GUI.DrawTexture (_rectBackground, backgroundImage, ScaleMode.StretchToFill, false);
        if(_gridVisible)
        {
            ImgUtils.TileTextureWithOffset(backgroundImageGrid,_rectBackgroundInit,
                _rectBackground,
                ScaleMode.ScaleToFit, 0/*_offsetWidth*/,0/* _offsetHeight*/);
        }
        GUISkin bkup = GUI.skin;
        GUI.skin = skin;

        // draw current scale --> ex: 1 x 1
        float scale = Mathf.Round ((1 / _planTransformation.GetScale ().x) * 100) / 100 ;
        //	GUI.DrawTexture (new Rect (850+ _offsetWidth-20, 550+ _offsetHeight-20, 140, 140), labelBackgroundImage, ScaleMode.StretchToFill, true);
        //	GUI.Label (new Rect (850+ _offsetWidth, 590 + _offsetHeight, 100, 20),/* scale.ToString () + " x " + */scale.ToString () + "m", "dimension label Main");

        Function_PoolDesigner function = _gui.GetFunction ();

        // Dessin de l'image de fond chargé par l'utilisateur
        if (function.GetBackgroundImage () != null &&
            function.IsBackgroundImageVisible () &&
            _gui.GetCurrentMode () != PoolDesignerMode.BackgroundScale)
        {
            Rect bgRect = function.GetBackgroundRect ();

            // on applique les transformation du plan a l'image de fond
            Vector2 bgPt = new Vector2 (bgRect.x + _offsetWidth, bgRect.y + _offsetHeight);
            bgPt = matrix.MultiplyPoint (bgPt);
            bgRect.x = bgPt.x;
            bgRect.y = bgPt.y;

            bgRect.width = bgRect.width * _planTransformation.GetScale ().x;
            bgRect.height = bgRect.height * _planTransformation.GetScale ().x;

            GUI.DrawTexture (bgRect, function.GetBackgroundImage (), ScaleMode.ScaleToFit, false);
        }

        if (_maxDimensionVisible && _polygon.GetPoints ().Count > 0 && !(_cotationVisible && _canMove && PC.In.Click1Hold()))
        {
            // draw dimension square with the boundingBox
            Bounds polyBounds = _polygon.bounds;
            Vector2 dimensionPosition = new Vector2 (
                polyBounds.center.x - polyBounds.extents.x + _offsetWidth,
                polyBounds.center.z - polyBounds.extents.z + _offsetHeight);

            dimensionPosition = matrix.MultiplyPoint (dimensionPosition);

            Vector2 dimensionSize = new Vector2 (polyBounds.size.x,
                                                 polyBounds.size.z);

            float poolWidth = Mathf.Round (polyBounds.size.x) / 100;
            float poolHeight = Mathf.Round (polyBounds.size.z) / 100;

            if(m_newWidth != poolWidth.ToString() && !m_isModifyingW)
                m_newWidth = poolWidth.ToString();
            if(m_newHeight != poolHeight.ToString() && !m_isModifyingH)
                m_newHeight = poolHeight.ToString();

            dimensionSize = matrix.MultiplyVector (dimensionSize);

            Rect dimensionRect = new Rect (dimensionPosition.x - DIMENSION_OFFSET,
                                           dimensionPosition.y - DIMENSION_OFFSET ,
                                           dimensionSize.x + DIMENSION_OFFSET + DIMENSION_OFFSET / 2,
                                           dimensionSize.y + DIMENSION_OFFSET + DIMENSION_OFFSET / 2);

            GUI.Label (dimensionRect, "", "dimensionSquare"); //Flèches

            m_cotationW.Set((dimensionRect.x + dimensionRect.width / 2) - 50,dimensionRect.y - 10,100,30);
            m_cotationH.Set(dimensionRect.x - 80,(dimensionRect.y + dimensionRect.height / 2) - 10,100,30);

        //			if(m_cotationH.x < 100f) // plus besoin car plus de boutons gauche/droite
        //			{
        //				if(m_cotationH.yMax < Screen.height/2f && m_cotationH.yMax > Screen.height/2f - 25f)
        //					m_cotationH.y =  Screen.height/2f - 25f - 50f;
        //				else if(m_cotationH.yMax > Screen.height/2f && m_cotationH.yMax < Screen.height/2f + 25f)
        //					m_cotationH.y =  Screen.height/2f + 25f + 20f;
        //				else if(m_cotationH.y > Screen.height/2f && m_cotationH.y < Screen.height/2f + 25f)
        //					m_cotationH.y =  Screen.height/2f + 25f + 20f;
        //				else if(m_cotationH.y < Screen.height/2f && m_cotationH.y > Screen.height/2f -25f)
        //					m_cotationH.y =  Screen.height/2f - 25f - 50f;
        //			}
            //MODIFICATION DES COTES HEIGHT-----------------------------------------------------------------
            if(!m_isModifyingH)
            {
                GUI.BeginGroup(m_cotationH);
                if(GUI.Button(new Rect(0,0,30,30),"","changeSize") ||
                    UsefulFunctions.GUIOutlineButton/* GUI.Button*/(new Rect(30,0,70,30),poolHeight.ToString () + "m","txtout","txtin"))
                {
                    m_isModifyingH = true;
                    m_isModifyingW = false;
        #if UNITY_ANDROID || UNITY_IPHONE
                    m_kb = TouchScreenKeyboard.Open(poolHeight.ToString(),TouchScreenKeyboardType.NumbersAndPunctuation);
//.........这里部分代码省略.........
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:101,代码来源:PolygonDrawer.cs

示例3: Update

    // Update is called once per frame
    protected void Update()
    {
        #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        _touches = Input.touches;
        #endif
        if (_gui.GetCurrentMode () == PoolDesignerMode.PolygonEdition)
        {
            _cursor = _planTransformation.GetTransformedMousePosition ();

            // on cherche le point et l'edge qui sont sous le curseur
            FindIntersectedPoint ();
            FindIntersectedEdge ();

        //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        //            if(Input.touchCount == 1)
        //            {
        //                _firstTouch = _planTransformation.GetTouches()[0];
        //                Touch testouch = _touches[0];
        //
        //            if (!_gui.isOnUI () && _firstTouch.phase == TouchPhase.Began)
        //            {
        //                Debug.Log("---------> firstTouch "+_firstTouch.deltaTime+", "+_firstTouch.position+", "+_firstTouch.deltaPosition+", "+_firstTouch.phase);
        //                Debug.Log("---------> testTouch  "+testouch.deltaTime+", "+testouch.position+", "+testouch.deltaPosition+", "+testouch.phase);
        //#else
          //if UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_EDITOR
            if (!_gui.isOnUI () && _planTransformation.GetClickBegan()/*PC.In.Click1Down()*/ && !_gui.IsOpen())
            {
        //#endif
                if(_gui.IsJustCloseMenu())
                {
                    _gui.setIsJustCloseMenu(false);
                    return;
                }
                if (_selectedPointIndexCandidate >= 0) // selection
                {
                    _selectedPointIndex = _selectedPointIndexCandidate;
                    _selectedPoint = _polygon.GetPoints ()[_selectedPointIndex];

                    if (!_polygon.IsClosed () && _selectedPointIndex == 0 /*&& _polygon.GetPoints ().Count > 2*/)
                    {
                        _polygon.Close ();
                        _selectedPointIndex = _polygon.GetPoints ().IndexOf (_selectedPoint);
                    }

                    _canMove = true;
                }
                else if (_selectedEdgeIndexCandidate >= 0) // insert point
                {
                    _selectedEdgeIndex = _selectedEdgeIndexCandidate;
                    _selectedEdge = _polygon.GetEdges ()[_selectedEdgeIndex];

                    Point2 newPoint = new Point2 (_cursor);
                    newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight);
                    _polygon.InsertPoint (_selectedEdgeIndex, newPoint);

                    _selectedPointIndex = _polygon.GetPoints ().IndexOf (newPoint);
                    _selectedPoint = newPoint;

                    _canMove = true;
                }

                else if (!_polygon.IsClosed ()) // add point
                {
                    Point2 newPoint = new Point2 (_cursor);
                    newPoint.Set(newPoint.GetX()-_offsetWidth, newPoint.GetY()-_offsetHeight);
                    _polygon.AddPoint (newPoint);

                    _selectedPointIndex = _polygon.GetPoints ().Count - 1;
                    _selectedPoint = newPoint;

                    _canMove = true;

                }
                else // deselection
                {
                    _selectedPointIndex = -1;
                    _selectedPoint = null;

                    _selectedEdgeIndex = -1;
                    _selectedEdge = null;
                }

                if (_selectedPointIndex >= 0) // update radius slider values
                {
                    _pointOffset = (Vector2)_selectedPoint - _cursor;

                    if (_selectedPoint.GetJunction () == JunctionType.Broken)
                    {
                        _gui.SetSliderValues (0, 1);
                    }
                    else if (_selectedPoint.GetJunction () == JunctionType.Curved)
                    {
                        ArchedPoint2 ar = _selectedPoint as ArchedPoint2;
                        _gui.SetSliderValues (ar.GetMeasuredRadius () / 100, ar.GetMaxRadius () / 100);
                    }
                }
            }
        //#if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
        //            }
//.........这里部分代码省略.........
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:101,代码来源:PolygonDrawer.cs

示例4: FindIntersectedEdge

    protected void FindIntersectedEdge()
    {
        _selectedEdgeIndexCandidate = -1;
        int edgeCounter = 0;

        float scale = 1 / _planTransformation.GetScale ().x;
        float pr = POINT_RADIUS * scale;

        // pour chaque edge on crée un rectangle de l'epaisseur POINT_RADIUS * currentScale
        // et de la longueur de l'edge. Puis on applique une transformation au curseur correspondant
        // a l'orientation de l'edge. Et on verifie que le curseur intersecte le rectangle.

        foreach (Edge2 edge in _polygon.GetEdges ())
        {
            Point2 prevPoint = edge.GetPrevPoint2 ();
            Point2 prevEdgePoint = new Point2 (prevPoint);
            if (prevPoint.GetJunction () == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = prevPoint as ArchedPoint2;
                prevEdgePoint.Set (aPoint.GetNextTangentPoint ());
            }

            Point2 nextPoint = edge.GetNextPoint2 ();
            Point2 nextEdgePoint = new Point2 (nextPoint);
            if (nextPoint.GetJunction () == JunctionType.Curved)
            {
                ArchedPoint2 aPoint = nextPoint as ArchedPoint2;
                nextEdgePoint.Set (aPoint.GetPrevTangentPoint ());
            }

            Edge2 transformedEdge = new Edge2 (prevEdgePoint, nextEdgePoint);

            Vector2 prevPt = transformedEdge.GetPrevPoint2 ();
            prevPt.Set(prevPt.x+_offsetWidth, prevPt.y+_offsetHeight);
            Vector2 nextPt = transformedEdge.GetNextPoint2 ();
            nextPt.Set(nextPt.x+_offsetWidth, nextPt.y+_offsetHeight);

            Vector3 translation = new Vector3 (prevPt.x, 0, prevPt.y);
            Matrix4x4 translationMatrix = Matrix4x4.TRS (translation, Quaternion.identity, Vector3.one);

            Vector3 edgeVector = new Vector3 (transformedEdge.ToVector2 ().x, 0, transformedEdge.ToVector2 ().y);
            Quaternion rotation = Quaternion.FromToRotation (edgeVector, Vector3.right);
            Matrix4x4 rotationMatrix = Matrix4x4.TRS (Vector3.zero, rotation, Vector3.one);

            Matrix4x4 edgeMatrix = translationMatrix * rotationMatrix * translationMatrix.inverse;
            Vector3 transformedCursor3 = edgeMatrix.MultiplyPoint (new Vector3 (_cursor.x, 0, _cursor.y));
            Vector2 transformedCursor = new Vector2 (transformedCursor3.x, transformedCursor3.z);

            Rect edgeRect = new Rect (prevPt.x + (pr / 2),
                                      prevPt.y - (pr / 2),
                                      transformedEdge.GetLength () - pr,
                                      pr);

            if (edgeRect.Contains (transformedCursor))
            {
                _selectedEdgeIndexCandidate = edgeCounter;
        //				Debug.Log ("EDGE " + edgeCounter);
            }

            ++edgeCounter;
        }
    }
开发者ID:gviaud,项目名称:OS-unity-5,代码行数:62,代码来源:PolygonDrawer.cs


注:本文中的Point2.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。