Exemple #1
0
    /// <summary>
    /// Update the screen Transformation.
    /// </summary>
    /// <param name="videoMode">Video mode.</param>
    /// <param name="verticalFieldOfView">Vertical FOV.</param>
    private void UpdateScreenTransformation(
        HardwareParameters.VideoModeAttributes videoMode, float verticalFieldOfView)
    {
        float fov = verticalFieldOfView;
        float distanceToScreen = gameObject.camera.farClipPlane;
        float frameAspect      = (float)videoMode.width / (float)videoMode.height;

        float scaleFactor = 1.0f;

        // Unity's Plane mesh default scale is 5
        float screenSize = 0.2f
                           * distanceToScreen
                           * Mathf.Tan(0.5f * fov * Mathf.Deg2Rad)
                           * scaleFactor;

        float screenWidth  = screenSize * frameAspect;
        float screenHeight = screenSize;

        Vector3 screenScale = new Vector3((Common.Mirroring ? 1 : -1) * screenWidth, 1f, screenHeight);

        screen.transform.localScale = screenScale;

        // We need this transformation dew to the way unity handles phone orientation
        screen.transform.localRotation = Common.GetWorldRotation() * Quaternion.AngleAxis(90f, Vector3.left);

        // distanceToScreen * 0.99f to make sure we are closer than camera far clipframe
        screen.transform.localPosition = new Vector3(0f, 0f, distanceToScreen * 0.99f);
    }
Exemple #2
0
    /// <summary>
    /// Init Texture2D.
    /// </summary>
    /// <param name="qualityMode">Video quality.</param>
    /// <param name="videoMode">Video mode.</param>
    /// <param name="backgroundTexture">Reference to Texture2D.</param>
    private void InitTexture(
        Mode qualityMode, HardwareParameters.VideoModeAttributes videoMode, ref Texture2D backgroundTexture)
    {
        int           potWidth, potHeight;
        TextureFormat textureFormat;

        if (qualityMode == Mode.QualityOptimized)
        {
            potWidth      = Mathf.NextPowerOfTwo(videoMode.width);
            potHeight     = Mathf.NextPowerOfTwo(videoMode.height);
            textureFormat = TextureFormat.ARGB32;
        }
        else if (qualityMode == Mode.PerformanceAndQuality)
        {
            potWidth      = Mathf.ClosestPowerOfTwo(videoMode.width);
            potHeight     = Mathf.ClosestPowerOfTwo(videoMode.height);
            textureFormat = TextureFormat.RGB565;
        }
        else
        {
            potWidth      = 512;
            potHeight     = 512;
            textureFormat = TextureFormat.RGB565;
        }

        backgroundTexture            = new Texture2D(potWidth, potHeight, textureFormat, false);
        backgroundTexture.filterMode = FilterMode.Bilinear;
        backgroundTexture.wrapMode   = TextureWrapMode.Clamp;
    }
Exemple #3
0
 /// <summary>
 /// Init screen, set screen texture.
 /// </summary>
 /// <param name="videoMode">Video mode.</param>
 /// <param name="backgroundTexture">Screen background texture.</param>
 private void InitScreen(HardwareParameters.VideoModeAttributes videoMode, Texture2D backgroundTexture)
 {
     if (screen == null)
     {
         ErrorHandler.instance.presentErrorMessage(
             "Camera component does not contain NCamera object of Screen is not assigned");
     }
     screen.renderer.material.mainTexture = backgroundTexture;
     StartCoroutine("InitBackground");
 }
Exemple #4
0
 /// <summary>
 /// Object major initializtion step.
 /// Build screen texture and initialize screen object.
 /// </summary>
 /// <param name="videoMode">Video mode.</param>
 /// <param name="verticalFieldOfView">Vertical FOV.</param>
 public void Init(HardwareParameters.VideoModeAttributes videoMode, float verticalFieldOfView)
 {
     InitTexture(mode, videoMode, ref m_backgroundTexture);
     InitScreen(videoMode, m_backgroundTexture);
     UpdateScreenTransformation(videoMode, verticalFieldOfView);
 }