Search Unity

Vertical text (90 degree rotation of horizontal text)

Discussion in 'Immediate Mode GUI (IMGUI)' started by Marc, Nov 29, 2007.

  1. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    Is there are way to rotate text in a label 90 degress so it will be vertical instead of horizontal in UnityGUI?

    Regards,
    Marc
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Yes. Setting the value of GUI.Matrix will allow you to do arbitrary transforms of your GUI (buttons, labels, etc)
     
  3. Marc

    Marc

    Joined:
    Oct 4, 2007
    Posts:
    499
    The reference point for the transformations are the center of the screen?

    EDIT: NVM i figued it out (it is center of screen). Thanks!
     
  4. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    I am getting a "bug" while using transformations. I want to create a Box rotated 45º and placed in the middle of the screen. My initial thought was to center it on zero and then create a matrix that rotated it 45º and moved it to the center of the screen:
    Code (csharp):
    1. Matrix4x4 m = Matrix4x4.identity;
    2. m.SetTRS(new Vector3(Screen.width/2, Screen.height/2), Quaternion.Euler(0,0,45), new Vector3(1,1,1));
    3. GUI.matrix = m;
    4. GUI.Box( new Rect(-50, -50 , 100, 100), "");
    5. GUI.matrix = Matrix4x4.identity;
    However, this does not work because GUI stuff that is out of the screen is clipped out (i.e. the (-50, -50) to (0,0) of the box is cut out).
    This means that I can't rotate something around its center. Is this a bug? Does this mean that if I want to rotate something around its center I need to create it from (0,0), rotate it, and then try to figure out exactly what pixels I need to subtract from the translation to make it look like it rotated around its axis?

    Regards,
    Afonso
     
  5. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Well, I didn't find any information about this, is this a bug or not? It seems like a bug to me. At this moment, the way I did it was by multiplying two matrixes in order to first change where it will rotate, then rotate it, and then move it back. I would like some clarification about this please.

    For anyone trying to rotate a GUI element around the middle of it, here is the only "clean" way I found do it:
    Code (csharp):
    1. Matrix4x4 m1 = Matrix4x4.identity;
    2. Matrix4x4 m2 = Matrix4x4.identity;
    3.        
    4. m2.SetTRS(new Vector3(200,200,0), Quaternion.Euler(0,0,aux), Vector3.one);
    5.        
    6. aux += 10f*Time.deltaTime; // aux is just to see it spin
    7. if( aux > 360f )
    8.     aux = 0.0f;
    9.  
    10. m1.SetTRS( new Vector3(-50, -50, 0), Quaternion.identity, Vector3.one );
    11.  
    12. GUI.matrix = m2*m1;
    13.  
    14. GUI.Box( new Rect(0,0 , 100, 100), "Hello My Friends!");
    15.  
    16. GUI.matrix = Matrix4x4.identity;