コード例 #1
0
        public Bounds GetWorldBounds(IUsesCameraOffset cameraOffset, float minBound)
        {
            var worldPose   = cameraOffset.ApplyOffsetToPose(pose);
            var worldCenter = worldPose.position + worldPose.rotation * center;

            var size = new Vector3(extents.x * 0.5f, 0, extents.y * 0.5f);

            k_Corners[0] = size;
            size.x      *= -1;
            k_Corners[1] = size;

            var rotation = pose.rotation;
            var position = pose.position + rotation * center;

            size = Vector3.zero;
            foreach (var corner in k_Corners)
            {
                // Get corner position in plane space
                var localVertex = rotation * corner + position;
                // Get corner position in session space
                localVertex = cameraOffset.ApplyOffsetToPosition(localVertex) - worldCenter;
                var val    = localVertex.x;
                var absVal = val > 0 ? val : -val;
                if (absVal > size.x)
                {
                    size.x = absVal;
                }

                val    = localVertex.y;
                absVal = val > 0 ? val : -val;
                if (absVal > size.y)
                {
                    size.y = absVal;
                }

                val    = localVertex.z;
                absVal = val > 0 ? val : -val;
                if (absVal > size.z)
                {
                    size.z = absVal;
                }
            }

            size *= 2;

            if (size.x < minBound)
            {
                size.x = minBound;
            }

            if (size.y < minBound)
            {
                size.y = minBound;
            }

            if (size.z < minBound)
            {
                size.z = minBound;
            }

            return(new Bounds(worldCenter, size));
        }