Exemplo n.º 1
0
 private void RotationWidget_OnRotationChange(Quaternion newrot, Quaternion oldrot)
 {
     DefaultWidget.Rotation  = newrot;
     PositionWidget.Rotation = newrot;
     ScaleWidget.Rotation    = newrot;
     OnRotationChange?.Invoke(newrot, oldrot);
 }
Exemplo n.º 2
0
    public void OnDrag(PointerEventData eventData)
    {
        var verticalDist = _pointerPosStart.y - eventData.position.y;
        var rot          = _rotationStart + verticalDist;

        transform.localRotation = Quaternion.Euler(0, 0, rot);
        OnRotationChange?.Invoke(rot);
    }
Exemplo n.º 3
0
        public void Update(float deltaTime)
        {
            if (!_isEnabled)
            {
                return;
            }

            if (GetMouseButtonDown(1))
            {
                _cashedHorizontal    = HorizontalRotation;
                _cashedVertical      = VerticalRotation;
                _cashedMousePosition = mousePosition;
            }

            if (GetMouseButton(1))
            {
                var mouseDelta = mousePosition - _cashedMousePosition;
                HorizontalRotation = Repeat(_cashedHorizontal + (mouseDelta.x / Screen.width) * _config.HorizontalRotationPerScreenWidth, 1);
                VerticalRotation   = Clamp01(_cashedVertical - (mouseDelta.y / Screen.height) * _config.VerticalRotationPerScreenHeight);
                OnRotationChange?.Invoke();
            }
        }
Exemplo n.º 4
0
 public void RotationChanged(Vector3 rot)
 {
     OnRotationChange?.Invoke(rot);
 }
 public void RotationChanged(Vector3 rot)
 {
     currentEntity?.SetRotation(rot);
     OnRotationChange?.Invoke(rot);
 }
Exemplo n.º 6
0
        public override void Update(Camera cam)
        {
            if (!Visible)
            {
                return;
            }

            var     ori  = ObjectSpace ? Rotation : Quaternion.Identity;
            Vector3 xdir = ori.Multiply(Vector3.UnitX);
            Vector3 ydir = ori.Multiply(Vector3.UnitY);
            Vector3 zdir = ori.Multiply(Vector3.UnitZ);

            Vector3[] axes   = { xdir, ydir, zdir };
            Vector3[] sides1 = { ydir, zdir, xdir };
            Vector3[] sides2 = { zdir, xdir, ydir };

            Ray     ray        = cam.MouseRay;
            Vector3 camrel     = Position - cam.Position;
            float   dist       = camrel.Length();
            float   size       = GetWorldSize(Size, dist, cam);
            float   ocircsize  = 1.0f * size;  //outer ring radius
            float   icircsize  = 0.75f * size; //inner ring radius
            float   icircthick = 0.2f * size;  //inner ring hit width
            float   ocircthick = 0.13f * size; //outer ring hit width
            float   icirchiti  = icircsize - icircthick;
            float   icirchito  = icircsize + icircthick;
            float   ocirchiti  = ocircsize - ocircthick;
            float   ocirchito  = ocircsize + ocircthick;


            //test for the main axes hits
            float      cullvalue = -0.18f;
            float      hitd      = float.MaxValue;
            Vector3    hitp      = camrel;
            Vector3    hitrel    = Vector3.Zero;
            WidgetAxis hitax     = WidgetAxis.None;
            Vector3    hitaxd    = Vector3.UnitX;
            Vector3    hitax1    = Vector3.UnitY;
            Vector3    hitax2    = Vector3.UnitZ;

            for (int i = 0; i < 3; i++)
            {
                WidgetAxis ax = (WidgetAxis)(1 << i);
                if ((ax & EnableAxes) == 0)
                {
                    continue;
                }
                Vector3 s1 = sides1[i];
                Vector3 s2 = sides2[i];
                if (GetAxisRayHit(s1, s2, camrel, ray, out hitp))
                {
                    float hitdist = hitp.Length();
                    float hitreld = (camrel.Length() - hitdist) / size;
                    if (hitreld < cullvalue)
                    {
                        continue;                      //this hit was at the backside of the widget; ignore
                    }
                    Vector3 thitrel = hitp - camrel;
                    float   hitrad  = thitrel.Length();
                    if ((hitrad > icirchiti) && (hitrad < icirchito) && (hitdist < hitd))
                    {
                        hitd   = hitdist;
                        hitax  = ax;
                        hitax1 = s1;
                        hitax2 = s2;
                        hitrel = thitrel;
                        hitaxd = axes[i];
                    }
                }
            }

            //test for the outer ring hit
            if ((hitax == WidgetAxis.None) && (EnableAxes == WidgetAxis.XYZ))
            {
                Vector3 sdir = Vector3.Normalize(camrel);
                //if (cam.IsMapView || cam.IsOrthographic)
                //{
                //    sdir = cam.ViewDirection;
                //}
                float   ad1 = Math.Abs(Vector3.Dot(sdir, Vector3.UnitY));
                float   ad2 = Math.Abs(Vector3.Dot(sdir, Vector3.UnitZ));
                Vector3 ax1 = Vector3.Normalize(Vector3.Cross(sdir, (ad1 > ad2) ? Vector3.UnitY : Vector3.UnitZ));
                Vector3 ax2 = Vector3.Normalize(Vector3.Cross(sdir, ax1));
                if (GetAxisRayHit(ax1, ax2, camrel, ray, out hitp))
                {
                    Vector3 thitrel = hitp - camrel;
                    float   hitrad  = thitrel.Length();
                    if ((hitrad > ocirchiti) && (hitrad < ocirchito))
                    {
                        hitax  = WidgetAxis.XYZ;
                        hitax1 = ax1;
                        hitax2 = ax2;
                        hitrel = thitrel;
                        hitaxd = sdir;
                    }
                }
            }


            MousedAxis = hitax;


            if (IsDragging && !WasDragging)
            {
                //drag start. mark the start vector and axes
                DraggedAxis         = MousedAxis;
                DragStartRotation   = Rotation;
                DraggedAxisDir      = hitaxd;
                DraggedAxisSideDir1 = hitax1;
                DraggedAxisSideDir2 = hitax2;

                bool hit = GetAxisRayHit(DraggedAxisSideDir1, DraggedAxisSideDir2, camrel, ray, out DragStartVec);
                if ((MousedAxis == WidgetAxis.None) || !hit)
                {
                    IsDragging = false;
                }
            }
            else if (IsDragging)
            {
                //continue drag.
                Vector3 newvec;
                bool    hit = GetAxisRayHit(DraggedAxisSideDir1, DraggedAxisSideDir2, camrel, ray, out newvec);
                if (hit)
                {
                    Vector3 diff = newvec - DragStartVec;
                    if (diff.Length() < 10000.0f) //put some limit to the plane intersection...
                    {
                        Vector3    nv     = Vector3.Normalize(newvec - camrel);
                        Vector3    ov     = Vector3.Normalize(DragStartVec - camrel);
                        float      na     = AngleOnAxes(nv, DraggedAxisSideDir1, DraggedAxisSideDir2);
                        float      oa     = AngleOnAxes(ov, DraggedAxisSideDir1, DraggedAxisSideDir2);
                        float      a      = na - oa;
                        Quaternion rot    = Quaternion.RotationAxis(DraggedAxisDir, a);
                        Quaternion oldrot = Rotation;
                        Rotation = Quaternion.Normalize(Quaternion.Multiply(rot, DragStartRotation));
                        if (Rotation != oldrot)
                        {
                            OnRotationChange?.Invoke(Rotation, oldrot);
                        }
                    }
                }
            }


            WasDragging = IsDragging;
        }
 private void Start()
 {
     positionAttribute.OnChanged += (x) => OnPositionChange?.Invoke(x);
     rotationAttribute.OnChanged += (x) => OnRotationChange?.Invoke(x);
     scaleAttribute.OnChanged    += (x) => OnScaleChange?.Invoke(x);
 }