Example #1
0
        // Update is called once per frame
        void Update()
        {
            Vector3 left_ctrl_pt    = GameObject.Find("LeftHandAnchor").transform.position;
            Vector3 right_ctrl_pt   = GameObject.Find("RightHandAnchor").transform.position;
            float   dist_left_ctrl  = (10.0f * (left_ctrl_pt - transform.position)).sqrMagnitude;
            float   dist_right_ctrl = (10.0f * (right_ctrl_pt - transform.position)).sqrMagnitude;
            float   sz = 0.1f + 0.9f / (Mathf.Min(dist_left_ctrl, dist_right_ctrl) + 1.0f);

            //transform.localScale = new Vector3(sz, sz, sz);

            if (updateInFrame == Time.frameCount)
            {
                return;
            }
            if (activeControllers.Count == 1)
            {
                var deltaMovement = activeControllers[0].transform.position - initialHandPosition;
                controlsManager.Extrudable.transform.root.transform.position = initialPosition + deltaMovement;

                Quaternion deltaRot = activeControllers[0].transform.rotation * Quaternion.Inverse(initialHandRotation);
                controlsManager.Extrudable.transform.root.position = RotatePointAroundPivot(controlsManager.Extrudable.transform.root.position, activeControllers[0].transform.position, deltaRot);
                controlsManager.Extrudable.transform.root.rotation = deltaRot * initialRotation;

                //controls.UpdateControls();


                ControlsManager.Instance.Extrudable.rebuild = true;
                //ControlsManager.Instance.UpdateControls();
            }
            else if (activeControllers.Count == 2)
            {
                float distanceBetweenControllers = Vector3.Distance(activeControllers[1].transform.position,
                                                                    activeControllers[0].transform.position);

                controlsManager.SetGlobalScale(initialScale * (distanceBetweenControllers / initialDistanceBetweenControllers));

                var scaleMovement = (initialPosition - initialControllerCenter) * ((distanceBetweenControllers / initialDistanceBetweenControllers) - 1);

                var deltaMovement = (activeControllers[1].transform.position +
                                     activeControllers[0].transform.position) * 0.5f -
                                    initialControllerCenter;
                controlsManager.Extrudable.transform.root.position = initialPosition + scaleMovement + deltaMovement;
            }
        }
Example #2
0
        // Update is called once per frame
        void Update()
        {
            if (updateInFrame == Time.frameCount)
            {
                return;
            }
            if (activeControllers.Count > 0 && activeControllers[0] == this)
            {
                if (mode == InteractionMode.SINGLE)
                {
                    var direction = (_turntable.transform.position - handTransform.position) * GetComponentInParent <Turntable>().rotationSensitivity;
                    direction.y = 0;
                    //Debug.Log(direction);
                    //Debug.Log(GetComponentInParent<Turntable>().rotationSensitivity);
                    _turntable.transform.rotation = initialRotation * startRotation * Quaternion.LookRotation(direction);
                }
                else
                {
                    if (activeControllers.Count == 2)
                    {
                        float distanceBetweenControllers = Vector3.Distance(activeControllers[1].handTransform.position,
                                                                            activeControllers[0].handTransform.position);

                        controlsManager.SetGlobalScale(initialScale *
                                                       (distanceBetweenControllers /
                                                        initialDistanceBetweenControllers));

                        var deltaMovement = (activeControllers[1].handTransform.position +
                                             activeControllers[0].handTransform.position) * 0.5f -
                                            initialControllerCenter;
                        _turntable.childObject.position =
                            initialPosition + deltaMovement;
                    }
                }
            }
        }