Esempio n. 1
0
        public OcclusionCullingSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;

            // Occlusion culling is implemented in the OcclusionCullingScreen.
            _graphicsScreen = new OcclusionCullingScreen(Services);
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
            Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

            // Add a custom game object which controls the camera.
            var cameraGameObject = new CameraObject(Services);

            GameObjectService.Objects.Add(cameraGameObject);
            _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

            // Load environment.
            GameObjectService.Objects.Add(new StaticSkyObject(Services)); // (includes light nodes)
            GameObjectService.Objects.Add(new StaticObject(Services, "Gravel/Gravel", 1, new Pose(new Vector3F(0, 0, 0))));

            // Set main directional light to enable shadow caster culling.
            _graphicsScreen.LightNode = ((LightNode)_graphicsScreen.Scene.GetSceneNode("Sunlight"));

            // To disable shadow maps and shadow caster culling:
            //((LightNode)_graphicsScreen.Scene.GetSceneNode("Sunlight")).Shadow = null;
            // _graphicsScreen.LightNode = null;

            // ----- Load building:
            // The model "Building/Building.fbx" represent a building that is assembled
            // from modular building blocks:
            //   "Building/concrete_door.fbx"
            //   "Building/concrete_double_window.fbx"
            //   "Building/concrete_small_double_window.fbx"
            //   "Building/wall_concrete_1.fbx"
            //   "Building/pillar_concrete_1.fbx"
            //   ...
            //
            // "Building/Building.fbx" only contains place holders (empty nodes) that
            // reference the building blocks. The building blocks are referenced by name.
            // Example: A place holder with name "concrete_door_001" is an instance of
            // "Building/concrete_door.fbx".
            var buildingNode = LoadBuilding("Building/", "Building");

            // Clone the building several times and add it to the scene.
#if XBOX
            const int numberOfColumns = 4;
            const int numberOfRows    = 4;
#else
            const int numberOfColumns = 10;
            const int numberOfRows    = 10;
#endif
            for (int i = 0; i < numberOfColumns; i++)
            {
                for (int j = 0; j < numberOfRows; j++)
                {
                    var clone = buildingNode.Clone();
                    clone.PoseWorld = new Pose(new Vector3F((i - numberOfColumns / 2) * 20, 0, (j - numberOfRows / 2) * 20));
                    _graphicsScreen.Scene.Children.Add(clone);
                }
            }

            // For debug visualization:
            // Selects the object that is visualized with <B>, <N>, <M>.
            _graphicsScreen.DebugObject = _graphicsScreen.Scene.GetSceneNode("pillar_concrete_3");

            _stringBuilder = new StringBuilder();
        }
Esempio n. 2
0
    public OcclusionCullingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Occlusion culling is implemented in the OcclusionCullingScreen.
      _graphicsScreen = new OcclusionCullingScreen(Services);
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      Services.Register(typeof(DebugRenderer), null, _graphicsScreen.DebugRenderer);
      Services.Register(typeof(IScene), null, _graphicsScreen.Scene);

      // Add a custom game object which controls the camera.
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      // Load environment.
      GameObjectService.Objects.Add(new StaticSkyObject(Services)); // (includes light nodes)
      GameObjectService.Objects.Add(new StaticObject(Services, "Gravel/Gravel", 1, new Pose(new Vector3F(0, 0, 0))));

      // Set main directional light to enable shadow caster culling.
      _graphicsScreen.LightNode = ((LightNode)_graphicsScreen.Scene.GetSceneNode("Sunlight"));

      // To disable shadow maps and shadow caster culling:
      //((LightNode)_graphicsScreen.Scene.GetSceneNode("Sunlight")).Shadow = null;
      // _graphicsScreen.LightNode = null;
      
      // ----- Load building:
      // The model "Building/Building.fbx" represent a building that is assembled
      // from modular building blocks:
      //   "Building/concrete_door.fbx"
      //   "Building/concrete_double_window.fbx"
      //   "Building/concrete_small_double_window.fbx"
      //   "Building/wall_concrete_1.fbx"
      //   "Building/pillar_concrete_1.fbx"
      //   ...
      //
      // "Building/Building.fbx" only contains place holders (empty nodes) that
      // reference the building blocks. The building blocks are referenced by name.
      // Example: A place holder with name "concrete_door_001" is an instance of
      // "Building/concrete_door.fbx".
      var buildingNode = LoadBuilding("Building/", "Building");

      // Clone the building several times and add it to the scene.
#if XBOX
      const int numberOfColumns = 4;
      const int numberOfRows = 4;
#else
      const int numberOfColumns = 10;
      const int numberOfRows = 10;
#endif
      for (int i = 0; i < numberOfColumns; i++)
      {
        for (int j = 0; j < numberOfRows; j++)
        {
          var clone = buildingNode.Clone();
          clone.PoseWorld = new Pose(new Vector3F((i - numberOfColumns / 2) * 20, 0, (j - numberOfRows / 2) * 20));
          _graphicsScreen.Scene.Children.Add(clone);
        }
      }

      // For debug visualization:
      // Selects the object that is visualized with <B>, <N>, <M>.
      _graphicsScreen.DebugObject = _graphicsScreen.Scene.GetSceneNode("pillar_concrete_3");

      _stringBuilder = new StringBuilder();
    }