Пример #1
0
    public virtual void OnDrag(PointerEventData eventData)
    {
        if (eventData != draggedEvent)
        {
            return;
        }

        if (!moveByVelocity)
        {
            // if rigidbody doen't exist, just move transform to eventData caster's pose
            var casterPose = GetEventPose(eventData);
            var offsetPose = eventList.GetLastValue();

            m_prevPose = new Pose(transform);

            if (rigid != null)
            {
                rigid.velocity        = Vector3.zero;
                rigid.angularVelocity = Vector3.zero;
            }

            var targetPose = casterPose * offsetPose;
            transform.position = targetPose.pos;
            transform.rotation = targetPose.rot;
        }
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        trackerPose = VivePose.GetPose(HandRole.RightHand);

        // Engine move
        if (WristBandInput.bBeginMove)
        {
            OnMoveBegin();
        }
        if (WristBandInput.bEndMove)
        {
            OnMoveEnd();
        }
        if (WristBandInput.bIsMoving && stayingColliders.Count == 0)
        {
            Engine.position  += trackerPose.pos - oriTransOfTracker;
            oriTransOfTracker = trackerPose.pos;
        }

        // Call ToolBox
        if (WristBandInput.bToolBox)
        {
            ani.clip = toolboxClip;
            ani.Play();
        }

        // DisAssemble
        if (WristBandInput.bDisAssemble)
        {
            ani.clip = disassembleClip;
            ani.Play();
        }
    }
    public virtual void OnColliderEventDragStart(ColliderButtonEventData eventData)
    {
        if (eventData.button != m_grabButton)
        {
            return;
        }

        var casterPose = GetEventPose(eventData);
        var offsetPose = Pose.FromToPose(casterPose, new Pose(transform));

        if (alignPosition)
        {
            offsetPose.pos = Vector3.zero;
        }
        if (alignRotation)
        {
            offsetPose.rot = Quaternion.identity;
        }

        if (eventData != grabbedEvent && beforeRelease != null)
        {
            beforeRelease.Invoke(this);
        }

        eventList.AddUniqueKey(eventData, offsetPose);

        if (afterGrabbed != null)
        {
            afterGrabbed.Invoke(this);
        }
    }
    public virtual void OnColliderEventDragFixedUpdate(ColliderButtonEventData eventData)
    {
        if (eventData != grabbedEvent)
        {
            return;
        }

        if (moveByVelocity)
        {
            // if rigidbody exists, follow eventData caster using physics
            var casterPose = GetEventPose(eventData);
            var offsetPose = eventList.GetLastValue();

            if (alignPosition)
            {
                offsetPose.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offsetPose.rot = Quaternion.Euler(alignRotationOffset);
            }

            var targetPose = casterPose * offsetPose;
            Pose.SetRigidbodyVelocity(rigid, rigid.position, targetPose.pos, followingDuration);
            Pose.SetRigidbodyAngularVelocity(rigid, rigid.rotation, targetPose.rot, followingDuration, overrideMaxAngularVelocity);
        }
    }
Пример #5
0
    public virtual void OnColliderEventPressDown(ColliderButtonEventData eventData)
    {
        if (eventData.button != m_grabButton || eventList.ContainsKey(eventData) || eventData == m_bannedEventData)
        {
            return;
        }

        var casterPose = GetEventPose(eventData);
        var offsetPose = Pose.FromToPose(casterPose, new Pose(transform));

        if (alignPosition)
        {
            offsetPose.pos = Vector3.zero;
        }
        if (alignRotation)
        {
            offsetPose.rot = Quaternion.identity;
        }

        if (!m_multipleGrabbers && eventList.Count > 0)
        {
            Release();
        }

        eventList.AddUniqueKey(eventData, offsetPose);

        if (afterGrabbed != null)
        {
            afterGrabbed.Invoke(this);
        }
    }
    public virtual void OnColliderEventDragUpdate(ColliderButtonEventData eventData)
    {
        if (eventData != grabbedEvent)
        {
            return;
        }

        if (!moveByVelocity)
        {
            // if rigidbody doesn't exist, just move to eventData caster's pose
            var casterPose = GetEventPose(eventData);
            var offsetPose = eventList.GetLastValue();

            if (alignPosition)
            {
                offsetPose.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offsetPose.rot = Quaternion.Euler(alignRotationOffset);
            }

            m_prevPose = new Pose(transform);

            if (rigid != null)
            {
                rigid.velocity        = Vector3.zero;
                rigid.angularVelocity = Vector3.zero;
            }

            var targetPose = casterPose * offsetPose;
            transform.position = targetPose.pos;
            transform.rotation = targetPose.rot;
        }
    }
    private void Start()
    {
        resetPoses = new Pose[effectTargets.Length];
        for (int i = 0; i < effectTargets.Length; ++i)
        {
            resetPoses[i] = new Pose(effectTargets[i]);
        }

        buttonOriginPosition = buttonObject.position;
    }
Пример #8
0
    public virtual void OnNewPoses()
    {
        var deviceIndex = m_viveRole.GetDeviceIndex();

        if (VRModule.IsValidDeviceIndex(deviceIndex))
        {
            m_staticExCamPose = VivePose.GetPose(deviceIndex);
        }

        if (isQuadViewActive)
        {
            Pose.SetPose(transform, m_staticExCamPose, m_origin);
        }
    }
    private void DoDrop()
    {
        if (!moveByVelocity && rigid != null && !rigid.isKinematic && m_prevPose != Pose.identity)
        {
            Pose.SetRigidbodyVelocity(rigid, m_prevPose.pos, transform.position, Time.deltaTime);
            Pose.SetRigidbodyAngularVelocity(rigid, m_prevPose.rot, transform.rotation, Time.deltaTime, overrideMaxAngularVelocity);

            m_prevPose = Pose.identity;
        }

        if (onDrop != null)
        {
            onDrop.Invoke(this);
        }
    }
Пример #10
0
    // Update is called once per frame
    public virtual void Update()
    {
        if (bIsDrag && tracker.gameObject.activeSelf)
        {
            var targetPose = new Pose(tracker) * transformation;// *offsetPose;
            transform.position = targetPose.pos;
            transform.rotation = targetPose.rot;
        }
        if (bIsSelected)
        {
            ShowInfo();
        }

        //if (Input.GetKeyDown(KeyCode.A))
        //    Reset();
    }
Пример #11
0
    protected virtual void FixedUpdate()
    {
        if (!isDragged)
        {
            return;
        }

        if (moveByVelocity)
        {
            // if rigidbody exists, follow eventData caster using physics
            var casterPose = GetEventPose(draggedEvent);
            var offsetPose = eventList.GetLastValue();

            var targetPose = casterPose * offsetPose;
            Pose.SetRigidbodyVelocity(rigid, rigid.position, targetPose.pos, followingDuration);
            Pose.SetRigidbodyAngularVelocity(rigid, rigid.rotation, targetPose.rot, followingDuration, overrideMaxAngularVelocity);
        }
    }
Пример #12
0
    public virtual void OnBeginDrag(PointerEventData eventData)
    {
        var casterPose = GetEventPose(eventData);
        var offsetPose = new Pose();

        switch (eventData.button)
        {
        case PointerEventData.InputButton.Middle:
        case PointerEventData.InputButton.Right:
        {
            var hitResult = eventData.pointerPressRaycast;
            var hitPose   = new Pose(hitResult.worldPosition, casterPose.rot);

            var caster2hit = new Pose(Vector3.forward * Mathf.Min(hitResult.distance, initGrabDistance), Quaternion.identity);
            var hit2center = Pose.FromToPose(hitPose, new Pose(transform));

            offsetPose = caster2hit * hit2center;
            break;
        }

        case PointerEventData.InputButton.Left:
        default:
        {
            offsetPose = Pose.FromToPose(casterPose, new Pose(transform));
            break;
        }
        }

        if (eventData != draggedEvent && beforeRelease != null)
        {
            beforeRelease.Invoke(this);
        }

        eventList.AddUniqueKey(eventData, offsetPose);

        if (afterDragged != null)
        {
            afterDragged.Invoke(this);
        }
    }
Пример #13
0
    protected virtual void FixedUpdate()
    {
        if (isGrabbed && moveByVelocity)
        {
            // if rigidbody exists, follow eventData caster using physics
            var casterPose = GetEventPose(grabbedEvent);
            var offsetPose = eventList.GetLastValue();

            if (alignPosition)
            {
                offsetPose.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offsetPose.rot = Quaternion.Euler(alignRotationOffset);
            }

            var targetPose = casterPose * offsetPose;
            Pose.SetRigidbodyVelocity(rigid, rigid.position, targetPose.pos, followingDuration);
            Pose.SetRigidbodyAngularVelocity(rigid, rigid.rotation, targetPose.rot, followingDuration, overrideMaxAngularVelocity);
        }
    }
Пример #14
0
        public static Pose FromToPose(Pose from, Pose to)
        {
            var invRot = Quaternion.Inverse(from.rot);

            return(new Pose(invRot * (to.pos - from.pos), invRot * to.rot));
        }
Пример #15
0
 public void Multiply(Pose a, Pose b)
 {
     rot = a.rot * b.rot;
     pos = a.pos + a.rot * b.pos;
 }
Пример #16
0
    protected virtual void Update()
    {
        if (isGrabbed && !moveByVelocity)
        {
            // if rigidbody doesn't exist, just move to eventData caster's pose
            var casterPose = GetEventPose(grabbedEvent);
            var offsetPose = eventList.GetLastValue();

            if (alignPosition)
            {
                offsetPose.pos = alignPositionOffset;
            }
            if (alignRotation)
            {
                offsetPose.rot = Quaternion.Euler(alignRotationOffset);
            }

            m_prevPose = new Pose(transform);

            if (rigid != null)
            {
                rigid.velocity        = Vector3.zero;
                rigid.angularVelocity = Vector3.zero;
            }

            var targetPose = casterPose * offsetPose;
            transform.position = targetPose.pos;
            transform.rotation = targetPose.rot;
        }

        // reset banned event data
        m_bannedEventData = null;

        // toggle grab button to release
        if (m_toggleToRelease && isGrabbed)
        {
            var released = grabbedEvent.GetPressDown();
            if (released)
            {
                m_bannedEventData = grabbedEvent; // ban this press down event so that it won't trigger another grab in OnColliderEventPressDown

                if (beforeRelease != null)
                {
                    beforeRelease.Invoke(this);
                }
            }

            eventList.RemoveAll((obj) => obj.Key.GetPressDown());

            if (isGrabbed)
            {
                if (released && afterGrabbed != null)
                {
                    afterGrabbed.Invoke(this);
                }
            }
            else
            {
                DoDrop();
            }
        }
    }
Пример #17
0
 public void LerpUnclamped(Pose to, float t)
 {
     pos = Vector3.LerpUnclamped(pos, to.pos, t);
     rot = Quaternion.SlerpUnclamped(rot, to.rot, t);
 }
Пример #18
0
 public virtual void BeginDrag()
 {
     bIsDrag        = true;
     transformation = Pose.FromToPose(new Pose(tracker), new Pose(transform));
 }
Пример #19
0
 public void Recenter()
 {
     m_staticExCamPose = Pose.identity;
 }
Пример #20
0
 public static Pose LerpUnclamped(Pose a, Pose b, float t)
 {
     return(new Pose(Vector3.LerpUnclamped(a.pos, b.pos, t), Quaternion.SlerpUnclamped(a.rot, b.rot, t)));
 }