如何在Unity中使用矩阵数值进行倾斜?

huangapple go评论87阅读模式
英文:

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 :

&lt;DOMBitmapInstance libraryItemName=&quot;Scene/Picture/CAM_U_cptgen_GEN_TOP_T1(4th_seat).png&quot;&gt;
  &lt;matrix&gt;
    &lt;Matrix a=&quot;0&quot; b=&quot;1.66069030761719&quot; c=&quot;-1.66069030761719&quot; d=&quot;0&quot; tx=&quot;178.5&quot; ty=&quot;-673&quot;/&gt;
  &lt;/matrix&gt;
&lt;/DOMBitmapInstance&gt;

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&lt;RectTransform&gt;().localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(c, a) * Mathf.Rad2Deg);
}

huangapple
  • 本文由 发表于 2023年1月9日 19:07:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定