Here are the examples of the csharp api UnityEngine.GeometryUtility.TestPlanesAABB(UnityEngine.Plane[], UnityEngine.Bounds) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
View Source File : SimpleTagalong.cs
License : MIT License
Project Creator : dag10
License : MIT License
Project Creator : dag10
protected virtual bool CalculateTagalongTargetPosition(Vector3 fromPosition, out Vector3 toPosition)
{
// Check to see if any part of the Tagalong's BoxCollider's bounds is
// inside the camera's view frustum. Note, the bounds used are an Axis
// Aligned Bounding Box (AABB).
bool needsToMove = !GeometryUtility.TestPlanesAABB(frustumPlanes, tagalongCollider.bounds);
// If we already know we don't need to move, bail out early.
if (!needsToMove)
{
toPosition = fromPosition;
return false;
}
// Calculate a default position where the Tagalong should go. In this
// case TagalongDistance from the camera along the gaze vector.
toPosition = Camera.main.transform.position + Camera.main.transform.forward * TagalongDistance;
// Create a Ray and set it's origin to be the default toPosition that
// was calculated above.
Ray ray = new Ray(toPosition, Vector3.zero);
Plane plane = new Plane();
float distanceOffset = 0f;
// Determine if the Tagalong needs to move to the right or the left
// to get back inside the camera's view frustum. The normals of the
// planes that make up the camera's view frustum point inward.
bool moveRight = frustumPlanes[frustumLeft].GetDistanceToPoint(fromPosition) < 0;
bool moveLeft = frustumPlanes[frustumRight].GetDistanceToPoint(fromPosition) < 0;
if (moveRight)
{
// If the Tagalong needs to move to the right, that means it is to
// the left of the left frustum plane. Remember that plane and set
// our Ray's direction to point towards that plane (remember the
// Ray's origin is already inside the view frustum.
plane = frustumPlanes[frustumLeft];
ray.direction = -Camera.main.transform.right;
}
else if (moveLeft)
{
// Apply similar logic to above for the case where the Tagalong
// needs to move to the left.
plane = frustumPlanes[frustumRight];
ray.direction = Camera.main.transform.right;
}
if (moveRight || moveLeft)
{
// If the Tagalong needed to move in the X direction, cast a Ray
// from the default position to the plane we are working with.
plane.Raycast(ray, out distanceOffset);
// Get the point along that ray that is on the plane and update
// the x component of the Tagalong's desired position.
toPosition.x = ray.GetPoint(distanceOffset).x;
}
// Similar logic follows below for determining if and how the
// Tagalong would need to move up or down.
bool moveDown = frustumPlanes[frustumTop].GetDistanceToPoint(fromPosition) < 0;
bool moveUp = frustumPlanes[frustumBottom].GetDistanceToPoint(fromPosition) < 0;
if (moveDown)
{
plane = frustumPlanes[frustumTop];
ray.direction = Camera.main.transform.up;
}
else if (moveUp)
{
plane = frustumPlanes[frustumBottom];
ray.direction = -Camera.main.transform.up;
}
if (moveUp || moveDown)
{
plane.Raycast(ray, out distanceOffset);
toPosition.y = ray.GetPoint(distanceOffset).y;
}
// Create a ray that starts at the camera and points in the direction
// of the calculated toPosition.
ray = new Ray(Camera.main.transform.position, toPosition - Camera.main.transform.position);
// Find the point along that ray that is the right distance away and
// update the calculated toPosition to be that point.
toPosition = ray.GetPoint(TagalongDistance);
// If we got here, needsToMove will be true.
return needsToMove;
}
19
View Source File : BoundsOctreeNode.cs
License : MIT License
Project Creator : IxxyXR
License : MIT License
Project Creator : IxxyXR
public void GetWithinFrustum(Plane[] planes, List<T> result) {
// Is the input node inside the frustum?
if (!GeometryUtility.TestPlanesAABB(planes, bounds)) {
return;
}
// Check against any objects in this node
for (int i = 0; i < objects.Count; i++) {
if (GeometryUtility.TestPlanesAABB(planes, objects[i].Bounds)) {
result.Add(objects[i].Obj);
}
}
// Check children
if (children != null) {
for (int i = 0; i < 8; i++) {
children[i].GetWithinFrustum(planes, result);
}
}
}
19
View Source File : RetainedGizmos.cs
License : MIT License
Project Creator : XINCGer
License : MIT License
Project Creator : XINCGer
public void FinalizeDraw () {
RemoveUnusedMeshes(meshes);
var cam = Camera.current;
var planes = GeometryUtility.CalculateFrustumPlanes(cam);
// Silently do nothing if the materials are not set
if (surfaceMaterial == null || lineMaterial == null) return;
Profiler.BeginSample("Draw Retained Gizmos");
// First surfaces, then lines
for (int matIndex = 0; matIndex <= 1; matIndex++) {
var mat = matIndex == 0 ? surfaceMaterial : lineMaterial;
for (int preplaced = 0; preplaced < mat.preplacedCount; preplaced++) {
mat.SetPreplaced(preplaced);
for (int i = 0; i < meshes.Count; i++) {
if (meshes[i].lines == (mat == lineMaterial) && GeometryUtility.TestPlanesAABB(planes, meshes[i].mesh.bounds)) {
Graphics.DrawMeshNow(meshes[i].mesh, Matrix4x4.idenreplacedy);
}
}
}
}
usedHashes.Clear();
Profiler.EndSample();
}