예제 #1
0
        private void LeftGrab(Selector.ButtonType button, bool grabState)
        {
            if (button != Selector.ButtonType.Grip)
            {
                return;
            }

            initialDistance = Vector3.Distance(selectorLeft.transform.localPosition, selectorRight.transform.localPosition);

            leftGrabbing = grabState;

            if (leftGrabbing || rightGrabbing)
            {
                if (!rightGrabbing)
                {
                    worldSrt.Clear();
                }

                Srt cameraRig = new Srt(transform);

                SetLocalCursor();

                childSrt = cameraRig.Inverse() * worldSrt;
                childSrt = cursorSrt.Inverse() * childSrt;
            }
        }
예제 #2
0
        private void Update()
        {
            if (!leftGrabbing && !rightGrabbing)
            {
                return;
            }

            SetLocalCursor();

            Srt CameraRigSrt = new Srt(transform);

            worldSrt = CameraRigSrt * (cursorSrt * childSrt);

            // Convert childSrt through cameraRigSrt and cursorSrt to world space and save to a new local variable worldMovedSrt.
            // This is where the world would be if it actually could be moved!

            // Note: cameraRigSrt and worldMovedSrt are now siblings in world space.
            // Convert cameraRigSrt (this) frame to be a child of worldMovedSrt and save to cameraRigMovedSrt.
            // Note: This is where the cameraRig would be in worldMovedSrt space!

            Srt cameraRigMovedSrt = worldSrt.Inverse() * CameraRigSrt;

            // But we cannot actually move world space so we move cameraRig instead.
            // If we changed worldMovedSrt to identity cameraRigMovedSrt is just the new cameraRig transform in world (identity) space.
            // You don't have to actually change worldMovedSrt to identity... just set cameraRig (this) transform to cameraRigMovedSrt.

            this.transform.SetLocalSRT(cameraRigMovedSrt);

            // Note: Use the transform.SetLocalSrt( ... ) method to set cameraRig (this) frame to your result.
        }
예제 #3
0
    private void Update()
    {
        if (isLeftGripped || isRightGripped)
        {
            SetControllerSrt();
            Srt worldCameraFrame = controllerSrt * worldOffsetSrt;
            if (DollyMode)
            {
                Quaternion correction = Quaternion.FromToRotation(worldCameraFrame.localRotation * Vector3.up, Vector3.up);
                worldCameraFrame.localRotation = correction * worldCameraFrame.localRotation;
                worldCameraFrame.localPosition = correction * (worldCameraFrame.localPosition - controllerSrt.localPosition) + controllerSrt.localPosition;
            }
            worldSrt = worldCameraFrame.Inverse();

            transform.localPosition = worldSrt.localPosition;
            transform.localRotation = worldSrt.localRotation;
            transform.localScale    = worldSrt.localScale;
        }
    }
예제 #4
0
 private void SetWorldOffsetSrt()
 {
     cameraRigSrt.Set(transform.position, transform.rotation, transform.localScale);
     worldOffsetSrt = controllerSrt.Inverse() * cameraRigSrt.Inverse();
 }
예제 #5
0
    static public Srt Inverse(this Transform A)
    {
        Srt retval = new Srt(A);

        return(retval.Inverse());
    }