版本: Unity 6 (6000.0)
语言英语
  • C#

Matrix4x4.MultiplyPoint3x4

建议更改

成功!

感谢您帮助我们改进 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们会阅读用户提出的每项建议更改,并在适用时进行更新。

关闭

提交失败

由于某种原因,您的建议更改无法提交。请 <a>稍后再试</a>。感谢您花时间帮助我们改进 Unity 文档的质量。

关闭

取消

声明

public Vector3 MultiplyPoint3x4(Vector3 point);

描述

使用此矩阵转换位置(快速)。

返回由当前变换矩阵转换的位置 v。此函数是 MultiplyPoint 的更快版本;但它只能处理常规的 3D 变换。 MultiplyPoint 速度较慢,但也可以处理投影变换。

其他资源:MultiplyPointMultiplyVector

using UnityEngine;

public class ExampleScript : MonoBehaviour { // Stretch a mesh at an arbitrary angle around the X axis.

// Angle and amount of stretching. float rotAngle; float stretch;

MeshFilter mf; Vector3[] origVerts; Vector3[] newVerts;

void Start() { // Get the Mesh Filter component, save its original vertices // and make a new vertex array for processing. mf = GetComponent< MeshFilter > (); origVerts = mf.mesh.vertices; newVerts = new Vector3[origVerts.Length]; }

void Update() { // Create a rotation matrix from a Quaternion. Quaternion rot = Quaternion.Euler(rotAngle, 0, 0); Matrix4x4 m = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one);

// Get the inverse of the matrix (ie, to undo the rotation). Matrix4x4 inv = m.inverse;

// For each vertex... for (var i = 0; i < origVerts.Length; i++) { // Rotate the vertex and scale it along its new Y axis. var pt = m.MultiplyPoint3x4(origVerts[i]); pt.y *= stretch;

// Return the vertex to its original rotation (but with the // scaling still applied). newVerts[i] = inv.MultiplyPoint3x4(pt); }

// Copy the transformed vertices back to the mesh. mf.mesh.vertices = newVerts; } }