Beispiel #1
0
    public GodRayObject(IServiceLocator services, GodRayFilter godRayFilter)
    {
      if (godRayFilter == null)
        throw new ArgumentNullException("godRayFilter");

      Name = "GodRay";
      _services = services;
      _godRayFilter = godRayFilter;
      _defaultScale = godRayFilter.Scale;
    }
Beispiel #2
0
    public GodRaySample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      _godRayFilter = new GodRayFilter(GraphicsService);
      GraphicsScreen.PostProcessors.Add(_godRayFilter);

      // The god ray filter light direction should match the direction of the sun light,
      // which was added by the StaticSkyObject.
      var lightNode = GraphicsScreen.Scene.GetSceneNode("Sunlight");
      _godRayFilter.LightDirection = lightNode.PoseWorld.ToWorldDirection(Vector3F.Forward);
    }
Beispiel #3
0
    public DeferredLightingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new DeferredGraphicsScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      // Add a game object which adds some GUI controls for the deferred graphics 
      // screen to the Options window.
      GameObjectService.Objects.Add(new DeferredGraphicsOptionsObject(Services));

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

      // Add gravity and damping to the physics simulation.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

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

      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new StaticSkyObject(Services)); // Skybox + some lights.
      GameObjectService.Objects.Add(new GroundObject(Services));

      // Add a god ray post-process filter and a game object which updates the god ray directions.
      var godRayFilter = new GodRayFilter(GraphicsService)
      {
        Intensity = new Vector3F(1.0f),
        NumberOfSamples = 12,
        NumberOfPasses = 2,
        Softness = 1,
      };
      _graphicsScreen.PostProcessors.Add(godRayFilter);
      GameObjectService.Objects.Add(new GodRayObject(Services, godRayFilter));

      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new DynamicObject(Services, 1));
      GameObjectService.Objects.Add(new DynamicObject(Services, 2));
      GameObjectService.Objects.Add(new DynamicObject(Services, 3));
      GameObjectService.Objects.Add(new DynamicObject(Services, 4));
      GameObjectService.Objects.Add(new DynamicObject(Services, 5));
      GameObjectService.Objects.Add(new DynamicObject(Services, 6));
      GameObjectService.Objects.Add(new DynamicObject(Services, 7));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new CampfireObject(Services));

      // The LavaBalls class controls all lava ball instances.
      var lavaBalls = new LavaBallsObject(Services);
      GameObjectService.Objects.Add(lavaBalls);

      // Create a lava ball instance.
      lavaBalls.Spawn();

      // Add a few palm trees.
      Random random = new Random(12345);
      for (int i = 0; i < 10; i++)
      {
        Vector3F position = new Vector3F(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
        Matrix33F orientation = Matrix33F.CreateRotationY(random.NextFloat(0, ConstantsF.TwoPi));
        float scale = random.NextFloat(0.5f, 1.2f);
        GameObjectService.Objects.Add(new StaticObject(Services, "PalmTree/palm_tree", scale, new Pose(position, orientation)));
      }
    }