Exemplo n.º 1
0
        protected virtual void Update()
        {
            // Retrieve the frustum planes from the camera.
            frustumPlanes = GeometryUtility.CalculateFrustumPlanes(Camera.main);

            // Determine if the Tagalong needs to move based on whether its
            // BoxCollider is in or out of the camera's view frustum.
            Vector3 tagalongTargetPosition;

            if (CalculateTagalongTargetPosition(transform.position, out tagalongTargetPosition))
            {
                // Derived classes will use the same Interpolator and may have
                // adjusted its PositionUpdateSpeed for some other purpose.
                // Restore the value we care about and tell the Interpolator
                // to move the Tagalong to its new target position.
                interpolator.PositionPerSecond = PositionUpdateSpeed;
                interpolator.SetTargetPosition(tagalongTargetPosition);
            }
            else if (!interpolator.Running && EnforceDistance)
            {
                // If the Tagalong is inside the camera's view frustum, and it is
                // supposed to stay a fixed distance from the camera, force the
                // tagalong to that location (without using the Interpolator).
                Ray ray = new Ray(Camera.main.transform.position, transform.position - Camera.main.transform.position);
                transform.position = ray.GetPoint(TagalongDistance);
            }
        }
Exemplo n.º 2
0
        private void Manipulate()
        {
            // First step is to figure out the delta between the initial hand position and the current hand position
            Vector3 localHandPosition            = Camera.main.transform.InverseTransformPoint(GestureManager.Instance.ManipulationHandPosition);
            Vector3 initialHandToCurrentHand     = localHandPosition - initialHandPosition;
            Vector3 scaledLocalHandPositionDelta = Vector3.Scale(initialHandToCurrentHand, handPositionScale);
            Vector3 localObjectPosition          = initialObjectPosition + scaledLocalHandPositionDelta;
            Vector3 worldObjectPosition          = Camera.main.transform.TransformPoint(localObjectPosition);

            // Rotate this object to face the user.
            Quaternion toQuat = Camera.main.transform.localRotation;

            toQuat.x = 0;
            toQuat.z = 0;
            this.transform.rotation = toQuat;

            // If the object has an interpolator we should use it, otherwise just move the transform directly
            if (targetInterpolator != null)
            {
                targetInterpolator.SetTargetPosition(worldObjectPosition);
            }
            else
            {
                this.transform.position = worldObjectPosition;
            }
        }