Exemplo n.º 1
0
        internal void CalculateCameraParameters(NativeCameraState nativeCameraState, out DoubleVector3 cameraPositionECEF, out DoubleVector3 interestPointECEF, out Vector3 cameraUpECEF)
        {
            var scaledInterestPoint = ScaleInterestPointWithEnvironmentFlattening(nativeCameraState.interestPointECEF);

            Vector3       forward, up;
            DoubleVector3 positionECEF;

            CameraHelpers.CalculateLookAt(
                scaledInterestPoint,
                nativeCameraState.interestBasisForwardECEF,
                nativeCameraState.pitchDegrees * Mathf.Deg2Rad,
                nativeCameraState.distanceToInterestPoint,
                out positionECEF, out forward, out up);

            interestPointECEF  = scaledInterestPoint;
            cameraPositionECEF = positionECEF;
            cameraUpECEF       = up;
        }
Exemplo n.º 2
0
        internal void ApplyNativeCameraState(NativeCameraState nativeCameraState, UnityEngine.Camera controlledCamera)
        {
            // assuming uniform scale
            var mapScale = m_root.transform.lossyScale;

            Debug.Assert(Mathf.Approximately(mapScale.x, mapScale.y) && Mathf.Approximately(mapScale.x, mapScale.z),
                         "When using built-in camera controls the map must have a uniform scale (identical along all axes).");

            controlledCamera.fieldOfView   = nativeCameraState.fieldOfViewDegrees;
            controlledCamera.nearClipPlane = nativeCameraState.nearClipPlaneDistance * mapScale.x;
            controlledCamera.farClipPlane  = nativeCameraState.farClipPlaneDistance * mapScale.x;

            DoubleVector3 cameraPositionECEF, interestPointECEF;
            Vector3       cameraUpECEF;

            CalculateCameraParameters(nativeCameraState, out cameraPositionECEF, out interestPointECEF, out cameraUpECEF);
            m_interestPointProvider.UpdateFromNative(interestPointECEF);

            var cameraRotation = new Quaternion();

            if (m_coordinateSystem == CoordinateSystem.ECEF)
            {
                var position = (cameraPositionECEF - m_originECEF).ToSingleVector();
                var interestPointPosition = (interestPointECEF - m_originECEF).ToSingleVector();
                var cameraToInterestPoint = interestPointPosition - position;

                controlledCamera.transform.position = m_root.transform.TransformPoint(position);
                cameraRotation.SetLookRotation(cameraToInterestPoint.normalized, cameraUpECEF);
                controlledCamera.transform.rotation = m_root.transform.rotation * cameraRotation;
            }
            else // if (m_coordinateSystem == CoordinateSystem.UnityWorld)
            {
                var localCameraPosition = m_frame.ECEFToLocalSpace(cameraPositionECEF);
                controlledCamera.transform.position = m_root.transform.TransformPoint(localCameraPosition);
                var localUp = m_frame.ECEFToLocalRotation * cameraUpECEF;
                var cameraToInterestPointECEF = (interestPointECEF - cameraPositionECEF).ToSingleVector();
                var localViewDirection        = m_frame.ECEFToLocalRotation * cameraToInterestPointECEF;
                cameraRotation.SetLookRotation(localViewDirection.normalized, localUp);
                controlledCamera.transform.rotation = m_root.transform.rotation * cameraRotation;
            }
        }
Exemplo n.º 3
0
        internal void ApplyNativeCameraState(NativeCameraState nativeCameraState, UnityEngine.Camera controlledCamera)
        {
            controlledCamera.fieldOfView   = nativeCameraState.fieldOfViewDegrees;
            controlledCamera.nearClipPlane = nativeCameraState.nearClipPlaneDistance;
            controlledCamera.farClipPlane  = nativeCameraState.farClipPlaneDistance;

            var interestBasis = new EcefTangentBasis(
                nativeCameraState.interestPointECEF,
                nativeCameraState.interestBasisRightECEF,
                nativeCameraState.interestBasisUpECEF,
                nativeCameraState.interestBasisForwardECEF);

            Vector3       forward, up;
            DoubleVector3 positionECEF;

            CameraHelpers.CalculateLookAt(
                interestBasis.PointEcef,
                interestBasis.Forward,
                nativeCameraState.pitchDegrees * Mathf.Deg2Rad,
                nativeCameraState.distanceToInterestPoint,
                out positionECEF, out forward, out up);

            m_interestPointProvider.UpdateFromNative(nativeCameraState.interestPointECEF);

            if (m_coordinateSystem == CoordinateSystem.ECEF)
            {
                var position = (positionECEF - m_originECEF).ToSingleVector();
                controlledCamera.transform.position = position;
                controlledCamera.transform.LookAt((interestBasis.PointEcef - m_originECEF).ToSingleVector(), up);
            }
            else // if (m_coordinateSystem == CoordinateSystem.UnityWorld)
            {
                controlledCamera.transform.position = m_frame.ECEFToLocalSpace(positionECEF);
                controlledCamera.transform.LookAt(m_frame.ECEFToLocalSpace(interestBasis.PointEcef), m_frame.ECEFToLocalRotation * up);
            }
        }