Skip to content

Instantly share code, notes, and snippets.

@nicloay
Last active August 29, 2015 13:56
Show Gist options
  • Save nicloay/9326636 to your computer and use it in GitHub Desktop.
Save nicloay/9326636 to your computer and use it in GitHub Desktop.
rotate around pivot issue
// enstead of this
GUIUtility.RotateAroundPivot(angle,
new Vector2(brushRect.x + brushRect.width * relativePivot.x,
brushRect.y + brushRect.height * relativePivot.y)
);
/////// should use
Matrix4x4 getMatrix(Rect rect){
Matrix4x4 result;
Vector2 v =new Vector2(rect.x + (rect.width * relativePivot.x) ,
rect.y + (rect.height * relativePivot.y)) ;
float scaleX = Screen.width / (float) GameData.instance.screenSize.x;
float scaleY = Screen.height / (float) GameData.instance.screenSize.y;
result =Matrix4x4.Scale(new Vector3(scaleX, scaleY, 1))
* Matrix4x4.TRS ( v, Quaternion.Euler(0,0,angle) , Vector3.one)
* Matrix4x4.TRS (-v, Quaternion.identity , Vector3.one);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment