Example #1
0
        public static Vector3 CalculateSitOnSurfaceOffset(AABB aabb, Plane surfacePlane, float offsetFromSurface)
        {
            List <Vector3> aabbCorners     = aabb.GetCornerPoints();
            int            pivotPointIndex = surfacePlane.GetFurthestPtBehind(aabbCorners);

            if (pivotPointIndex < 0)
            {
                pivotPointIndex = surfacePlane.GetClosestPtInFrontOrOnPlane(aabbCorners);
            }

            if (pivotPointIndex >= 0)
            {
                Vector3 pivotPt = aabbCorners[pivotPointIndex];
                Vector3 prjPt   = surfacePlane.ProjectPoint(pivotPt);
                return((prjPt - pivotPt) + surfacePlane.normal * offsetFromSurface);
            }

            return(Vector3.zero);
        }
Example #2
0
        public static void DrawWireCornerBox(AABB box, float wireCornerLinePercentage)
        {
            // Store these for easy access
            Mesh           wireCornerLineMesh = MeshPool.Get.UnitCoordSystem;
            List <Vector3> boxCorners         = box.GetCornerPoints();

            // Clamp percentage
            wireCornerLinePercentage = Mathf.Clamp(wireCornerLinePercentage, 0.0f, 1.0f);

            // Front bottom left point
            Vector3   originalScale   = box.Extents * wireCornerLinePercentage;
            Vector3   scale           = originalScale;
            Vector3   position        = boxCorners[(int)BoxCorner.FrontBottomLeft];
            Matrix4x4 transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);

            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Front bottom right point
            position        = boxCorners[(int)BoxCorner.FrontBottomRight];
            scale.x        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Front top right point
            position        = boxCorners[(int)BoxCorner.FrontTopRight];
            scale.y        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Front top left point
            position        = boxCorners[(int)BoxCorner.FrontTopLeft];
            scale           = originalScale;
            scale.y        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Back bottom left point
            position        = boxCorners[(int)BoxCorner.BackBottomLeft];
            scale.y         = originalScale.y;
            scale.x        *= -1.0f;
            scale.z        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Back bottom right point
            position        = boxCorners[(int)BoxCorner.BackBottomRight];
            scale.x         = originalScale.x;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Back top right point
            position        = boxCorners[(int)BoxCorner.BackTopRight];
            scale.y        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);

            // Back top left point
            position        = boxCorners[(int)BoxCorner.BackTopLeft];
            scale.x        *= -1.0f;
            transformMatrix = Matrix4x4.TRS(position, Quaternion.identity, scale);
            Graphics.DrawMeshNow(wireCornerLineMesh, transformMatrix);
        }