英文:
How to skew in Unity with matrix values?
问题
我需要对Unity项目中的元素进行一些变换,使用我从XML文件中提取的矩阵数值:
<DOMBitmapInstance libraryItemName="Scene/Picture/CAM_U_cptgen_GEN_TOP_T1(4th_seat).png">
<matrix>
<Matrix a="0" b="1.66069030761719" c="-1.66069030761719" d="0" tx="178.5" ty="-673"/>
</matrix>
</DOMBitmapInstance>
我的问题是,如何倾斜我的图像,因为'a'和'd'应该是x和y的缩放,而'b'和'c'是y和x的倾斜。
我需要在Unity中显示图像并对其进行动画处理,因此这些值可能会更改。
到目前为止,我已提取了所有的值并已应用'a'和'd'。
提前感谢!
在项目的先前版本中,我曾在同一项目上工作,但是生成的不是源文件(如他们所说,计划已更改),它是在js中生成的,我可以轻松提取倾斜值,因为它是一个像'90'度这样的旋转值。但是对于同一项目,现在我有这些数值,我不太知道如何将它们应用到Unity Transform中。
英文:
I need to do some transform to elements in Unity for a project, with matrix values that I extract on a XML file :
<DOMBitmapInstance libraryItemName="Scene/Picture/CAM_U_cptgen_GEN_TOP_T1(4th_seat).png">
<matrix>
<Matrix a="0" b="1.66069030761719" c="-1.66069030761719" d="0" tx="178.5" ty="-673"/>
</matrix>
</DOMBitmapInstance>
My question is, how can I skew my image, because 'a' and 'd' are supposed to be for x and y scale, and 'b' and 'c' are for y and x skew.
I need to display images and to animate them in Unity, so this values can change.
For now on, I extract all values and already apply 'a' and 'd'.
Thanks in advance !
In a previous version of the project, I worked on the same project but generated, not the source file (plans have changed like they say) and It was generated in js, and I could easily extract Skew value because It was a rotation value like '90' degrees. But for the same project, now I have this numbers I don't really know how to apply them into a Unity Transform.
答案1
得分: 0
所以,我找到了一个解决方案,如果有人将来需要做和我一样的事情,我会在这里发布。
public void SetSkew(float b, float c)
{
float a = elementObject.transform.localScale.x;
elementObject.GetComponent<RectTransform>().localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(c, a) * Mathf.Rad2Deg);
}
英文:
So, I found a solution, I'll post here if someone needs one day to do the same as me.
public void SetSkew(float b, float c)
{
float a = elementObject.transform.localScale.x;
elementObject.GetComponent<RectTransform>().localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(c, a) * Mathf.Rad2Deg);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论