コード例 #1
0
ファイル: CameraEx.cs プロジェクト: youngbrett/TreehouseHack
        public static List <GameObject> GetVisibleObjects(this Camera camera, CameraViewVolume viewVolume)
        {
            // Retrieve the objects which are overlapped by the camera volume's OBB
            List <GameObject> overlappedObjects = RTScene.Get.OverlapBox(viewVolume.WorldOBB);

            if (overlappedObjects.Count == 0)
            {
                return(new List <GameObject>());
            }

            // Loop through each overlapped object
            var boundsQConfig = new ObjectBounds.QueryConfig();

            boundsQConfig.ObjectTypes  = GameObjectTypeHelper.AllCombined;
            boundsQConfig.NoVolumeSize = Vector3Ex.FromValue(1e-5f);

            var visibleObjects = new List <GameObject>(overlappedObjects.Count);

            foreach (var gameObject in overlappedObjects)
            {
                // Retrieve the object's world AABB
                AABB worldAABB = ObjectBounds.CalcWorldAABB(gameObject, boundsQConfig);

                // If the AABB is valid and if the camera's view volume intersects the AABB,
                // it means we are dealing with a visible object so we store it inside the
                // output list.
                if (worldAABB.IsValid && viewVolume.CheckAABB(worldAABB))
                {
                    visibleObjects.Add(gameObject);
                }
            }

            return(visibleObjects);
        }
コード例 #2
0
        /// <summary>
        /// Checks if the handle is visible on the screen (i.e. it is visible to the
        /// specified camera.
        /// </summary>
        /// <param name="camera">The camera which is involved in the visibility test.</param>
        /// <param name="frustumWorldPlanes">The camera frustum world planes.</param>
        /// <returns>
        /// True if at least one shape (either 2D or 3D) that belongs to the handle is
        /// visible and false otehrwise. Note: When the gizmo position lies behind the
        /// camera near plane, all 2D shapes are considered NOT visible.
        /// </returns>
        public bool IsVisibleToCamera(Camera camera, Plane[] frustumWorldPlanes)
        {
            bool found2DVisible = false;
            bool found3DVisible = false;

            if (Num2DShapes != 0)
            {
                if (camera.IsPointInFrontNearPlane(Gizmo.Transform.Position3D))
                {
                    foreach (var shape in _2DShapes)
                    {
                        Rect enclosingRect = shape.Shape.GetEncapsulatingRect();
                        if (camera.pixelRect.Overlaps(enclosingRect, true))
                        {
                            found2DVisible = true;
                            break;
                        }
                    }
                }
            }

            if (found2DVisible)
            {
                return(true);
            }

            if (Num3DShapes != 0)
            {
                foreach (var shape in _3DShapes)
                {
                    AABB aabb = shape.Shape.GetAABB();
                    if (CameraViewVolume.CheckAABB(camera, aabb, frustumWorldPlanes))
                    {
                        found3DVisible = true;
                        break;
                    }
                }
            }

            return(found3DVisible);
        }