Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

RotateAroundPivot when gui matrix is transformed

Discussion in 'Immediate Mode GUI (IMGUI)' started by HermanssoN, Mar 24, 2009.

  1. HermanssoN

    HermanssoN

    Joined:
    Mar 23, 2009
    Posts:
    8
    Hello.

    I'm trying to make my GUI resolution independant, following the example from the 3D platform tutorial.

    The GUI now looks nice on different resolution, all except the one I rotate. I have a leaver that rotates around a pivot point, and the rotation is only correct in one resolution.


    Code (csharp):
    1.  
    2. //m_virtualHeight = 768
    3. GUI.matrix = Matrix4x4.TRS (new Vector3(0, 0, 0), Quaternion.identity, new Vector3 (Screen.height / m_virtualHeight, Screen.height / m_virtualHeight, 1));
    4.  
    and when i rotate my leaver

    Code (csharp):
    1.  
    2. Matrix4x4 Old = GUI.matrix;
    3.        
    4.         GUIUtility.RotateAroundPivot ( m_pinAngle, m_pivot );
    5.        
    6.         if( m_difficultyPin )
    7.         {
    8.             GUI.Box( m_pinRect,m_difficultyPin );
    9.         }
    10.  

    This works fine when I run in 1024 * 768.
    I don't know hot to calculate the pivot point so it's resolution independant.
     
  2. HermanssoN

    HermanssoN

    Joined:
    Mar 23, 2009
    Posts:
    8
    Once the GUI.matrix has been given a new transform:


    Code (csharp):
    1.  
    2. GUI.matrix = Matrix4x4.TRS ( new Vector3(0f,0f,0f), Quaternion.identity,new  Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1));
    3.  
    4.  
    the GUIUtility.RotateAroundPivot stops to work. The pivot point is correct, but the rotation is all wrong.
     
  3. filecity

    filecity

    Joined:
    Apr 21, 2009
    Posts:
    117
    I also have the problem.

    I use GUI matrix to fit all my GUI nicely in any resolution.
    But the GUIUtility.RotateAroundPivot doesn't work in any resolution. The pivot point cannot adjust by itself in other resolution.

    Any solutions?
     
  4. MasterYoda

    MasterYoda

    Joined:
    Nov 21, 2012
    Posts:
    1
    facing the same problem,

    multiplying (Screen.height/Screen.width)*(1024.0/768.0) to the m_pinAngle takes care of rotation and you need to modify m_pivot coordinates also(as they don't get scaled by the GUI matrix). So multiplying (Screen.width / 1024.0) to m_pivot's x coordinate and (Screen.height / 768.0) to y will take care of that.


    I did that and the new scaling was a little better but still not accurate when pivotangle is large.
    Any idea how to do that?

    Thanks
     
  5. diegodorado

    diegodorado

    Joined:
    Jul 2, 2013
    Posts:
    4
    Thanx MasterYoda! that did the trick for me... wasnt using large angles thogh... with small angles works great.
    Anyway, this should be taken care by unity matrix