简体   繁体   中英

Sorting points in 3D

If I have a set of points in 3D, and a camera plane, how would I sort them based on distance to that plane? I need pesudo code at least. I want to construct a plane from a camera then sort the points.

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM