예제 #1
0
 public bool AabbCull(AabbBounds aabb)
 {
     if (AabbCullPlaneCheck(aabb, left))
     {
         return(true);
     }
     if (AabbCullPlaneCheck(aabb, right))
     {
         return(true);
     }
     if (AabbCullPlaneCheck(aabb, bottom))
     {
         return(true);
     }
     if (AabbCullPlaneCheck(aabb, top))
     {
         return(true);
     }
     if (AabbCullPlaneCheck(aabb, near))
     {
         return(true);
     }
     if (AabbCullPlaneCheck(aabb, far))
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
        public AabbBounds TransformAabb(mat4 transformation)
        {
            Span <vec3> points = stackalloc [] {
                new vec3(max.x, max.y, max.z),
                new vec3(max.x, max.y, min.z),
                new vec3(max.x, min.y, max.z),
                new vec3(max.x, min.y, min.z),
                new vec3(min.x, max.y, max.z),
                new vec3(min.x, max.y, min.z),
                new vec3(min.x, min.y, max.z),
                new vec3(min.x, min.y, min.z)
            };

            points[0] = (transformation * new vec4(points[0], 1)).xyz;              //vec3.Transform(points[0], transformation);
            AabbBounds newBounds = new AabbBounds(points[0]);

            for (int i = 1; i < points.Length; i++)
            {
                points[i] = (transformation * new vec4(points[i], 1)).xyz;
                newBounds = newBounds.Encapsulate(points[i]);
            }

            return(newBounds);
        }
    }
예제 #3
0
        private bool AabbCullPlaneCheck(AabbBounds aabb, Plane plane)
        {
            vec3 planeNormal = plane.Normal();
            vec3 axisVert    = new vec3();

            // x-axis
            if (plane.a < 0.0f)               // Which AABB vertex is furthest down (plane normals direction) the x axis
            {
                axisVert.x = aabb.min.x;      // min x plus tree positions x
            }
            else
            {
                axisVert.x = aabb.max.x;                 // max x plus tree positions x
            }
            // y-axis
            if (plane.b < 0.0f)               // Which AABB vertex is furthest down (plane normals direction) the y axis
            {
                axisVert.y = aabb.min.y;
            }
            else
            {
                axisVert.y = aabb.max.y;
            }

            // z-axis
            if (plane.c < 0.0f)               // Which AABB vertex is furthest down (plane normals direction) the z axis
            {
                axisVert.z = aabb.min.z;
            }
            else
            {
                axisVert.z = aabb.max.z;
            }

            // Now we get the signed distance from the AABB vertex that's furthest down the frustum planes normal,
            // and if the signed distance is negative, then the entire bounding box is behind the frustum plane, which means
            // that it should be culled

            //ClassifyPoint
            return(vec3.Dot(planeNormal, axisVert) + plane.d < 0.0f);
        }