void Update()
    {
        // dont run Update() if there is no gesture listener
        if (!gestureListener)
        {
            return;
        }

        if (gestureListener.IsZoomingIn() || gestureListener.IsZoomingOut())
        {
            // zoom the model
            float zoomFactor = gestureListener.GetZoomFactor();

            Vector3 newLocalScale = new Vector3(zoomFactor, zoomFactor, zoomFactor);
            transform.localScale = Vector3.Lerp(transform.localScale, newLocalScale, spinSpeed * Time.deltaTime);
        }

        if (gestureListener.IsTurningWheel())
        {
            // rotate the model
            float turnAngle   = Mathf.Clamp(gestureListener.GetWheelAngle(), -30f, 30f);
            float updateAngle = Mathf.Lerp(0, turnAngle, spinSpeed * Time.deltaTime);

            if (screenCamera)
            {
                transform.RotateAround(transform.position, screenCamera.transform.TransformDirection(Vector3.up), updateAngle);
            }
            else
            {
                transform.Rotate(Vector3.up * turnAngle, Space.World);
            }
        }

        if (gestureListener.IsRaiseHand())
        {
            // reset the model
            Vector3 newLocalScale = Vector3.one;
            transform.localScale = newLocalScale;

            transform.rotation = screenCamera ? screenCamera.transform.rotation * initialRotation : initialRotation;
        }
    }
示例#2
0
    void Update()
    {
        // dont run Update() if there is no gesture listener
        if (!gestureListener)
        {
            return;
        }

        if (gestureListener.IsZoomingIn() || gestureListener.IsZoomingOut())
        {
            // zoom the model
            float zoomFactor = gestureListener.GetZoomFactor();

            Vector3 newLocalScale = new Vector3(zoomFactor, zoomFactor, zoomFactor);
            transform.localScale = Vector3.Lerp(transform.localScale, newLocalScale, spinSpeed * Time.deltaTime);
        }

        if (gestureListener.IsTurningWheel())
        {
            // rotate the model
            float turnAngle = gestureListener.GetWheelAngle();

            Vector3 newRotation = transform.rotation.eulerAngles;
            newRotation.y     += turnAngle;
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(newRotation), spinSpeed * Time.deltaTime);
        }

        if (gestureListener.IsRaiseHand())
        {
            // reset the model
            Vector3 newLocalScale = Vector3.one;
            transform.localScale = newLocalScale;

            Vector3 newRotation = transform.rotation.eulerAngles;
            newRotation.y      = 0f;
            transform.rotation = Quaternion.Euler(newRotation);
        }
    }