Search Unity

Rotate Camera Viewport Issue

Discussion in 'Scripting' started by devandart, Apr 11, 2014.

  1. devandart

    devandart

    Joined:
    Jun 7, 2013
    Posts:
    144
    Hi folks,

    I have to create a game for 6 players on a touch screen table.
    So I have to rotate the viewports (for each player a individual viewport) around the display.

    For this task I use this script on each camera:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class CameraMatrixManipulator : MonoBehaviour {
    6.     public float ViewportAngle = 0f;
    7.     public Vector3 Scale = Vector3.one;
    8.  
    9.     void Start(){
    10.     }
    11.  
    12.     void OnPreCull() {
    13.         camera.ResetWorldToCameraMatrix();
    14.         camera.ResetProjectionMatrix();
    15.        
    16.         camera.projectionMatrix = camera.projectionMatrix *
    17.             Matrix4x4.TRS(camera.transform.position, Quaternion.AngleAxis(ViewportAngle, camera.transform.forward), Scale);
    18.     }
    19.  
    20.     void OnPreRender() {
    21.         GL.SetRevertBackfacing(true);
    22.     }
    23.  
    24.     void OnPostRender() {  
    25.     GL.SetRevertBackfacing(false);
    26.     }
    27. }
    28.  
    Everything seems fine but when I move the rotated (ViewportAngle = -90 for e.g.) cameras during runtime on the x OR y individually axes the viewport shifts on x AND y the same time.

    I hope one of you can show me a hint what is wrong in my script.

    Thank you really much!

    Regards

    [SOLVED]
    I set the viewport rect of each camera, rotated each camera and then each camera got a empty GameObject without rotation.
    Thats the Solution. :D

    It's so easy... Damn it. :D
     
    Last edited: Apr 23, 2014
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    no response... so newbie question time :)

    bit of a shot in the dark but it's not an issue of World vs Local coordinate systems is it?
     
  3. devandart

    devandart

    Joined:
    Jun 7, 2013
    Posts:
    144
    This is a good idea, but I don't know where. :D
    This problem only happens when the ViewportAngle is unequal 0.

    Any other ideas?
     
  4. devandart

    devandart

    Joined:
    Jun 7, 2013
    Posts:
    144
    Another idea was to use this method, but it doesn't work, too.

    Code (csharp):
    1.  
    2. camera.projectionMatrix = camera.projectionMatrix *
    3.             Matrix4x4.TRS(camera.transform.position, Quaternion.Euler(0, 0, ViewportAngle), Scale);
    4.