如果我在3D中有一组点和一个摄像机平面,我将如何根据到该平面的距离对它们进行排序?我至少需要pesudo代码。我想用相机构建一个平面然后对点进行排序。
答案 0 :(得分:1)
class CompareDistance
{
public float DistanceToCameraPlane(Vector3 pointInSpace)
{
var cameraPosition = Camera.main.transform.position;
var cameraForward = Camera.main.transform.forward;
var deltaToCamera = pointInSpace - cameraPosition;
var projection = Vector3.Project(deltaToCamera, cameraForward);
return projection.magnitude;
}
}