Ejemplo n.º 1
0
        private Vector3 GetAxisPlaneIntersect(Vector2 screenPosition, Vector3 planeNormal)
        {
            Vector3 intersect;
            Ray     ray = Service.Cameras.CurrentCamera.ScreenPointToRay(screenPosition);

            MathEditorUtils.LinePlaneIntersection(out intersect, ray.origin,
                                                  ray.direction, planeNormal,
                                                  currentPlanePt);
            return(intersect);
        }
Ejemplo n.º 2
0
        private Vector3 GetAxisIntersect(Vector3 mousePlanePos, Vector3 axisVector, Vector3 perpVector)
        {
            Vector3 intersection1;
            Vector3 intersection2;

            MathEditorUtils.CalculateLineLineIntersection(gizmo.position,
                                                          gizmo.position + axisVector,
                                                          mousePlanePos,
                                                          mousePlanePos + perpVector,
                                                          out intersection1,
                                                          out intersection2);
            return(intersection1);
        }
Ejemplo n.º 3
0
 private void UpdateFromInput(Vector3 value)
 {
     startPos   = currentSelected.position;
     currentPos = value;
     if (snapDrag)
     {
         currentSelected.position = MathEditorUtils.Vector3Round(currentPos);
     }
     else
     {
         currentSelected.position = currentPos;
     }
     gizmo.transform.position = currentSelected.position;
 }
Ejemplo n.º 4
0
        /// Called when a previously-pressed finger moves or remains stationary.
        public void Drag(int id, Vector2 screenPositionLast, Vector2 screenPosition)
        {
            if (isDraggingGizmo)
            {
                Vector3 normUp          = snapDrag ? Vector3.up : currentPlaneNormUp;
                Vector3 xzIntersect     = GetAxisPlaneIntersect(screenPosition, normUp);
                Vector3 xzLastIntersect = GetAxisPlaneIntersect(screenPositionLast, normUp);
                Vector3 xzDiff          = xzIntersect - xzLastIntersect;

                Vector3 normFw          = snapDrag ? Vector3.forward : currentPlaneNormFw;
                Vector3 xyIntersect     = GetAxisPlaneIntersect(screenPosition, normFw);
                Vector3 xyLastIntersect = GetAxisPlaneIntersect(screenPositionLast, normFw);
                Vector3 xyDiff          = xyIntersect - xyLastIntersect;

                Vector3 normRt          = snapDrag ? Vector3.right : currentPlaneNormRt;
                Vector3 yzIntersect     = GetAxisPlaneIntersect(screenPosition, normRt);
                Vector3 yzLastIntersect = GetAxisPlaneIntersect(screenPositionLast, normRt);
                Vector3 yzDiff          = yzIntersect - yzLastIntersect;

                switch (currentAxis)
                {
                case TranslationAxes.XAxis:
                    if (snapDrag)
                    {
                        currentPos += new Vector3(xzDiff.x, 0f, 0f);
                    }
                    else
                    {
                        Vector3 xAxisDiff = GetAxisDiff(xzIntersect, xzLastIntersect, gizmo.right, gizmo.forward);
                        currentPos += xAxisDiff;
                    }
                    break;

                case TranslationAxes.ZAxis:
                    if (snapDrag)
                    {
                        currentPos += new Vector3(0f, 0f, xzDiff.z);
                    }
                    else
                    {
                        Vector3 zAxisDiff = GetAxisDiff(xzIntersect, xzLastIntersect, gizmo.forward, gizmo.right);
                        currentPos += zAxisDiff;
                    }
                    break;

                case TranslationAxes.YAxis:
                    if (snapDrag)
                    {
                        currentPos += new Vector3(0f, xyDiff.y, 0f);
                    }
                    else
                    {
                        Vector3 yAxisDiff = GetAxisDiff(xyIntersect, xyLastIntersect, gizmo.up, gizmo.right);
                        currentPos += yAxisDiff;
                    }
                    break;

                case TranslationAxes.XZAxis:
                    currentPos += new Vector3(xzDiff.x, xzDiff.y, xzDiff.z);
                    break;

                case TranslationAxes.XYAxis:
                    currentPos += new Vector3(xyDiff.x, xyDiff.y, xyDiff.z);
                    break;

                case TranslationAxes.YZAxis:
                    currentPos += new Vector3(yzDiff.x, yzDiff.y, yzDiff.z);
                    break;
                }

                currentSelected.position = snapDrag ?
                                           MathEditorUtils.Vector3Round(currentPos) :
                                           currentPos;

                gizmo.transform.position = currentSelected.transform.position;
                SendTransformUpdate(currentSelected.position);
            }
        }