我想获取一个顶点并将其存储在变量中。然后我想不断更新位置、旋转和平移。Ik 知道我可以将对象的位置与顶点的位置相加以获得新的顶点位置。但我不知道如何使用比例和旋转来做到这一点。有人知道吗?
using UnityEngine;
using System.Collections;
public class FollowVertex : MonoBehaviour {
public Transform testSphere;
public Transform indicator;
void Update()
{
indicator.position = GetVertex();
}
Vector3 GetVertex()
{
Mesh TMesh = testSphere.GetComponent<MeshFilter>().mesh;
Vector3 Tvertex = TMesh.vertices[1];
return Tvertex + testSphere.position ; // + the rotation, scale and translation of "testSphere"
}
}
提前感谢!
编辑 1:
我想我可以修改这个旋转功能以进行旋转。
function RotateVertexAround(center: Vector3, axis: Vector3, angle: float){
var pos: Vector3 = transform.position;
var rot: Quaternion = Quaternion.AngleAxis(angle, axis); // get the desired rotation
var dir: Vector3 = pos - center; // find current direction relative to center
dir = rot * dir; // rotate the direction
transform.position = center + dir; // define new position
// rotate object to keep looking at the center:
var myRot: Quaternion = transform.rotation;
transform.rotation *= Quaternion.Inverse(myRot) * rot * myRot;
}
现在我唯一需要知道的是如何做秤,我可以用矩阵做到这一点吗?
您应该能够通过 TransformPoint()
方法执行此操作,该方法将顶点从局部空间转换为世界空间。
即
Vector3 GetVertex()
{
Mesh TMesh = testSphere.GetComponent<MeshFilter>().mesh;
Vector3 Tvertex = TMesh.vertices[1];
return testSphere.TransformPoint(Tvertex);
}