예제 #1
0
    private void UpdateCameraPosition()
    {
        if (cameraRotation.x > 80)
        {
            cameraRotation.x = 80f;
        }
        else if (cameraRotation.x < 0)
        {
            cameraRotation.x = 0;
        }

        float rx = 90 - cameraRotation.x;

        if (rx > 89.9)
        {
            rx = 89.9f;
        }

        double px = Math.Cos(rx * Mathf.Deg2Rad) * cameraDistance;
        double py = Math.Sin(rx * Mathf.Deg2Rad) * cameraDistance;
        double pz = Math.Cos(cameraRotation.y * Mathf.Deg2Rad) * px;

        px = Math.Sin(cameraRotation.y * Mathf.Deg2Rad) * px;

        Vector3 targetPosition = transform.position;

        if (this is OnlineMapsTileSetControl)
        {
            Vector3 offset = new Vector3(api.tilesetSize.x / -2, 0, api.tilesetSize.y / 2);
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;

            if (control.smoothZoom && control.smoothZoomStarted)
            {
                targetPosition = control.originalPosition;
            }

            if (control.useElevation && control.elevationZoomRange.InRange(api.zoom))
            {
                double tlx, tly, brx, bry;
                api.GetTopLeftPosition(out tlx, out tly);
                api.GetBottomRightPosition(out brx, out bry);

                float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry);
                offset.y = control.GetMaxElevationValue(yScale);
            }

            targetPosition += transform.rotation * offset;
        }

        Vector3 oldPosition = activeCamera.transform.position;
        Vector3 newPosition = transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition;

        activeCamera.transform.position = newPosition;
        activeCamera.transform.LookAt(targetPosition);

        if (oldPosition != newPosition && OnCameraControl != null)
        {
            OnCameraControl();
        }
    }
예제 #2
0
    protected void UpdateCameraPosition()
    {
        //if (cameraRotation.x > maxCameraRotationX) cameraRotation.x = 0; //changed value here
        //else if (cameraRotation.x < 0) cameraRotation.x = 0;

        float rx = 90 - 0;

        if (rx > 89.9)
        {
            rx = 89.9f;
        }

        double px = Math.Cos(rx * Mathf.Deg2Rad) * cameraDistance;
        double py = Math.Sin(rx * Mathf.Deg2Rad) * cameraDistance;
        double pz = Math.Cos(cameraRotation.y * Mathf.Deg2Rad) * px;

        px = Math.Sin(cameraRotation.y * Mathf.Deg2Rad) * px;

        Vector3 targetPosition = transform.position;

        if (this is OnlineMapsTileSetControl)
        {
            Vector3 offset = new Vector3(map.tilesetSize.x / -2, 0, map.tilesetSize.y / 2);
            OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance;

            if (control.smoothZoom && control.smoothZoomStarted)
            {
                targetPosition = originalPosition;
            }

            if (control.useElevation && control.elevationZoomRange.InRange(map.zoom))
            {
                double tlx, tly, brx, bry;
                map.GetCorners(out tlx, out tly, out brx, out bry);
                float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry);
                if (cameraAdjustTo == OnlineMapsCameraAdjust.maxElevationInArea)
                {
                    offset.y = control.GetMaxElevationValue(yScale);
                }
                else
                {
                    offset.y = control.GetElevationValue(targetPosition.x, targetPosition.z, yScale, tlx, tly, brx, bry);
                }
            }

            offset.Scale(control.smoothZoomStarted? control.originalScale: transform.lossyScale);
            targetPosition += transform.rotation * offset;
        }

        Vector3 oldPosition = activeCamera.transform.position;
        Vector3 newPosition = transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition;

        activeCamera.transform.position = newPosition;
        activeCamera.transform.LookAt(targetPosition);

        if (oldPosition != newPosition && OnCameraControl != null)
        {
            OnCameraControl();
        }
    }