Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Ravel · May 05, 2014 at 04:55 PM · guimatrix4x4rotatearoundpivot

Problems with Gropuing after a scaling matrix modification....

Well basically the problem is that when a texture(in my case "needle") is suposed to rotate around the gropus center (wich is the resolution of the background image (in my case "speedo") will have an incorrect pivot position...

This would normally not happen, but since I have a scaling matrix modification, the groups are not working properly...

Heres the code:

 using UnityEngine;
 using System.Collections;
 
 public class HUD : MonoBehaviour {
     
     public Texture2D speedo;
     public Texture2D needle;
     
     // Internal    
     private Vector2 currentResolution;
     private Vector2 nativeResolution;
     private Vector3 nativeScale;
     private float aspectRatio;
     private float nativeRes = 720;
     
     private float rotAngle = 0;    
     Rect speedoRect;
     Vector2 speedoPivot;
     
     void OnGUI ()
     {        
         InitGUIMatrix();        
         
         if(speedo)
         {
             GUI.BeginGroup(new Rect(100,0,512,512)); // <---- Matrix gets messed up
             GUI.DrawTexture(new Rect(0,0,speedo.width,speedo.height),speedo); // Background
             Matrix4x4 prevMat = GUI.matrix;    
             pivotPoint = new Vector2(speedo.width/2, speedo.height/2);    // Correct.
             pivotPoint.x /= (screenRect.width)/(Screen.width);            // Needs a modifyer after gropued?
             pivotPoint.y /= (screenRect.height)/(Screen.height);        // ...
             GUIUtility.RotateAroundPivot(rotAngle, pivotPoint); // <---- Fix me...
             
             rotAngle -= 100f*Time.deltaTime; // test rotation
             if(needle)
             {
                 GUI.DrawTexture(new Rect(0,0,speedo.width,speedo.height),needle); // Needle (rotating tex)
             }
             GUI.EndGroup();
             GUI.matrix = prevMat;
         }
     }
     
     /// Inits the GUI matrix.
     void InitGUIMatrix()
     {
         aspectRatio = GetScreenAspectRatio();
         currentResolution = new Vector2(Screen.width,Screen.height); // Just store
         nativeResolution.x = (nativeRes*aspectRatio);
         nativeResolution.y = nativeRes;
         nativeScale.x = Screen.width / nativeResolution.x;
         nativeScale.y = Screen.height / nativeResolution.y;
         nativeScale.z = 1;        
         scaledMat = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, nativeScale);
         GUI.matrix = scaledMat;
     }    
     
     float GetScreenAspectRatio()
     {
         return (Screen.width*(1.0f/Screen.height));
     }    
 }

Heres the original post for the media.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Texture Spinner - Dead Center 1 Answer

NullReferenceException using Matrix4x4? 2 Answers

Taking the user's screen resolution before running a GUI.matrix? 0 Answers

GUI Matrix problem 1 Answer

Why does my GUI.Window dragging behaviour act erratically on a rotated window? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges