UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
Vector3.OrthoNormalize
# [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html).OrthoNormalize public static void **OrthoNormalize** (ref [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **normal**, ref [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **tangent**); ## 描述 将向量标准化并使它们彼此正交。 标准化 `tangent`。 标准化 `tangent` 并确保其与 `normal` 正交(即它们之间的角度为 90 度)。 另请参阅:[Normalize](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.Normalize.html) 函数。 --- public static void **OrthoNormalize** (ref [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **normal**, ref [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **tangent**, ref [Vector3](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.html) **binormal**); ## 描述 将向量标准化并使它们彼此正交。 标准化 `tangent`。 标准化 `tangent` 并确保其与 `normal` 正交。 标准化 `binormal` 并确保其与 `normal` 和 `tangent` 正交。 空间中的点通常使用标准 XYZ 轴系的坐标指定。 但是,如果有任意三个向量为标准化向量(即其大小为 1) 并且彼此正交(即相互垂直),您就可以将它们解读为“轴”。 创建自己的坐标轴很有用,例如,若要在任意方向上缩放网格 而不只是沿 XYZ 轴缩放,则您可以将顶点变换到自己的坐标系, 对其进行缩放,然后再变换回来。通常情况下,这样的变换将仅沿一个轴进行, 另外两个轴要么保持不变,要么受到平等对待。 例如,可以通过在一个轴上放大,同时在另外两个轴上按比例缩小的方式 向网格应用拉伸效果。也就是说,一旦指定了第一个轴向量, 则另两个轴向量并不重要(只要它们是标准化并且正交的即可)。 OrthoNormalize 可用于确保第一个向量为标准化向量, 然后为其他两个轴生成标准化的正交向量。 ``` // Mesh "stretch" effect along a chosen axis. using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { // The axis and amount of scaling. public Vector3 stretchAxis; public float stretchFactor = 1.0F; // MeshFilter component and arrays for the original and transformed vertices. private MeshFilter mf; private Vector3[] origVerts; private Vector3[] newVerts; // Our new basis vectors. private Vector3 basisA; private Vector3 basisB; private Vector3 basisC; void Start() { // Get the Mesh Filter, then make a copy of the original vertices // and a new array to calculate the transformed vertices. mf = GetComponent<MeshFilter>(); origVerts = mf.mesh.vertices; newVerts = new Vector3[origVerts.Length]; } void Update() { // BasisA is just the specified axis for stretching - the // other two are just arbitrary axes generated by OrthoNormalize. basisA = stretchAxis; Vector3.OrthoNormalize(ref basisA, ref basisB, ref basisC); // Copy the three new basis vectors into the rows of a matrix // (since it is actually a 4x4 matrix, the bottom right corner // should also be set to 1). Matrix4x4 toNewSpace = new Matrix4x4(); toNewSpace.SetRow(0, basisA); toNewSpace.SetRow(1, basisB); toNewSpace.SetRow(2, basisC); toNewSpace[3, 3] = 1.0F; // The scale values are just the diagonal entries of the scale // matrix. The vertices should be stretched along the first axis // and squashed proportionally along the other two. Matrix4x4 scale = new Matrix4x4(); scale[0, 0] = stretchFactor; scale[1, 1] = 1.0F / stretchFactor; scale[2, 2] = 1.0F / stretchFactor; scale[3, 3] = 1.0F; // The inverse of the first matrix transforms the vertices back to // the original XYZ coordinate space(transpose is the same as inverse // for an orthogonal matrix, which this is). Matrix4x4 fromNewSpace = toNewSpace.transpose; // The three matrices can now be combined into a single symmetric matrix. Matrix4x4 trans = toNewSpace * scale * fromNewSpace; // Transform each of the mesh's vertices by the symmetric matrix. int i = 0; while (i < origVerts.Length) { newVerts[i] = trans.MultiplyPoint3x4(origVerts[i]); i++; } // ...and finally, update the mesh with the new vertex array. mf.mesh.vertices = newVerts; } } ``` 另请参阅:[Normalize](https://docs.unity3d.com/cn/2019.4/ScriptReference/Vector3.Normalize.html) 函数。
da
2022年6月22日 10:56
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码