Пример #1
0
        public LodBlendingSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _graphicsScreen             = new FourWaySplitScreen(Services);
            _graphicsScreen.DrawReticle = false;
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            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 GroundObject(Services));
            GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
            GameObjectService.Objects.Add(new FogObject(Services));
            GameObjectService.Objects.Add(new StaticSkyObject(Services));
            GameObjectService.Objects.Add(new OptionsObject(Services));

            // Add a few LOD test objects.
            for (int i = 0; i < 10; i++)
            {
                GameObjectService.Objects.Add(new LodTestObject(Services));
            }
        }
Пример #2
0
        public XnaModelSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Load XNA model.
            _model = ContentManager.Load <Model>("Saucer3/saucer");

            // Enable default lighting.
            var basicEffects = _model.Meshes
                               .SelectMany(m => m.MeshParts)
                               .Select(mp => mp.Effect)
                               .OfType <BasicEffect>();

            foreach (var effect in basicEffects)
            {
                effect.EnableDefaultLighting();
            }
        }
Пример #3
0
        public async Task SaveObjectAsync(CameraObject @object, Guid deviceKey)
        {
            var objects    = new List <Object>();
            var deviceId   = (await _device.GetAsync(deviceKey)) !.DeviceId;
            var personKeys = @object.Data.Keys.Select(Guid.Parse).ToList();

            var persons = await _dbContext.Person
                          .Include(x => x.Group).ThenInclude(x => x.GroupShift)
                          .Where(x => personKeys.Contains(x.Key) && x.IsActive).ToListAsync();

            Log.Information("Group date {date}", @object.Date);

            foreach (var(key, model) in @object.Data)
            {
                Log.Information("Saving Object {objectId}, with count {count}", key, model.PersonCount);
                var dbObject = new Object
                {
                    CreateDate  = DateTime.Now,
                    DeviceId    = deviceId,
                    ChannelId   = @object.CameraId,
                    PersonKey   = Guid.Parse(key),
                    FrameDate   = DateTime.Parse(@object.Date),
                    Frame       = await SaveImageAsync(model),
                    PersonCount = model.PersonCount
                };

                //FillGroupEntry(persons, dbObject);

                objects.Add(dbObject);
            }

            await _dbContext.Object.AddRangeAsync(objects);

            await _dbContext.SaveChangesAsync();
        }
Пример #4
0
 public void Create()
 {
     Screen.orientation = ScreenOrientation.Landscape;
     _playPauseListener = playing =>
     {
         CameraObject.Playing = playing;
     };
     _resetAllListener = () =>
     {
         CameraObject.Playing = false;
         CameraObject.SetPlayPos(0.0);
     };
     CameraObject = MmdCameraObject.CreateGameObject().GetComponent <MmdCameraObject>();
     CameraObject.transform.localPosition = new Vector3(0, 18, -40);
     CameraObject.transform.localRotation = Quaternion.identity;
     MainSceneController.Instance.SwitchPlayPause(false);
     MainSceneController.Instance.OnPlayPause.AddListener(_playPauseListener);
     MainSceneController.Instance.ResetAll();
     MainSceneController.Instance.OnResetAll.AddListener(_resetAllListener);
     try
     {
         CameraObject.LoadCameraMotion(MainSceneController.Instance.CameraFilePath);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Пример #5
0
    public LodBlendingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new FourWaySplitScreen(Services);
      _graphicsScreen.DrawReticle = false;
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      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 GroundObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new StaticSkyObject(Services));

      // Add a few LOD test objects.
      for (int i = 0; i < 10; i++)
        GameObjectService.Objects.Add(new LodTestObject(Services));
    }
Пример #6
0
    public AvatarRagdollSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // This sample uses for a DebugRenderer for the rendering rigid bodies.
      _debugRenderer = new DebugRenderer(GraphicsService, SpriteFont);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Add some objects which allow the user to interact with the rigid bodies.
      _grabObject = new GrabObject(Services);
      _ballShooterObject = new BallShooterObject(Services) { Speed = 20 };
      GameObjectService.Objects.Add(_grabObject);
      GameObjectService.Objects.Add(_ballShooterObject);

      // Add some default force effects.
      Simulation.ForceEffects.Add(new Gravity());
      Simulation.ForceEffects.Add(new Damping());

      // Add a ground plane in the simulation.
      Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
      {
        MotionType = MotionType.Static
      });

      // Create a random avatar.
      _avatarDescription = AvatarDescription.CreateRandom();
      _avatarRenderer = new AvatarRenderer(_avatarDescription);
    }
Пример #7
0
    public SubmeshSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      var graphicsDevice = GraphicsService.GraphicsDevice;

      // The MeshHelper class can create submeshes for several basic shapes:
      _sphere = MeshHelper.CreateUVSphere(graphicsDevice, 20);
      _torus = MeshHelper.CreateTorus(graphicsDevice, 0.5f, 0.667f, 16);
      _teapot = MeshHelper.CreateTeapot(graphicsDevice, 1, 8);

      // MeshHelper.CreateBox() returns a new submesh for a box. Instead we can call
      // MeshHelper.GetBox(), which returns a shared submesh. - GetBox() will always 
      // return the same instance.
      _box = MeshHelper.GetBox(GraphicsService);

      // We can also create a submesh that uses line primitives.
      _cone = MeshHelper.GetConeLines(GraphicsService);

      // We use a normal XNA BasicEffect to render the submeshes.
      _effect = new BasicEffect(graphicsDevice) { PreferPerPixelLighting = true };
      _effect.EnableDefaultLighting();
    }
Пример #8
0
        protected override void SelectionMoved(Selection sel)
        {
            if (sel.Drawable is CameraObject)
            {
                if (CameraDragged != null)
                {
                    CameraObject co = sel.Drawable as CameraObject;
                    // Adjust offset
                    co.MediaFile.Offset = new Time(-co.TimeNode.Start.MSeconds);
                    // And notify
                    CameraDragged(co.MediaFile, co.TimeNode);
                }
            }
            else
            {
                if (TimeNodeChanged != null)
                {
                    Time     moveTime;
                    TimeNode tn = (sel.Drawable as TimeNodeObject).TimeNode;

                    if (sel.Position == SelectionPosition.Right)
                    {
                        moveTime = tn.Stop;
                    }
                    else
                    {
                        moveTime = tn.Start;
                    }
                    TimeNodeChanged(tn, moveTime);
                }
            }
        }
Пример #9
0
        void HandleSelectedCameraChanged(object sender, EventArgs args)
        {
            CameraObject camera = camerasTimeline.SelectedCamera;

            if (camera != null)
            {
                // Check if we need to reopen the player
                if (!sec_cam_playerbin.Player.Opened ||
                    sec_cam_playerbin.Player.FileSet.FirstOrDefault() != camera.MediaFile)
                {
                    MediaFileSet fileSet = new MediaFileSet();
                    fileSet.Add(camera.MediaFile);

                    sec_cam_playerbin.Player.Open(fileSet);

                    // Configure audio
                    HandleAudioToggled(sec_cam_audio_button, new EventArgs());
                }
                // And update
                HandleCameraUpdate(camera);
            }
            else
            {
                // When no camera is selected show the initial didactic message.
                ShowDidactic(DidacticMessage.Initial);
            }
        }
Пример #10
0
        public SubmeshSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };
            GraphicsService.Screens.Insert(0, _delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            var graphicsDevice = GraphicsService.GraphicsDevice;

            // The MeshHelper class can create submeshes for several basic shapes:
            _sphere = MeshHelper.CreateUVSphere(graphicsDevice, 20);
            _torus  = MeshHelper.CreateTorus(graphicsDevice, 0.5f, 0.667f, 16);
            _teapot = MeshHelper.CreateTeapot(graphicsDevice, 1, 8);

            // MeshHelper.CreateBox() returns a new submesh for a box. Instead we can call
            // MeshHelper.GetBox(), which returns a shared submesh. - GetBox() will always
            // return the same instance.
            _box = MeshHelper.GetBox(GraphicsService);

            // We can also create a submesh that uses line primitives.
            _cone = MeshHelper.GetConeLines(GraphicsService);

            // We use a normal XNA BasicEffect to render the submeshes.
            _effect = new BasicEffect(graphicsDevice)
            {
                PreferPerPixelLighting = true
            };
            _effect.EnableDefaultLighting();
        }
Пример #11
0
        /// <summary>
        /// Handles the tick from media player to update Current Time in timelines.
        /// </summary>
        /// <param name="currentTime">Current time.</param>
        void HandleTick(Time currentTime, Time duration, bool seekable)
        {
            timerule.CurrentTime        = currentTime;
            camerasTimeline.CurrentTime = currentTime;

            CameraObject camera = camerasTimeline.SelectedCamera;

            // Detect when secondary camera goes in and out of scope while main camera is playing.
            if (camera != null)
            {
                if (IsInScope(camera))
                {
                    if (ShowSecondaryPlayer())
                    {
                        // If the player was shown, resync.
                        SyncSecondaryPlayer();
                    }
                }
                else
                {
                    ShowDidactic(DidacticMessage.CameraOutOfScope);
                }
            }
            QueueDraw();
        }
Пример #12
0
    public CascadedShadowSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      _graphicsScreen = new DeferredGraphicsScreen(Services)
      {
        // For debugging: Disable materials and only show light buffer.
        DebugMode = DeferredGraphicsDebugMode.VisualizeDiffuseLightBuffer
      };
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      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));

      ShadowSample.CreateScene(Services, ContentManager, _graphicsScreen);

      // Get the cascaded shadow of the sunlight (which was created by the DynamicSkyObject).
      _cascadedShadow = (CascadedShadow)((LightNode)_graphicsScreen.Scene.GetSceneNode("Sunlight")).Shadow;

      CreateGuiControls();
    }
Пример #13
0
        public ManualMeshRenderSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            _scene = new Scene();
            SceneSample.InitializeDefaultXnaLights(_scene);

            // For advanced users: Set this flag if you want to analyze the imported opaque data of
            // effect bindings.
            EffectBinding.KeepOpaqueData = true;

            _model = ContentManager.Load <ModelNode>("Dude/Dude").Clone();
            var meshNode = _model.GetSubtree().OfType <MeshNode>().First();

            meshNode.ScaleLocal = new Vector3(1, 2, 1);
            var mesh     = meshNode.Mesh;
            var timeline = new TimelineClip(mesh.Animations.Values.First())
            {
                Duration     = TimeSpan.MaxValue,
                LoopBehavior = LoopBehavior.Cycle,
            };

            AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
        }
Пример #14
0
    public FigurePickerObject(IGraphicsService graphicsService, Scene scene, CameraObject cameraObject, DebugRenderer debugRenderer)
    {
      _cameraObject = cameraObject;
      _scene = scene;
      _debugRenderer = debugRenderer;

      // Create a collision domain which manages all collision objects used for
      // picking: the picking object and the collision objects for figure nodes.
      _collisionDomain = new CollisionDomain(new CollisionDetection());

      // Create the picking object:
      // The picking object represents the mouse cursor or the reticle. Usually 
      // a ray is used, but in this example we want to use a cylinder/cone. This 
      // allows to check which objects within a certain radius of the reticle. A 
      // picking cylinder/cone is helpful for touch devices where the picking is 
      // done with an imprecise input method like the human finger.

      // We want to pick objects in 10 pixel radius around the reticle. To determine 
      // the world space size of the required cylinder/cone, we can use the projection
      // and the viewport. 
      const float pickingRadius = 10;
      var projection = _cameraObject.CameraNode.Camera.Projection;
      var viewport = graphicsService.GraphicsDevice.Viewport;

      Shape pickingShape;
      if (projection is OrthographicProjection)
      {
        // Use cylinder for orthographic projections:
        // The cylinder is centered at the camera position and reaches from the 
        // camera position to the camera far plane. A TransformedShape is used
        // to rotate and translate the cylinder.
        float radius = projection.Width / viewport.Width * pickingRadius;
        pickingShape = new TransformedShape(
          new GeometricObject(
            new CylinderShape(radius, projection.Far),
            new Pose(new Vector3F(0, 0, -projection.Far / 2), Matrix33F.CreateRotationX(ConstantsF.PiOver2))));
      }
      else
      {
        // Use cone for perspective projections:
        // The cone tip is at the camera position and the cone base is at the 
        // camera far plane. 

        // Compute the radius at the far plane that projects to 10 pixels in screen space.
        float radius = viewport.Unproject(
          new Vector3(viewport.Width / 2.0f + pickingRadius, viewport.Height / 2.0f, 1),
          (Matrix)_cameraObject.CameraNode.Camera.Projection.ToMatrix44F(),
          Matrix.Identity,
          Matrix.Identity).X;

        // A transformed shape is used to rotate and translate the cone.
        pickingShape = new TransformedShape(
          new GeometricObject(
            new ConeShape(radius, projection.Far),
            new Pose(new Vector3F(0, 0, -projection.Far), Matrix33F.CreateRotationX(ConstantsF.PiOver2))));
      }

      // Create collision object with the picking shape.
      _pickingObject = new CollisionObject(new GeometricObject(pickingShape, _cameraObject.CameraNode.PoseWorld));
    }
Пример #15
0
        public static CameraObject Alloc()
        {
            global::System.IntPtr cPtr = C4dApiPINVOKE.CameraObject_Alloc();
            CameraObject          ret  = (cPtr == global::System.IntPtr.Zero) ? null : new CameraObject(cPtr, false);

            return(ret);
        }
Пример #16
0
        public async Task <IEnumerable <string> > Get(long id)
        {
            // Note that even this GET creates an Actor based on the id
            // passed in because of the OnActivateAsync() method. The
            // OnActivateAsync() method gets triggered the first time
            // any of the Actor methods are invoked. In this case, the
            // GetCameraAsync() method is called below. This means the
            // OnActivateSync() method gets triggered, which creates
            // the actor before the execution of GetCameraAsync.
            // This is something you need to watch out for.
            CameraObject        camera      = null;
            ActorId             actorId     = new ActorId(id);
            IBackEndCameraActor cameraActor = ActorProxy.Create <IBackEndCameraActor>(actorId, backEndCameraActorServiceUri);

            try
            {
                camera = await cameraActor.GetCameraAsync();

                System.Diagnostics.Trace.WriteLine("Getting Camera {0}.", actorId.ToString());
            }
            catch (Exception exc)
            {
                System.Diagnostics.Trace.WriteLine(String.Format("Error: {0}", exc.Message));
            }

            //return new string[] { JsonConvert.SerializeObject(camera) };
            return(new string[] { camera.Location });
        }
Пример #17
0
    public ManualMeshRenderSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      _scene = new Scene();
      SceneSample.InitializeDefaultXnaLights(_scene);

      // For advanced users: Set this flag if you want to analyze the imported opaque data of
      // effect bindings.
      EffectBinding.KeepOpaqueData = true;

      _model = ContentManager.Load<ModelNode>("Dude/Dude").Clone();
      var meshNode = _model.GetSubtree().OfType<MeshNode>().First();
      meshNode.ScaleLocal = new Vector3F(1, 2, 1);
      var mesh = meshNode.Mesh;
      var timeline = new TimelineClip(mesh.Animations.Values.First())
      {
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Cycle,
      };
      AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
    }
Пример #18
0
    public LightSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new DeferredGraphicsScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      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));
      GameObjectService.Objects.Add(new GroundObject(Services));

      // Disable the main lights (of the StaticSkyObject) and add some test lights instead.
      _graphicsScreen.Scene.GetSceneNode("Sunlight").IsEnabled = false;
      _graphicsScreen.Scene.GetSceneNode("Ambient").IsEnabled = false;
      GameObjectService.Objects.Add(new TestLightsObject(Services));

      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
    }
Пример #19
0
    public XnaModelSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      // Load XNA model.
      _model = ContentManager.Load<Model>("Saucer3/saucer");

      // Enable default lighting.
      var basicEffects = _model.Meshes
                               .SelectMany(m => m.MeshParts)
                               .Select(mp => mp.Effect)
                               .OfType<BasicEffect>();
      foreach (var effect in basicEffects)
        effect.EnableDefaultLighting();
    }
Пример #20
0
        public AvatarRagdollSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // This sample uses for a DebugRenderer for the rendering rigid bodies.
            _debugRenderer = new DebugRenderer(GraphicsService, SpriteFont);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
            GameObjectService.Objects.Add(_cameraObject);

            // Add some objects which allow the user to interact with the rigid bodies.
            _grabObject        = new GrabObject(Services);
            _ballShooterObject = new BallShooterObject(Services)
            {
                Speed = 20
            };
            GameObjectService.Objects.Add(_grabObject);
            GameObjectService.Objects.Add(_ballShooterObject);

            // Add some default force effects.
            Simulation.ForceEffects.Add(new Gravity());
            Simulation.ForceEffects.Add(new Damping());

            // Add a ground plane in the simulation.
            Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
            {
                MotionType = MotionType.Static
            });

            // Create a random avatar.
            _avatarDescription = AvatarDescription.CreateRandom();
            _avatarRenderer    = new AvatarRenderer(_avatarDescription);
        }
Пример #21
0
        public LightSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            _graphicsScreen             = new DeferredGraphicsScreen(Services);
            _graphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            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));
            GameObjectService.Objects.Add(new GroundObject(Services));

            // Disable the main lights (of the StaticSkyObject) and add some test lights instead.
            _graphicsScreen.Scene.GetSceneNode("Sunlight").IsEnabled = false;
            _graphicsScreen.Scene.GetSceneNode("Ambient").IsEnabled  = false;
            GameObjectService.Objects.Add(new TestLightsObject(Services));

            GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
            GameObjectService.Objects.Add(new LavaBallsObject(Services));
            GameObjectService.Objects.Add(new FogObject(Services));

            GameObjectService.Objects.Add(new OptionsObject(Services));
        }
Пример #22
0
    public ProxyNodeSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      _renderer = new MeshRenderer();

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      _scene = new Scene();
      SceneSample.InitializeDefaultXnaLights(_scene);

      // For advanced users: Set this flag if you want to analyze the imported opaque data of
      // effect bindings.
      EffectBinding.KeepOpaqueData = true;

      // Original model in scene graph.
      var modelNode = ContentManager.Load<ModelNode>("Dude/Dude").Clone();
      modelNode.PoseLocal = new Pose(new Vector3F(-2, 0, 0));
      var meshNode = modelNode.GetSubtree().OfType<MeshNode>().First();
      _scene.Children.Add(modelNode);

      // Clone referenced by proxy node.
      var modelNode2 = modelNode.Clone();
      var meshNode2 = modelNode2.GetSubtree().OfType<MeshNode>().First();
      meshNode2.SkeletonPose = meshNode.SkeletonPose;
      _proxyNode = new ProxyNode(null)
      {
        Name = "Proxy",
        PoseLocal = new Pose(new Vector3F(2, 0, 0), Matrix33F.CreateRotationY(ConstantsF.Pi)),
        ScaleLocal = new Vector3F(0.5f),
      };
      _scene.Children.Add(_proxyNode);
      _proxyNode.Node = modelNode2;

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

      var mesh = meshNode.Mesh;
      foreach (var m in mesh.Materials)
      {
        //((ConstParameterBinding<Vector3>)m["Default"].ParameterBindings["SpecularColor"]).Value = new Vector3();
        ((SkinnedEffectBinding)m["Default"]).PreferPerPixelLighting = true;
      }

      var timeline = new TimelineClip(mesh.Animations.Values.First())
      {
        Duration = TimeSpan.MaxValue,
        LoopBehavior = LoopBehavior.Cycle,
      };
      AnimationService.StartAnimation(timeline, (IAnimatableProperty)meshNode.SkeletonPose);
    }
Пример #23
0
 public GameStateManager(GraphicsDevice graphicsDevice, Game game)
     : base(game)
 {
     this.graphicsDevice = graphicsDevice;
     camera       = new CameraObject(graphicsDevice);
     enemySpawner = new EnemySpawner(camera.camera1, graphicsDevice);
     new Bullets(enemySpawner, camera, graphicsDevice);
 }
Пример #24
0
        public void CameraPositionIsEqualWithBindedActor()
        {
            PlayerActor  player = new PlayerActor(new Vector2(200, 100), new Vector2(32, 32));
            CameraObject CO     = new CameraObject(player);

            Assert.AreEqual(200, CO.CameraX);
            Assert.AreEqual(100, CO.CameraY);
        }
Пример #25
0
        public void CameraSetPosition()
        {
            CameraObject CO = new CameraObject();

            CO.CameraX = 15;
            CO.CameraY = 200;
            Assert.AreEqual(15, CO.CameraX);
            Assert.AreEqual(200, CO.CameraY);
        }
Пример #26
0
    public ProjectedShadowSample(Microsoft.Xna.Framework.Game game)
    : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Create a new empty scene.
      _scene = new Scene();
      Services.Register(typeof(IScene), null, _scene);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(-8, 6, 8), -ConstantsF.PiOver4, -0.4f);
      GameObjectService.Objects.Add(_cameraObject);

      // Add a default light setup (ambient light + 3 directional lights).
      var defaultLightsObject = new DefaultLightsObject(Services);
      GameObjectService.Objects.Add(defaultLightsObject);

      // Get the main directional light.
      _mainDirectionalLightNode = ((LightNode)_scene.GetSceneNode("KeyLight"));

      // Add a ground plane model to the scene graph.
      var grid = ContentManager.Load<ModelNode>("Ground/Ground").Clone();
      grid.ScaleLocal = new Vector3F(0.3f);
      _scene.Children.Add(grid);

      // Add a tank model to the scene graph.
      var tank = ContentManager.Load<ModelNode>("Tank/tank").Clone();
      _scene.Children.Add(tank);

      // Remember the mesh nodes of tank node.
      _tankMeshNodes = tank.GetSubtree().Where(n => n is MeshNode).ToArray();

      // Create the renderers.
      _meshRenderer = new MeshRenderer();

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

      _projectedShadowRenderer = new ProjectedShadowRenderer(GraphicsService)
      {
        // The plane onto which the shadows are projected. It is positioned a bit above the ground
        // plane to avoid z-fighting.
        ShadowedPlane = new Plane(new Vector3F(0, 1, 0), 0.01f),

        // The shadow color is a transparent black.
        ShadowColor = new Vector4F(0, 0, 0, 0.4f),

        // The light position is set in Update().
        //LightPosition = ...
      };
    }
Пример #27
0
        public MyGameComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services)
            : base(game)
        {
            // Get the services that this component needs regularly.
            _services          = services;
            _inputService      = services.GetInstance <IInputService>();
            _simulation        = services.GetInstance <Simulation>();
            _graphicsService   = services.GetInstance <IGraphicsService>();
            _gameObjectService = services.GetInstance <IGameObjectService>();
            _uiService         = services.GetInstance <IUIService>();

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

            // Create the DeferredGraphicsScreen and some 3D objects.
            _deferredGraphicsScreen             = new DeferredGraphicsScreen(services);
            _deferredGraphicsScreen.DrawReticle = true;
            _graphicsService.Screens.Insert(0, _deferredGraphicsScreen);

            // The GameObjects below expect try to retrieve DebugRenderer and Scene via
            // service container.
            var serviceContainer = (ServiceContainer)services;

            serviceContainer.Register(typeof(DebugRenderer), null, _deferredGraphicsScreen.DebugRenderer);
            serviceContainer.Register(typeof(IScene), null, _deferredGraphicsScreen.Scene);

            _cameraGameObject = new CameraObject(services);
            _gameObjectService.Objects.Add(_cameraGameObject);
            _deferredGraphicsScreen.ActiveCameraNode = _cameraGameObject.CameraNode;
            _gameObjectService.Objects.Add(new GrabObject(services));
            _gameObjectService.Objects.Add(new StaticSkyObject(services));
            _gameObjectService.Objects.Add(new GroundObject(services));
            for (int i = 0; i < 10; i++)
            {
                _gameObjectService.Objects.Add(new DynamicObject(services, 1));
            }

            // Get the "SampleUI" screen that was created by the StartScreenComponent.
            _uiScreen = _uiService.Screens["SampleUI"];

            // Add a second GraphicsScreen. This time it is a DelegateGraphicsScreen that
            // draws the UI over DeferredGraphicsScreen.
            _delegateGraphicsScreen = new DelegateGraphicsScreen(_graphicsService)
            {
                RenderCallback = context => _uiScreen.Draw(context.DeltaTime)
            };
            _graphicsService.Screens.Insert(1, _delegateGraphicsScreen);

            // Create the game menu window. But do not display it yet.
            _gameMenuWindow = new GameMenuWindow
            {
                // If the menu is opened and closed a lot, it is more efficient when _gameMenuWindow.Close()
                // makes the window invisible but does not remove it from the screen.
                HideOnClose = true,
            };
        }
Пример #28
0
    public TerrainSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

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

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

      var scene = _graphicsScreen.Scene;
      Services.Register(typeof(IScene), null, 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, 5000);
      cameraGameObject.ResetPose(new Vector3F(0, 2, 5), 0, 0);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      // Add standard game objects.
      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true)
      {
        EnableCloudShadows = false,
        FogSampleAngle = 0.1f,
        FogSaturation = 1,
      });

      var fogObject = new FogObject(Services) { AttachToCamera = true };
      GameObjectService.Objects.Add(fogObject);

      // Set nice fog values.
      // (Note: If we change the fog values here, the GUI in the Options window is not
      // automatically updated.)
      fogObject.FogNode.IsEnabled = true;
      fogObject.FogNode.Fog.Start = 100;
      fogObject.FogNode.Fog.End = 2500;
      fogObject.FogNode.Fog.Start = 100;
      fogObject.FogNode.Fog.HeightFalloff = 0.25f;

      // Add an ocean at height 0.
      GameObjectService.Objects.Add(new OceanObject(Services));

      // Add the terrain.
      var terrainObject = new TerrainObject(Services);
      GameObjectService.Objects.Add(terrainObject);

      SampleFramework.ShowOptionsWindow();
    }
Пример #29
0
        public SplitScreenSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;

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

            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 of player A.
            var cameraGameObject = new CameraObject(Services);

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

            var projection = (PerspectiveProjection)cameraGameObject.CameraNode.Camera.Projection;

            projection.SetFieldOfView(
                projection.FieldOfViewY,
                GraphicsService.GraphicsDevice.Viewport.AspectRatio / 2,
                projection.Near,
                projection.Far);
            cameraGameObject.CameraNode.Camera = new Camera(projection);

            // A second camera for player B.
            _cameraNodeB = new CameraNode(cameraGameObject.CameraNode.Camera);
            _graphicsScreen.ActiveCameraNodeB = _cameraNodeB;

            GameObjectService.Objects.Add(new GrabObject(Services));
            GameObjectService.Objects.Add(new GroundObject(Services));
            GameObjectService.Objects.Add(new DudeObject(Services));
            GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
            GameObjectService.Objects.Add(new LavaBallsObject(Services));
            GameObjectService.Objects.Add(new FogObject(Services));
            GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3(0, 0, -2))));
            GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3(3, 0, 0), Quaternion.CreateRotationY(MathHelper.ToRadians(-20)))));
            GameObjectService.Objects.Add(new StaticSkyObject(Services));

            // Add a few palm trees.
            Random random = new Random(12345);

            for (int i = 0; i < 10; i++)
            {
                Vector3 position    = new Vector3(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
                Matrix  orientation = Matrix.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)));
            }
        }
Пример #30
0
    public FogSphereSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Create a graphics screen. This screen has to call the FogSphereRenderer
      // to handle the FogSphereNode!
      _graphicsScreen = new DeferredGraphicsScreen(Services) { DrawReticle = true };
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      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;

      // More standard objects.
      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true));
      GameObjectService.Objects.Add(new GroundObject(Services));
      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, 5));
      GameObjectService.Objects.Add(new DynamicObject(Services, 6));
      GameObjectService.Objects.Add(new DynamicObject(Services, 7));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));

      // 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)));
      }

      // ----- Add a FogSphereNode to scene.
      var fogSphereNode = new FogSphereNode
      {
        Name = "FogSphere",
        ScaleLocal = new Vector3F(5, 3, 5),
        PoseWorld = new Pose(new Vector3F(0, 0, -3)),
      };
      _graphicsScreen.Scene.Children.Add(fogSphereNode);
    }
Пример #31
0
        public SkySample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;

            _graphicsScreen             = new DeferredGraphicsScreen(Services);
            _graphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, _graphicsScreen);
            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 GroundObject(Services));
            GameObjectService.Objects.Add(new DudeObject(Services));
            GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
            GameObjectService.Objects.Add(new LavaBallsObject(Services));
            GameObjectService.Objects.Add(new FogObject(Services));
            GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3(0, 0, -2))));
            GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3(3, 0, 0), Quaternion.CreateRotationY(MathHelper.ToRadians(-20)))));

            // The DynamicSkyObject creates the dynamic sky and lights.
            GameObjectService.Objects.Add(new DynamicSkyObject(Services));

            // Add a few palm trees.
            Random random = new Random(12345);

            for (int i = 0; i < 10; i++)
            {
                Vector3 position    = new Vector3(random.NextFloat(-3, -8), 0, random.NextFloat(0, -5));
                Matrix  orientation = Matrix.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)));
            }

            // Add a grain filter to add some noise in the night.
            _graphicsScreen.PostProcessors.Add(new GrainFilter(GraphicsService)
            {
                IsAnimated         = true,
                LuminanceThreshold = 0.3f,
                ScaleWithLuminance = true,
                Strength           = 0.04f,
                GrainScale         = 1.5f,
            });
        }
Пример #32
0
        protected override void SceneInitialization(IContextState context, RenderEngine engine, ElementTag camera)
        {
            var smanager = Context.GetSystemManager();

            smanager.CreateSystem <DefaultInputSystem>();
            smanager.CreateSystem <ZoomToAllObjectsSystem>();
            smanager.CreateSystem <MovingSystem>();
            smanager.CreateSystem <CollidingSystem>();
            smanager.CreateSystem <DefaultOrthographicCameraSystem>();
            smanager.CreateSystem <LightsSystem>();
            //  smanager.CreateSystem<MovementSystem>();
            //  smanager.CreateSystem<EmptyAnimationSystem>();
            //  smanager.CreateSystem<MeshAnimationSystem>();
            //  smanager.CreateSystem<StickOnHeightMapSystem>();
            //     smanager.CreateSystem<ObjectMovementSystem>();
            //    smanager.CreateSystem<Systems.TerrainGeneratorSystem>();
            //   smanager.CreateSystem<Physics.Engine.PhysicalSystem>();

            smanager
            .CreateSystem <RenderSystem>()
            .Init(engine.Graphics)
            // .CreateNested<SkyGradientColoringRenderTechnique>()
            //  .CreateNested<SkyPlaneWithParallaxRenderTechnique>()
            //   .CreateNested<TerrainRenderTechnique>()//
            //.CreateNested<Toolkit.D3D.CameraViews.CameraViewsRenderTechnique<CustomRenderProperties>>()
            //.CreateNested<OITTriangleColoredVertexRenderTechnique<ToolkitRenderProperties>>()
            .CreateNested <TriangleColoredVertexRenderTechnique <ToolkitRenderProperties> >()
            .CreateNested <TriangleTexturedVertexRenderTechnique <ToolkitRenderProperties> >()
            .CreateNested <LineVertexRenderTechnique <ToolkitRenderProperties> >()
            //.CreateNested<CudaTestTechniques<ToolkitRenderProperties>>()
            .CreateNested <SpherePointRenderTechnique <ToolkitRenderProperties> >()
            //.CreateNested<AminRenderTechniqueSystem>()
            ;

            //smanager
            //    .CreateSystem<AminRenderSystem>()
            //    .Init(device);Context
            var manager = Context.GetEntityManager();

            cameraObject = CameraObject.UpdateOrthographic <RenderSystem>(camera, Context, Surface);

            LightObject.CreateAmbientLight(manager, 0.2f);                                           //0.05f
            LightObject.CreateFollowCameraDirectLight(manager, System.Numerics.Vector3.UnitZ, 0.8f); //0.95f

            CoordinateSystem = CoordinateSystemLinesGameObject.Create(context, false);

            Loaded?.Invoke();


            //VisualSphereObject.SphereGeo(Context, ElementTag.New($"Point"), new VisualSphereObject.Data {
            //    Center = new Vector3(10, 20, 10),
            //    Color = V4Colors.Yellow,
            //    Radius = 10
            //});
        }
Пример #33
0
        public void CameraPositionCannotMoveIfBindedToActor()
        {
            PlayerActor  player = new PlayerActor(new Vector2(200, 100), new Vector2(32, 32));
            CameraObject CO     = new CameraObject(player);

            CO.CameraX = 1000;
            CO.CameraY = 0;

            Assert.AreEqual(200, CO.CameraX);
            Assert.AreEqual(100, CO.CameraY);
        }
Пример #34
0
    public MyGameComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services)
      : base(game)
    {
      // Get the services that this component needs regularly.
      _services = services;
      _inputService = services.GetInstance<IInputService>();
      _simulation = services.GetInstance<Simulation>();
      _graphicsService = services.GetInstance<IGraphicsService>();
      _gameObjectService = services.GetInstance<IGameObjectService>();
      _uiService = services.GetInstance<IUIService>();

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

      // Create the DeferredGraphicsScreen and some 3D objects.
      _deferredGraphicsScreen = new DeferredGraphicsScreen(services);
      _deferredGraphicsScreen.DrawReticle = true;
      _graphicsService.Screens.Insert(0, _deferredGraphicsScreen);

      // The GameObjects below expect try to retrieve DebugRenderer and Scene via
      // service container.
      var serviceContainer = (ServiceContainer)services;
      serviceContainer.Register(typeof(DebugRenderer), null, _deferredGraphicsScreen.DebugRenderer);
      serviceContainer.Register(typeof(IScene), null, _deferredGraphicsScreen.Scene);

      _cameraGameObject = new CameraObject(services);
      _gameObjectService.Objects.Add(_cameraGameObject);
      _deferredGraphicsScreen.ActiveCameraNode = _cameraGameObject.CameraNode;
      _gameObjectService.Objects.Add(new GrabObject(services));
      _gameObjectService.Objects.Add(new StaticSkyObject(services));
      _gameObjectService.Objects.Add(new GroundObject(services));
      for (int i = 0; i < 10; i++)
        _gameObjectService.Objects.Add(new DynamicObject(services, 1));

      // Get the "SampleUI" screen that was created by the StartScreenComponent.
      _uiScreen = _uiService.Screens["SampleUI"];

      // Add a second GraphicsScreen. This time it is a DelegateGraphicsScreen that
      // draws the UI over DeferredGraphicsScreen.
      _delegateGraphicsScreen = new DelegateGraphicsScreen(_graphicsService)
      {
        RenderCallback = context => _uiScreen.Draw(context.DeltaTime)
      };
      _graphicsService.Screens.Insert(1, _delegateGraphicsScreen);

      // Create the game menu window. But do not display it yet.
      _gameMenuWindow = new GameMenuWindow
      {
        // If the menu is opened and closed a lot, it is more efficient when _gameMenuWindow.Close()
        // makes the window invisible but does not remove it from the screen.
        HideOnClose = true,
      };
    }
Пример #35
0
    public SkySample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new DeferredGraphicsScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      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 GroundObject(Services));
      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3F(0, 0, -2))));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3F(3, 0, 0), QuaternionF.CreateRotationY(MathHelper.ToRadians(-20)))));

      // The DynamicSkyObject creates the dynamic sky and lights.
      GameObjectService.Objects.Add(new DynamicSkyObject(Services));

      // 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)));
      }

      // Add a grain filter to add some noise in the night.
      _graphicsScreen.PostProcessors.Add(new GrainFilter(GraphicsService)
      {
        IsAnimated = true,
        LuminanceThreshold = 0.3f,
        ScaleWithLuminance = true,
        Strength = 0.04f,
        GrainScale = 1.5f,
      });
    }
Пример #36
0
        public PostProcessingSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;

            // Add a PostProcessingGraphicsScreen. This graphics screen has a Scene and does
            // the rendering including post-processing. Please look at PostProcessingGraphicsScreen
            // for more details.
            GraphicsScreen             = new PostProcessingGraphicsScreen(Services);
            GraphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, GraphicsScreen);

            // GameObjects that need to render stuff will retrieve the DebugRenderers or
            // Scene through the service provider.
            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, 100);

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

            GameObjectService.Objects.Add(new GrabObject(Services));
            GameObjectService.Objects.Add(new StaticSkyObject(Services)
            {
                SkyExposure = 1
            });
            GameObjectService.Objects.Add(new GroundObject(Services));

            for (int i = 0; i < 20; i++)
            {
                GameObjectService.Objects.Add(new DynamicObject(Services, 2));
            }

            for (int i = 0; i < 10; i++)
            {
                var randomPosition = new Vector3(
                    RandomHelper.Random.NextFloat(-5, 5),
                    0,
                    RandomHelper.Random.NextFloat(-10, 0));
                var randomOrientation = Quaternion.CreateRotationY(RandomHelper.Random.NextFloat(0, ConstantsF.TwoPi));

                GameObjectService.Objects.Add(new DudeObject(Services)
                {
                    Pose = new Pose(randomPosition, randomOrientation)
                });
            }
        }
Пример #37
0
        void UpdateLabels()
        {
            CameraObject camera = camerasTimeline.SelectedCamera;

            if (camera != null)
            {
                sec_cam_label.Markup = String.Format(
                    "<b>{0}</b> - <span foreground=\"{1}\" size=\"smaller\">{2}: {3}</span>",
                    camera.MediaFile.Name, Config.Style.PaletteActive.ToRGBString(false),
                    Catalog.GetString("Offset"), camera.MediaFile.Offset.ToMSecondsString());
            }
        }
Пример #38
0
    public SplitScreenSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

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

      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 of player A.
      var cameraGameObject = new CameraObject(Services);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      var projection = (PerspectiveProjection)cameraGameObject.CameraNode.Camera.Projection;
      projection.SetFieldOfView(
        projection.FieldOfViewY,
        GraphicsService.GraphicsDevice.Viewport.AspectRatio / 2,
        projection.Near,
        projection.Far);
      cameraGameObject.CameraNode.Camera = new Camera(projection);

      // A second camera for player B.
      _cameraNodeB = new CameraNode(cameraGameObject.CameraNode.Camera);
      _graphicsScreen.ActiveCameraNodeB = _cameraNodeB;

      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new GroundObject(Services));
      GameObjectService.Objects.Add(new DudeObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));
      GameObjectService.Objects.Add(new FogObject(Services));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Barrier", 0.9f, new Pose(new Vector3F(0, 0, -2))));
      GameObjectService.Objects.Add(new StaticObject(Services, "Barrier/Cylinder", 0.9f, new Pose(new Vector3F(3, 0, 0), QuaternionF.CreateRotationY(MathHelper.ToRadians(-20)))));
      GameObjectService.Objects.Add(new StaticSkyObject(Services));

      // 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)));
      }
    }
Пример #39
0
        public VarianceShadowSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            _graphicsScreen = new DeferredGraphicsScreen(Services)
            {
                // For debugging: Disable materials and only show light buffer.
                DebugMode = DeferredGraphicsDebugMode.VisualizeDiffuseLightBuffer
            };
            _graphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, _graphicsScreen);

            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));

            // Create test scene.
            ShadowSample.CreateScene(Services, ContentManager, _graphicsScreen);

            // Get directional light created by the DynamicSkyObject and replace the default
            // shadow with our custom VSM shadow.
            _lightNode      = _graphicsScreen.Scene.GetDescendants().OfType <LightNode>().First(n => n.Shadow is CascadedShadow);
            _varianceShadow = new VarianceShadow
            {
                // If a target area is set, the VSM covers the given area.
                // If no target area is set, the VSM covers the area in front of the camera.
                TargetArea = new Aabb(new Vector3(-100, 0, -100), new Vector3(100, 50, 100)),
            };
            _lightNode.Shadow = _varianceShadow;

            // Apply a blur filter to the shadow map.
            _varianceShadow.Filter = new Blur(GraphicsService);
            _varianceShadow.Filter.InitializeGaussianBlur(11, 3, false);

            // Register our custom shadow map and shadow mask renderers.
            _graphicsScreen.ShadowMapRenderer.Renderers.Add(new VarianceShadowMapRenderer(_graphicsScreen.ShadowMapRenderer.RenderCallback));
            _graphicsScreen.ShadowMaskRenderer.Renderers.Add(new VarianceShadowMaskRenderer(GraphicsService));

            CreateGuiControls();
        }
Пример #40
0
        public override void ProcessTextureObject(ObjectInformation oi)
        {
            switch (oi.name.ToUpper())
            {
            case "CAMERAOBJECT":
                CameraObject cameraObject = new CameraObject(2000, 2, oi.position, true, oi.name);
                return;
            }

            //If we have come this far we will create a tile with the texture
            Tile t = new Tile(item.getTexture(), item.Position, layer.ScrollSpeed, item.Name, layer.Name);
        }
Пример #41
0
    public VarianceShadowSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      _graphicsScreen = new DeferredGraphicsScreen(Services)
      {
        // For debugging: Disable materials and only show light buffer.
        DebugMode = DeferredGraphicsDebugMode.VisualizeDiffuseLightBuffer
      };
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      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));

      // Create test scene.
      ShadowSample.CreateScene(Services, ContentManager, _graphicsScreen);

      // Get directional light created by the DynamicSkyObject and replace the default 
      // shadow with our custom VSM shadow.
      _lightNode = _graphicsScreen.Scene.GetDescendants().OfType<LightNode>().First(n => n.Shadow is CascadedShadow);
      _varianceShadow = new VarianceShadow
      {
        // If a target area is set, the VSM covers the given area.
        // If no target area is set, the VSM covers the area in front of the camera.
        TargetArea = new Aabb(new Vector3F(-100, 0, -100), new Vector3F(100, 50, 100)),
      };
      _lightNode.Shadow = _varianceShadow;

      // Apply a blur filter to the shadow map.
      _varianceShadow.Filter = new Blur(GraphicsService);
      _varianceShadow.Filter.InitializeGaussianBlur(11, 3, false);

      // Register our custom shadow map and shadow mask renderers.
      _graphicsScreen.ShadowMapRenderer.Renderers.Add(new VarianceShadowMapRenderer(_graphicsScreen.ShadowMapRenderer.RenderCallback));
      _graphicsScreen.ShadowMaskRenderer.Renderers.Add(new VarianceShadowMaskRenderer(GraphicsService));

      CreateGuiControls();
    }
Пример #42
0
        public void BindedCameraUnbindAndMove()
        {
            PlayerActor  player = new PlayerActor(new Vector2(200, 100), new Vector2(32, 32));
            CameraObject CO     = new CameraObject(player);

            CO.UnbindActor();

            CO.CameraX = 10;
            CO.CameraY = 20;

            Assert.AreEqual(10, CO.CameraX);
            Assert.AreEqual(20, CO.CameraY);
        }
Пример #43
0
        public void FreeCameraDynamicBind()
        {
            PlayerActor  player = new PlayerActor(new Vector2(200, 100), new Vector2(32, 32));
            CameraObject CO     = new CameraObject();

            CO.CameraX = 2;
            CO.CameraY = 4;

            CO.BindActor(player);

            Assert.AreEqual(200, CO.CameraX);
            Assert.AreEqual(100, CO.CameraY);
        }
Пример #44
0
        public VolumetricCloudSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;

            _graphicsScreen             = new DeferredGraphicsScreen(Services);
            _graphicsScreen.DrawReticle = true;
            GraphicsService.Screens.Insert(0, _graphicsScreen);
            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));
            _dynamicSkyObject = new DynamicSkyObject(Services, false, false, true);
            GameObjectService.Objects.Add(_dynamicSkyObject);
            GameObjectService.Objects.Add(new GroundObject(Services));
            GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
            GameObjectService.Objects.Add(new LavaBallsObject(Services));

            _particleCloud0 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
            {
                PoseLocal = new Pose(new Vector3(-0, 100, -400)),
            };
            ParticleSystemService.ParticleSystems.Add(_particleCloud0.ParticleSystem);
            _graphicsScreen.Scene.Children.Add(_particleCloud0);

            _particleCloud1 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
            {
                PoseLocal = new Pose(new Vector3(-200, 100, -200)),
            };
            ParticleSystemService.ParticleSystems.Add(_particleCloud1.ParticleSystem);
            _graphicsScreen.Scene.Children.Add(_particleCloud1);

            _particleCloud2 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
            {
                PoseLocal = new Pose(new Vector3(400, 400, -400)),
            };
            ParticleSystemService.ParticleSystems.Add(_particleCloud2.ParticleSystem);
            _graphicsScreen.Scene.Children.Add(_particleCloud2);
        }
Пример #45
0
    public VolumetricCloudSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      _graphicsScreen = new DeferredGraphicsScreen(Services);
      _graphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, _graphicsScreen);
      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));
      _dynamicSkyObject = new DynamicSkyObject(Services, false, false, true);
      GameObjectService.Objects.Add(_dynamicSkyObject);
      GameObjectService.Objects.Add(new GroundObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new LavaBallsObject(Services));

      _particleCloud0 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
      {
        PoseLocal = new Pose(new Vector3F(-0, 100, -400)),
      };
      ParticleSystemService.ParticleSystems.Add(_particleCloud0.ParticleSystem);
      _graphicsScreen.Scene.Children.Add(_particleCloud0);

      _particleCloud1 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
      {
        PoseLocal = new Pose(new Vector3F(-200, 100, -200)),
      };
      ParticleSystemService.ParticleSystems.Add(_particleCloud1.ParticleSystem);
      _graphicsScreen.Scene.Children.Add(_particleCloud1);

      _particleCloud2 = new ParticleSystemNode(CreateParticleCloud(ContentManager))
      {
        PoseLocal = new Pose(new Vector3F(400, 400, -400)),
      };
      ParticleSystemService.ParticleSystems.Add(_particleCloud2.ParticleSystem);
      _graphicsScreen.Scene.Children.Add(_particleCloud2);
    }
Пример #46
0
    public InGameUIScreen(IServiceLocator services, IUIRenderer renderer)
      : base("InGame", renderer)
    {
      var gameObjectService = services.GetInstance<IGameObjectService>();
      _cameraObject = (CameraObject)gameObjectService.Objects["Camera"];

      _simulation = services.GetInstance<Simulation>();

      Background = Color.White;

      // Add one window to the screen.
      Window window = new InGameWindow(services) { X = 175, Y = 30 };
      window.Show(this);
    }
Пример #47
0
        public DebugRendererSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            SampleFramework.IsMouseVisible = false;
            var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
            {
                RenderCallback = Render,
            };

            GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

            // Add a custom game object which controls the camera.
            _cameraObject = new CameraObject(Services);
            GameObjectService.Objects.Add(_cameraObject);

            // Load a sprite font.
            var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default");

            // Create a new debug renderer.
            _debugRenderer = new DebugRenderer(GraphicsService, spriteFont)
            {
                DefaultColor = Color.White,
            };

            // A normal XNA model.
            _xnaModel = ContentManager.Load <Model>("Saucer3/saucer");

            // A DigitalRune model.
            _modelNode           = ContentManager.Load <ModelNode>("Dude/Dude").Clone();
            _modelNode.PoseLocal = new Pose(new Vector3F(6, 0, -7));

            // Create a geometric object with a height field shape.
            var numberOfSamplesX = 20;
            var numberOfSamplesZ = 20;
            var samples          = new float[numberOfSamplesX * numberOfSamplesZ];

            for (int z = 0; z < numberOfSamplesZ; z++)
            {
                for (int x = 0; x < numberOfSamplesX; x++)
                {
                    samples[z * numberOfSamplesX + x] = 1.0f + (float)(Math.Cos(z / 2f) * Math.Sin(x / 2f) * 1.0f);
                }
            }
            HeightField heightField = new HeightField(0, 0, 120, 120, samples, numberOfSamplesX, numberOfSamplesZ);

            _geometricObject = new GeometricObject(heightField, new Pose(new Vector3F(5, 0, -5)))
            {
                Scale = new Vector3F(0.01f, 0.05f, 0.02f),
            };
        }
Пример #48
0
        protected override void OnUpdate(TimeSpan deltaTime)
        {
            if (_cameraObject == null)
            {
                // Get the camera game object.
                var gameObjectService = _services.GetInstance <IGameObjectService>();
                _cameraObject = gameObjectService.Objects.OfType <CameraObject>().First();
            }

            // Create an AABB with the camera position and add the MaxDistance.
            var cameraPosition = _cameraObject.CameraNode.PoseWorld.Position;
            var cameraAabb     = new Aabb(cameraPosition, cameraPosition);

            cameraAabb.Minimum -= new Vector3F(MaxDistance);
            cameraAabb.Maximum += new Vector3F(MaxDistance);

            // Add all scene nodes which are within the MaxDistance to the scene.
            // Remove the other scene nodes.
            // TODO: This code performs brute-force checks. We can make this a lot faster
            // when the nodes are in a simple 2D grid structure.
            // TODO: It is not necessary to make these checks each frame. It is sufficient
            // to update the scene nodes when the camera has moved a certain distance.
            // TODO: Add a hysteresis.
            for (int x = 0; x < _nodes.GetLength(0); x++)
            {
                for (int z = 0; z < _nodes.GetLength(0); z++)
                {
                    bool isVisible = GeometryHelper.HaveContact(cameraAabb, _nodes[x, z].Aabb);
                    if (isVisible)
                    {
                        if (_nodes[x, z].Parent == null)
                        {
                            _scene.Children.Add(_nodes[x, z]);
                        }

                        _nodes[x, z].CastsShadows = CastsShadows;
                    }
                    else
                    {
                        if (_nodes[x, z].Parent != null)
                        {
                            _scene.Children.Remove(_nodes[x, z]);
                        }
                    }

                    _nodes[x, z].IsEnabled = isVisible;
                }
            }
        }
Пример #49
0
    public PostProcessingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Add a PostProcessingGraphicsScreen. This graphics screen has a Scene and does
      // the rendering including post-processing. Please look at PostProcessingGraphicsScreen 
      // for more details.
      GraphicsScreen = new PostProcessingGraphicsScreen(Services);
      GraphicsScreen.DrawReticle = true;
      GraphicsService.Screens.Insert(0, GraphicsScreen);

      // GameObjects that need to render stuff will retrieve the DebugRenderers or
      // Scene through the service provider.
      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, 100);
      GameObjectService.Objects.Add(cameraGameObject);
      GraphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new StaticSkyObject(Services) { SkyExposure = 1 });
      GameObjectService.Objects.Add(new GroundObject(Services));

      for (int i = 0; i < 20; i++)
        GameObjectService.Objects.Add(new DynamicObject(Services, 2));

      for (int i = 0; i < 10; i++)
      {
        var randomPosition = new Vector3F(
          RandomHelper.Random.NextFloat(-5, 5),
          0,
          RandomHelper.Random.NextFloat(-10, 0));
        var randomOrientation = QuaternionF.CreateRotationY(RandomHelper.Random.NextFloat(0, ConstantsF.TwoPi));

        GameObjectService.Objects.Add(new DudeObject(Services)
        {
          Pose = new Pose(randomPosition, randomOrientation)
        });
      }
    }
Пример #50
0
    public TechniqueBindingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

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

      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;

      // More standard objects.
      GameObjectService.Objects.Add(new GrabObject(Services));
      GameObjectService.Objects.Add(new ObjectCreatorObject(Services));
      GameObjectService.Objects.Add(new StaticSkyObject(Services));
      GameObjectService.Objects.Add(new GroundObject(Services));

      // Tell the graphics service how to treat effect techniques which use
      // the "RepeatParameter" annotation.
      _repeatTechniqueInterpreter = new RepeatTechniqueInterpreter();
      GraphicsService.EffectInterpreters.Insert(0, _repeatTechniqueInterpreter);
      _repeatTechniqueBinder = new RepeatTechniqueBinder();
      GraphicsService.EffectBinders.Insert(0, _repeatTechniqueBinder);

      // Load model.
      _modelNode = ContentManager.Load<ModelNode>("Fur2/FurBall").Clone();
      _rigidBody = new RigidBody(new SphereShape(0.5f));

      // Set a random pose.
      _rigidBody.Pose = new Pose(new Vector3F(0, 1, 0), RandomHelper.Random.NextQuaternionF());
      _modelNode.PoseWorld = _rigidBody.Pose;

      // Add rigid body to physics simulation and model to scene.
      Simulation.RigidBodies.Add(_rigidBody);
      _graphicsScreen.Scene.Children.Add(_modelNode);
    }
Пример #51
0
    public BakedAnimationSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a random avatar.
      _avatarDescription = AvatarDescription.CreateRandom();
      _avatarRenderer = new AvatarRenderer(_avatarDescription);

      // Convert animation.
      _waveAnimation = BakeAnimation(new AvatarAnimation(AvatarAnimationPreset.Clap));
    }
Пример #52
0
    public FigureSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");

      _figureRenderer = new FigureRenderer(GraphicsService, 2048);
      _spriteRenderer = new SpriteRenderer(GraphicsService, spriteFont);
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont)
      {
        DefaultColor = Color.Black,
        DefaultTextPosition = new Vector2F(20, 40)
      };

      _scene = new Scene();

      // To draw figures, they are flattened (= converted to line segments) 
      // internally. Figure.Tolerance defines the allowed error between the 
      // smooth and the flattened curve.
      Figure.Tolerance = 0.0001f;

      // Add some FigureNodes to the scene.
      CreateGrid();
      CreateGridClone();
      CreateRandomPath();
      CreateRectangles();
      CreateEllipses();
      CreateAlphaBlendedFigures();
      CreateChain();
      CreateGizmo(spriteFont);
      CreateFlower();

      // Add a game object which handles the picking:
      GameObjectService.Objects.Add(new FigurePickerObject(GraphicsService, _scene, _cameraObject, _debugRenderer));
    }
Пример #53
0
    public WeightedBlendedOITSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Weighted blended OIT is implemented in custom graphics screen.
      // (Only mesh nodes are supported.)
      _graphicsScreen = new WeightedBlendedOITScreen(Services);
      GraphicsService.Screens.Insert(0, _graphicsScreen);

      // Create the standard camera object.
      var cameraGameObject = new CameraObject(Services, 500);
      GameObjectService.Objects.Add(cameraGameObject);
      _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode;

      // Add some lights.
      SceneSample.InitializeDefaultXnaLights(_graphicsScreen.Scene);

      // The tank model used in this example has special materials.
      // See
      // - Samples\Content\WeightedBlendedOIT\engine_diff_tex.drmat
      // - Samples\Content\WeightedBlendedOIT\turret_alt_diff_tex.drmat
      //
      // These materials support the following render passes:
      // - "Default"
      // - "AlphaBlend" same as "Default" except that the Alpha value is lowered.
      // - "ZOnly" renders only the depth into the depth buffer.
      // - "WeightedBlendedOIT" renders the transparent model into the WBOIT render targets.
      // These render passes are used in the WeightedBlendedOITScreen.

      // Load two instances of the "Tank" model:
      // The first instance is rendered opaque (for reference).
      var model = ContentManager.Load<ModelNode>("WeightedBlendedOIT/tank").Clone();
      model.PoseWorld = new Pose(new Vector3F(-4, 0, 0));
      _graphicsScreen.Scene.Children.Add(model);

      // The second instance is rendered transparent.
      model = ContentManager.Load<ModelNode>("WeightedBlendedOIT/tank").Clone();
      model.PoseWorld = new Pose(new Vector3F(4, 0, 0));
      // Set flag to indicate that this instance should be rendered transparent.
      model.GetSubtree().ForEach(node => node.UserFlags = (short)WboitFlags.Transparent);
      _graphicsScreen.Scene.Children.Add(model);
    }
Пример #54
0
    public DebugRendererSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      // Load a sprite font.
      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");

      // Create a new debug renderer.
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont)
      {
        DefaultColor = Color.White,
      };

      // A normal XNA model.
      _xnaModel = ContentManager.Load<Model>("Saucer3/saucer");

      // A DigitalRune model.
      _modelNode = ContentManager.Load<ModelNode>("Dude/Dude").Clone();
      _modelNode.PoseLocal = new Pose(new Vector3F(6, 0, -7));

      // Create a geometric object with a height field shape.
      var numberOfSamplesX = 20;
      var numberOfSamplesZ = 20;
      var samples = new float[numberOfSamplesX * numberOfSamplesZ];
      for (int z = 0; z < numberOfSamplesZ; z++)
        for (int x = 0; x < numberOfSamplesX; x++)
          samples[z * numberOfSamplesX + x] = 1.0f + (float)(Math.Cos(z / 2f) * Math.Sin(x / 2f) * 1.0f);
      HeightField heightField = new HeightField(0, 0, 120, 120, samples, numberOfSamplesX, numberOfSamplesZ);
      _geometricObject = new GeometricObject(heightField, new Pose(new Vector3F(5, 0, -5)))
      {
        Scale = new Vector3F(0.01f, 0.05f, 0.02f),
      };
    }
Пример #55
0
    public CustomAvatarAnimationSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a random avatar.
      _avatarDescription = AvatarDescription.CreateRandom();
      _avatarRenderer = new AvatarRenderer(_avatarDescription);

      // Wrap the Stand0 AvatarAnimationPreset (see WrappedAnimationSample) to create an
      // infinitely looping stand animation.
      AvatarAnimation standAnimationPreset = new AvatarAnimation(AvatarAnimationPreset.Stand0);
      TimelineGroup standAnimation = new TimelineGroup
      {
        new WrappedAvatarExpressionAnimation(standAnimationPreset),
        new WrappedAvatarSkeletonAnimation(standAnimationPreset),
      };
      _standAnimation = new TimelineClip(standAnimation)
      {
        LoopBehavior = LoopBehavior.Cycle,  // Cycle the Stand animation...
        Duration = TimeSpan.MaxValue,       // ...forever.
      };

      // Load animations from content pipeline.
      _faintAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Faint");
      _jumpAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Jump");
      _kickAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Kick");
      _punchAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Punch");

      // The walk cycle should loop: Put it into a timeline clip and set a
      // loop-behavior.
      TimelineGroup walkAnimation = ContentManager.Load<TimelineGroup>("XboxAvatars/Walk");
      _walkAnimation = new TimelineClip(walkAnimation)
      {
        LoopBehavior = LoopBehavior.Cycle,  // Cycle the Walk animation...
        Duration = TimeSpan.MaxValue,       // ...forever.
      };
    }
Пример #56
0
    public ObliqueFrustumSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var graphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, graphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);

      TestClippedProjection();
    }
Пример #57
0
    public BasicAvatarSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // This sample uses for a DebugRenderer for the rendering Avatar skeleton.
      _debugRenderer = new DebugRenderer(GraphicsService, SpriteFont)
      {
        DefaultColor = Color.Black,
        DefaultTextPosition = new Vector2F(10),
      };

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a random avatar.
      _avatarDescription = AvatarDescription.CreateRandom();
      _avatarRenderer = new AvatarRenderer(_avatarDescription);
    }
Пример #58
0
    public AvatarAttachmentSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;

      // This sample uses Scene and MeshRenderer for rendering the attached models.
      _scene = new Scene();
      _meshRenderer = new MeshRenderer();

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      _cameraObject.ResetPose(new Vector3F(0, 1, -3), ConstantsF.Pi, 0);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a random avatar.
      _avatarDescription = AvatarDescription.CreateRandom();
      _avatarRenderer = new AvatarRenderer(_avatarDescription);

      // Load walk animation using the content pipeline.
      TimelineGroup animation = ContentManager.Load<TimelineGroup>("XboxAvatars/Walk");

      // Create a looping walk animation.
      _walkAnimation = new TimelineClip(animation)
      {
        LoopBehavior = LoopBehavior.Cycle,  // Cycle Walk animation...
        Duration = TimeSpan.MaxValue,       // ...forever.
      };

      var baseballBatModelNode = ContentManager.Load<ModelNode>("XboxAvatars/BaseballBat").Clone();
      _baseballBatMeshNode = baseballBatModelNode.GetChildren().OfType<MeshNode>().First();

      // If we only render the baseball bat, it appears black. We need to add it to
      // a scene with some lights. (The lights do not affect the avatar.)
      SceneSample.InitializeDefaultXnaLights(_scene);

      // We must detach the mesh node from its current parent (the model node) before
      // we can add it to the scene.
      _baseballBatMeshNode.Parent.Children.Remove(_baseballBatMeshNode);
      _scene.Children.Add(_baseballBatMeshNode);
    }
Пример #59
0
    public InstancingSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      _scene = new Scene();
      _scene.Children.Add(_cameraObject.CameraNode);

      // Add a lot of instances of one model to the scene. This model uses a custom 
      // shader which supports instancing. See the *.drmdl, *.drmat and *.fx files 
      // in the directory of the FBX file.
      var model = ContentManager.Load<ModelNode>("InstancedModel/InstancedModel");
      for (int x = 1; x < 50; x++)
      {
        for (int z = 1; z < 20; z++)
        {
          var clone = model.Clone();
          Pose pose = clone.PoseLocal;
          pose.Position.X -= x;
          pose.Position.Z -= z;
          clone.PoseLocal = pose;
          clone.ScaleLocal = new Vector3F(0.7f);
          SetRandomColorAndAlpha(clone);
          _scene.Children.Add(clone);
        }
      }

      SceneSample.InitializeDefaultXnaLights(_scene);

      _meshRenderer = new MeshRenderer();
    }
Пример #60
0
    public CustomSceneNodeSample(Microsoft.Xna.Framework.Game game)
      : base(game)
    {
      SampleFramework.IsMouseVisible = false;
      var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService)
      {
        RenderCallback = Render,
      };
      GraphicsService.Screens.Insert(0, delegateGraphicsScreen);

      // Add a custom game object which controls the camera.
      _cameraObject = new CameraObject(Services);
      GameObjectService.Objects.Add(_cameraObject);

      // Create a new empty scene.
      _scene = new Scene();

      // Add the camera node to the scene.
      _scene.Children.Add(_cameraObject.CameraNode);

      // Add a few TextNodes. Position them along a circle.
      for (int i = 0; i < 36; i++)
      {
        Vector3F position = Matrix33F.CreateRotationZ(MathHelper.ToRadians((float)i * 10)) * new Vector3F(1, 0, 0);
        var textNode = new TextNode
        {
          PoseLocal = new Pose(position),
          Color = Color.Yellow,
          Text = i.ToString()
        };
        _scene.Children.Add(textNode);
      }

      // Initialize the TextRenderer.
      var spriteFont = UIContentManager.Load<SpriteFont>("UI Themes/BlendBlue/Default");
      _textRenderer = new TextRenderer(GraphicsService, spriteFont);

      // For debugging:
      _debugRenderer = new DebugRenderer(GraphicsService, spriteFont);
    }