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); }
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); }
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(); }
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 = ... }; }
public BakedAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // 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)); }
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)); }
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 Vector3(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. }; }
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. }; }
public WrappedAvatarAnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // This sample uses for a DebugRenderer for rendering text. _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); }
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); }
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); }
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); }
public TerrainHoleSample(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 standard game objects. var cameraGameObject = new CameraObject(Services, 5000); cameraGameObject.ResetPose(new Vector3(0, 2, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true) { EnableCloudShadows = false, }); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); UpdateHoleTexture(); CreateGuiControls(); }
public TerrainHoleSample(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 standard game objects. var cameraGameObject = new CameraObject(Services, 5000); cameraGameObject.ResetPose(new Vector3F(0, 2, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true) { EnableCloudShadows = false, }); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); UpdateHoleTexture(); CreateGuiControls(); }
public TerrainDecalSample(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 cameraObject = new CameraObject(Services, 5000); cameraObject.ResetPose(new Vector3F(0, 2, 5), 0, 0); GameObjectService.Objects.Add(cameraObject); _graphicsScreen.ActiveCameraNode = cameraObject.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, }); GameObjectService.Objects.Add(new FogObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // Add a blood decal to the terrain. var decal0 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.08f), SpecularColor = new Vector3F(0.2f), SpecularPower = 100, DiffuseTexture = ContentManager.Load<Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, Alpha = 0.9f, }; AddDecal(decal0); // Add a black blood decal (oil spill?) var decal1 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.0f), SpecularColor = new Vector3F(0.5f), SpecularPower = 100, DiffuseTexture = ContentManager.Load<Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, }; AddDecal(decal1); // Add more random decals. The decals can share materials! var decal0Material = decal0.Material; for (int i = 0; i < 50; i++) { var decal = new TerrainDecalLayer(decal0Material) { Pose = GetRandomPose(), Width = 2, Height = 2, }; AddDecal(decal); } }
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 = ... }; }
public ParallaxTerrainSample(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 standard game objects. var cameraGameObject = new CameraObject(Services, 5000); cameraGameObject.ResetPose(new Vector3(0, 2, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true) { EnableCloudShadows = false, }); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // To see parallax occlusion mapping, we need a detail texture with a height map. // In this sample we reuse the pavement texture of the ParallaxMappingSample and // add it to the terrain. for (int row = 0; row < 2; row++) { for (int column = 0; column < 2; column++) { var terrainTile = _terrainObject.TerrainNode.Terrain.Tiles[row * 2 + column]; string tilePostfix = "-" + row + "-" + column; // e.g. "-0-1" var materialPavement = new TerrainMaterialLayer(GraphicsService) { DiffuseColor = new Vector3(1), SpecularColor = new Vector3(5), SpecularPower = 20, DiffuseTexture = ContentManager.Load <Texture2D>("Parallax/AgedPavement_diffuse"), NormalTexture = ContentManager.Load <Texture2D>("Parallax/AgedPavement_normal"), SpecularTexture = ContentManager.Load <Texture2D>("Parallax/AgedPavement_specular"), HeightTexture = ContentManager.Load <Texture2D>("Parallax/AgedPavement_height"), TileSize = 0.005f * 512, BlendTexture = ContentManager.Load <Texture2D>("Terrain/Terrain001-Blend-Grass" + tilePostfix), BlendTextureChannel = 0, BlendHeightInfluence = 0.5f, BlendThreshold = 0.5f, BlendRange = 0.5f, }; terrainTile.Layers.Add(materialPavement); } } // Replace the terrain effects with effects which support parallax occlusion mapping. UpdateTerrainMaterial(true); CreateGuiControls(); }
public ProjectedShadowSample2(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // The dude model uses a new ProjectedShadowSkinned.fx effect. This effect contains new // parameters 'ShadowMatrix' and 'ShadowColor' which are not yet supported. When an mesh is // loaded via the content manager, effect bindings are automatically created. This is done // by effect interpreters and effect binders. The graphics service uses several predefined // effect interpreter and binder classes to support the most common effect parameters. E.g. // the SceneEffectInterpreter and SceneEffectBinder handle parameters like 'World', 'View', // 'ViewProjection', 'CameraPosition', 'FogColor', etc. (see also class // SceneEffectParameterSemantics). // We can add new effect interpreters/binders or we can add an entry to an existing // interpreter/binder. Let's add entries to the standard SceneEffectInterpreter which creates // meta-data for the new parameters: var sceneEffectInterpreter = GraphicsService.EffectInterpreters.OfType<SceneEffectInterpreter>().First(); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowMatrix", (parameter, index) => new EffectParameterDescription(parameter, "ShadowMatrix", index, EffectParameterHint.Global)); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowColor", (parameter, index) => new EffectParameterDescription(parameter, "ShadowColor", index, EffectParameterHint.Global)); // Add entries to the standard SceneEffectBinder which create DelegateParameterBindings for // the new parameters. The delegate bindings use callback methods to compute the parameter // value. var sceneEffectBinder = GraphicsService.EffectBinders.OfType<SceneEffectBinder>().First(); sceneEffectBinder.MatrixBindings.Add( "ShadowMatrix", (effect, parameter, data) => new DelegateParameterBinding<Matrix>(effect, parameter, GetShadowMatrix)); sceneEffectBinder.Vector4Bindings.Add( "ShadowColor", (effect, parameter, data) => new DelegateParameterBinding<Vector4>(effect, parameter, GetShadowColor)); // 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(-2, 2, 2), -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 dude model to the scene graph. var dude = ContentManager.Load<ModelNode>("DudeWithProjectedShadow/Dude").Clone(); dude.PoseWorld = new Pose(Matrix33F.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(dude); _scene.Children.Add(dude); // Start walk animation. StartDudeAnimation(dude); // Create the renderers. _meshRenderer = new MeshRenderer(); _shadowColor = new Vector4(0, 0, 0, 0.4f); }
public TerrainTextureSample(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, 60); cameraGameObject.ResetPose(new Vector3F(0, 1.8f, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; for (int i = 0; i < 10; i++) { GameObjectService.Objects.Add(new DynamicObject(Services, 1)); } GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true)); // Create a simple flat terrain. var terrain = new Terrain(); _terrainTile = new TerrainTile(GraphicsService) { OriginX = -100, OriginZ = -100, CellSize = 1, }; terrain.Tiles.Add(_terrainTile); // Create a flat dummy height texture. float[] heights = new float[200 * 200]; Texture2D heightTexture = null; TerrainHelper.CreateHeightTexture( GraphicsService.GraphicsDevice, heights, 200, 200, false, ref heightTexture); _terrainTile.HeightTexture = heightTexture; var shadowMapEffect = ContentManager.Load <Effect>("DigitalRune/Terrain/TerrainShadowMap"); var gBufferEffect = ContentManager.Load <Effect>("DigitalRune/Terrain/TerrainGBuffer"); var materialEffect = ContentManager.Load <Effect>("DigitalRune/Terrain/TerrainMaterial"); var material = new Material { { "ShadowMap", new EffectBinding(GraphicsService, shadowMapEffect, null, EffectParameterHint.Material) }, { "GBuffer", new EffectBinding(GraphicsService, gBufferEffect, null, EffectParameterHint.Material) }, { "Material", new EffectBinding(GraphicsService, materialEffect, null, EffectParameterHint.Material) } }; var terrainNode = new TerrainNode(terrain, material) { DetailClipmap = { CellsPerLevel = 1364, NumberOfLevels = 9, EnableMipMap = true, }, }; scene.Children.Add(terrainNode); // Add 3 detail textures layers: gravel, rock, snow. float detailCellSize = terrainNode.DetailClipmap.CellSizes[0]; var materialGravel = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load <Texture2D>("Terrain/Gravel-Diffuse"), NormalTexture = ContentManager.Load <Texture2D>("Terrain/Gravel-Normal"), SpecularTexture = ContentManager.Load <Texture2D>("Terrain/Gravel-Specular"), TileSize = detailCellSize * 512, BlendRange = 0.1f, }; _terrainTile.Layers.Add(materialGravel); var noiseTexture = NoiseHelper.GetNoiseTexture(GraphicsService, 128, 60); var materialRock = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load <Texture2D>("Terrain/Rock-02-Diffuse"), NormalTexture = ContentManager.Load <Texture2D>("Terrain/Rock-02-Normal"), SpecularTexture = ContentManager.Load <Texture2D>("Terrain/Rock-02-Specular"), HeightTexture = ContentManager.Load <Texture2D>("Terrain/Rock-02-Height"), TileSize = detailCellSize * 1024, DiffuseColor = new Vector3F(1 / 0.702f), BlendTexture = noiseTexture, BlendTextureChannel = 0, BlendRange = 0.1f, TerrainHeightBlendRange = 0.1f, }; _terrainTile.Layers.Add(materialRock); var materialSnow = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load <Texture2D>("Terrain/Snow-Diffuse"), NormalTexture = ContentManager.Load <Texture2D>("Terrain/Snow-Normal"), SpecularTexture = ContentManager.Load <Texture2D>("Terrain/Snow-Specular"), TileSize = detailCellSize * 512, BlendTexture = noiseTexture, BlendTextureChannel = 1, BlendRange = 0.1f, }; _terrainTile.Layers.Add(materialSnow); // Create a flat plane for collision detection. var rigidBody = new RigidBody(new PlaneShape(), new MassFrame(), null) { MotionType = MotionType.Static, }; Simulation.RigidBodies.Add(rigidBody); CreateGuiControls(); }
public IntersectionSample(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, 10); _cameraObject.ResetPose(new Vector3(0, 0, -4), ConstantsF.Pi, 0); GameObjectService.Objects.Add(_cameraObject); // Create a new scene with some lights. _scene = new Scene(); SceneSample.InitializeDefaultXnaLights(_scene); _meshRenderer = new MeshRenderer(); _debugRenderer = new DebugRenderer(GraphicsService, null); _intersectionRenderer = new IntersectionRenderer(GraphicsService, ContentManager) { DownsampleFactor = 1, }; //_submeshA = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new SphereShape(0.5f).GetMesh(0.001f, 5), MathHelper.ToRadians(70)); //_submeshB = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)); var meshNodeA = CreateMeshNode(new[] { MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)), }, Color.DarkBlue); meshNodeA.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-0.5f, 0.5f), RandomHelper.Random.NextQuaternion()); _scene.Children.Add(meshNodeA); _debugRenderer.DrawObject(meshNodeA, Color.Green, true, false); var shape = new TransformedShape( new GeometricObject(new SphereShape(0.5f), new Pose(new Vector3(1, 0, 0)))); var meshNodeB = CreateMeshNode(new[] { MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, shape.GetMesh(0.001f, 4), MathHelper.ToRadians(90)), }, Color.Gray); meshNodeB.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-1f, 1f), RandomHelper.Random.NextQuaternion()); _scene.Children.Add(meshNodeB); _debugRenderer.DrawObject(meshNodeB, Color.Green, true, false); var meshNodeC = CreateMeshNode(new[] { MeshHelper.CreateBox(GraphicsService.GraphicsDevice), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)) }, Color.DarkGreen); meshNodeC.PoseWorld = new Pose(RandomHelper.Random.NextVector3(-1f, 1f), RandomHelper.Random.NextQuaternion()); meshNodeC.ScaleLocal = new Vector3(0.1f, 1f, 0.5f); _scene.Children.Add(meshNodeC); _debugRenderer.DrawObject(meshNodeC, Color.Green, true, false); _meshNodePairs.Add(new Pair <MeshNode>(meshNodeA, meshNodeB)); _meshNodePairs.Add(new Pair <MeshNode>(meshNodeA, meshNodeC)); _meshNodePairs.Add(new Pair <MeshNode>(meshNodeB, meshNodeC)); CreateGuiControls(); }
public ProjectedShadowSample2(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // The dude model uses a new ProjectedShadowSkinned.fx effect. This effect contains new // parameters 'ShadowMatrix' and 'ShadowColor' which are not yet supported. When an mesh is // loaded via the content manager, effect bindings are automatically created. This is done // by effect interpreters and effect binders. The graphics service uses several predefined // effect interpreter and binder classes to support the most common effect parameters. E.g. // the SceneEffectInterpreter and SceneEffectBinder handle parameters like 'World', 'View', // 'ViewProjection', 'CameraPosition', 'FogColor', etc. (see also class // SceneEffectParameterSemantics). // We can add new effect interpreters/binders or we can add an entry to an existing // interpreter/binder. Let's add entries to the standard SceneEffectInterpreter which creates // meta-data for the new parameters: var sceneEffectInterpreter = GraphicsService.EffectInterpreters.OfType <SceneEffectInterpreter>().First(); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowMatrix", (parameter, index) => new EffectParameterDescription(parameter, "ShadowMatrix", index, EffectParameterHint.Global)); sceneEffectInterpreter.ParameterDescriptions.Add( "ShadowColor", (parameter, index) => new EffectParameterDescription(parameter, "ShadowColor", index, EffectParameterHint.Global)); // Add entries to the standard SceneEffectBinder which create DelegateParameterBindings for // the new parameters. The delegate bindings use callback methods to compute the parameter // value. var sceneEffectBinder = GraphicsService.EffectBinders.OfType <SceneEffectBinder>().First(); sceneEffectBinder.MatrixBindings.Add( "ShadowMatrix", (effect, parameter, data) => new DelegateParameterBinding <Matrix>(effect, parameter, GetShadowMatrix)); sceneEffectBinder.Vector4Bindings.Add( "ShadowColor", (effect, parameter, data) => new DelegateParameterBinding <Vector4>(effect, parameter, GetShadowColor)); // 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 Vector3(-2, 2, 2), -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 Vector3(0.3f); _scene.Children.Add(grid); // Add a dude model to the scene graph. var dude = ContentManager.Load <ModelNode>("DudeWithProjectedShadow/Dude").Clone(); dude.PoseWorld = new Pose(Matrix.CreateRotationY(ConstantsF.Pi)); SampleHelper.EnablePerPixelLighting(dude); _scene.Children.Add(dude); // Start walk animation. StartDudeAnimation(dude); // Create the renderers. _meshRenderer = new MeshRenderer(); _shadowColor = new Vector4(0, 0, 0, 0.4f); }
public RoadSample(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 Vector3(0, 2, 5), 0, 0); GameObjectService.Objects.Add(cameraGameObject); // Add the vehicle object from the vehicle sample. var vehicleObject = new ConstraintVehicleObject(Services); GameObjectService.Objects.Add(vehicleObject); // Add the car-follow-camera from the vehicle sample. var vehicleCameraObject = new VehicleCameraObject(vehicleObject.Vehicle.Chassis, Services); GameObjectService.Objects.Add(vehicleCameraObject); // Now, we have two CameraNodes. The graphics screen uses the camera node of the CameraObject, // as usual. _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // The CameraObject should not react to input. cameraGameObject.IsEnabled = false; // The CameraNode of the VehicleCameraObject controls the other CameraNode. vehicleCameraObject.CameraNode.SceneChanged += (s, e) => { cameraGameObject.CameraNode.SetLastPose(false); cameraGameObject.CameraNode.PoseWorld = vehicleCameraObject.CameraNode.PoseWorld; }; // Add standard game objects. 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 default 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 the terrain _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // Add the TerrainRoadLayer to the terrain. CreateRoad(); // Modify the terrain height values. ClampTerrainToRoad(); }
public ParallaxTerrainSample(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 standard game objects. var cameraGameObject = new CameraObject(Services, 5000); cameraGameObject.ResetPose(new Vector3F(0, 2, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); GameObjectService.Objects.Add(new GrabObject(Services)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true) { EnableCloudShadows = false, }); GameObjectService.Objects.Add(new ObjectCreatorObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // To see parallax occlusion mapping, we need a detail texture with a height map. // In this sample we reuse the pavement texture of the ParallaxMappingSample and // add it to the terrain. for (int row = 0; row < 2; row++) { for (int column = 0; column < 2; column++) { var terrainTile = _terrainObject.TerrainNode.Terrain.Tiles[row * 2 + column]; string tilePostfix = "-" + row + "-" + column; // e.g. "-0-1" var materialPavement = new TerrainMaterialLayer(GraphicsService) { DiffuseColor = new Vector3F(1), SpecularColor = new Vector3F(5), SpecularPower = 20, DiffuseTexture = ContentManager.Load<Texture2D>("Parallax/AgedPavement_diffuse"), NormalTexture = ContentManager.Load<Texture2D>("Parallax/AgedPavement_normal"), SpecularTexture = ContentManager.Load<Texture2D>("Parallax/AgedPavement_specular"), HeightTexture = ContentManager.Load<Texture2D>("Parallax/AgedPavement_height"), TileSize = 0.005f * 512, BlendTexture = ContentManager.Load<Texture2D>("Terrain/Terrain001-Blend-Grass" + tilePostfix), BlendTextureChannel = 0, BlendHeightInfluence = 0.5f, BlendThreshold = 0.5f, BlendRange = 0.5f, }; terrainTile.Layers.Add(materialPavement); } } // Replace the terrain effects with effects which support parallax occlusion mapping. UpdateTerrainMaterial(true); CreateGuiControls(); }
public TerrainDecalSample(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 cameraObject = new CameraObject(Services, 5000); cameraObject.ResetPose(new Vector3F(0, 2, 5), 0, 0); GameObjectService.Objects.Add(cameraObject); _graphicsScreen.ActiveCameraNode = cameraObject.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, }); GameObjectService.Objects.Add(new FogObject(Services)); // Create terrain. _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // Add a blood decal to the terrain. var decal0 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.08f), SpecularColor = new Vector3F(0.2f), SpecularPower = 100, DiffuseTexture = ContentManager.Load <Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, Alpha = 0.9f, }; AddDecal(decal0); // Add a black blood decal (oil spill?) var decal1 = new TerrainDecalLayer(GraphicsService) { Pose = GetRandomPose(), Width = 2, Height = 2, DiffuseColor = new Vector3F(0.0f), SpecularColor = new Vector3F(0.5f), SpecularPower = 100, DiffuseTexture = ContentManager.Load <Texture2D>("Decals/Decal_diffuse_mask"), // Original: "Decals/Blood_diffuse_mask", NormalTexture = GraphicsService.GetDefaultNormalTexture(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_normal"), SpecularTexture = GraphicsService.GetDefaultTexture2DWhite(), // Original: ContentManager.Load<Texture2D>("Decals/Blood_specular"), FadeOutStart = 3, FadeOutEnd = 5, }; AddDecal(decal1); // Add more random decals. The decals can share materials! var decal0Material = decal0.Material; for (int i = 0; i < 50; i++) { var decal = new TerrainDecalLayer(decal0Material) { Pose = GetRandomPose(), Width = 2, Height = 2, }; AddDecal(decal); } }
public RoadSample(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); // Add the vehicle object from the vehicle sample. var vehicleObject = new ConstraintVehicleObject(Services); GameObjectService.Objects.Add(vehicleObject); // Add the car-follow-camera from the vehicle sample. var vehicleCameraObject = new VehicleCameraObject(vehicleObject.Vehicle.Chassis, Services); GameObjectService.Objects.Add(vehicleCameraObject); // Now, we have two CameraNodes. The graphics screen uses the camera node of the CameraObject, // as usual. _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; // The CameraObject should not react to input. cameraGameObject.IsEnabled = false; // The CameraNode of the VehicleCameraObject controls the other CameraNode. vehicleCameraObject.CameraNode.SceneChanged += (s, e) => { cameraGameObject.CameraNode.SetLastPose(false); cameraGameObject.CameraNode.PoseWorld = vehicleCameraObject.CameraNode.PoseWorld; }; // Add standard game objects. 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 default 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 the terrain _terrainObject = new TerrainObject(Services); GameObjectService.Objects.Add(_terrainObject); // Add the TerrainRoadLayer to the terrain. CreateRoad(); // Modify the terrain height values. ClampTerrainToRoad(); }
public AdvancedAvatarRagdollSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // This sample uses for a DebugRenderer to draw text and rigid bodies. _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); // 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()); // Create a random avatar. _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Use the "Wave" animation preset. var avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); _expressionAnimation = new AnimationClip<AvatarExpression>(new WrappedAvatarExpressionAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _skeletonAnimation = new AnimationClip<SkeletonPose>(new WrappedAvatarSkeletonAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Add a ground plane in the simulation. Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3F.UnitY, 0)) { MotionType = MotionType.Static }); // Distribute a few dynamic spheres and boxes across the landscape. SphereShape sphereShape = new SphereShape(0.3f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(sphereShape) { Pose = new Pose(position) }); } BoxShape boxShape = new BoxShape(0.6f, 0.6f, 0.6f); for (int i = 0; i < 10; i++) { Vector3F position = RandomHelper.Random.NextVector3F(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(boxShape) { Pose = new Pose(position) }); } }
public AdvancedAvatarRagdollSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // This sample uses for a DebugRenderer to draw text and rigid bodies. _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 Vector3(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()); // Create a random avatar. _avatarDescription = AvatarDescription.CreateRandom(); _avatarRenderer = new AvatarRenderer(_avatarDescription); // Use the "Wave" animation preset. var avatarAnimation = new AvatarAnimation(AvatarAnimationPreset.Wave); _expressionAnimation = new AnimationClip <AvatarExpression>(new WrappedAvatarExpressionAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; _skeletonAnimation = new AnimationClip <SkeletonPose>(new WrappedAvatarSkeletonAnimation(avatarAnimation)) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, }; // Add a ground plane in the simulation. Simulation.RigidBodies.Add(new RigidBody(new PlaneShape(Vector3.UnitY, 0)) { MotionType = MotionType.Static }); // Distribute a few dynamic spheres and boxes across the landscape. SphereShape sphereShape = new SphereShape(0.3f); for (int i = 0; i < 10; i++) { Vector3 position = RandomHelper.Random.NextVector3(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(sphereShape) { Pose = new Pose(position) }); } BoxShape boxShape = new BoxShape(0.6f, 0.6f, 0.6f); for (int i = 0; i < 10; i++) { Vector3 position = RandomHelper.Random.NextVector3(-10, 10); position.Y = 1; Simulation.RigidBodies.Add(new RigidBody(boxShape) { Pose = new Pose(position) }); } }
public IntersectionSample(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, 10); _cameraObject.ResetPose(new Vector3F(0, 0, -4), ConstantsF.Pi, 0); GameObjectService.Objects.Add(_cameraObject); // Create a new scene with some lights. _scene = new Scene(); SceneSample.InitializeDefaultXnaLights(_scene); _meshRenderer = new MeshRenderer(); _debugRenderer = new DebugRenderer(GraphicsService, null); _intersectionRenderer = new IntersectionRenderer(GraphicsService, ContentManager) { DownsampleFactor = 1, }; //_submeshA = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new SphereShape(0.5f).GetMesh(0.001f, 5), MathHelper.ToRadians(70)); //_submeshB = MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)); var meshNodeA = CreateMeshNode(new[] { MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)), }, Color.DarkBlue); meshNodeA.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-0.5f, 0.5f), RandomHelper.Random.NextQuaternionF()); _scene.Children.Add(meshNodeA); _debugRenderer.DrawObject(meshNodeA, Color.Green, true, false); var shape = new TransformedShape( new GeometricObject(new SphereShape(0.5f), new Pose(new Vector3F(1, 0, 0)))); var meshNodeB = CreateMeshNode(new[] { MeshHelper.CreateTorus(GraphicsService.GraphicsDevice, 1, 0.3f, 30), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, shape.GetMesh(0.001f, 4), MathHelper.ToRadians(90)), }, Color.Gray); meshNodeB.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-1f, 1f), RandomHelper.Random.NextQuaternionF()); _scene.Children.Add(meshNodeB); _debugRenderer.DrawObject(meshNodeB, Color.Green, true, false); var meshNodeC = CreateMeshNode(new[] { MeshHelper.CreateBox(GraphicsService.GraphicsDevice), MeshHelper.CreateSubmesh(GraphicsService.GraphicsDevice, new BoxShape(1, 1, 2).GetMesh(0.001f, 5), MathHelper.ToRadians(70)) }, Color.DarkGreen); meshNodeC.PoseWorld = new Pose(RandomHelper.Random.NextVector3F(-1f, 1f), RandomHelper.Random.NextQuaternionF()); meshNodeC.ScaleLocal = new Vector3F(0.1f, 1f, 0.5f); _scene.Children.Add(meshNodeC); _debugRenderer.DrawObject(meshNodeC, Color.Green, true, false); _meshNodePairs.Add(new Pair<MeshNode>(meshNodeA, meshNodeB)); _meshNodePairs.Add(new Pair<MeshNode>(meshNodeA, meshNodeC)); _meshNodePairs.Add(new Pair<MeshNode>(meshNodeB, meshNodeC)); CreateGuiControls(); }
public ProceduralTerrainSample(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 Vector3(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 default 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 a procedural terrain. var terrainObject = new ProceduralTerrainObject(Services); GameObjectService.Objects.Add(terrainObject); SampleFramework.ShowOptionsWindow(); }
public TerrainTextureSample(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, 60); cameraGameObject.ResetPose(new Vector3F(0, 1.8f, 0), 0, 0); GameObjectService.Objects.Add(cameraGameObject); _graphicsScreen.ActiveCameraNode = cameraGameObject.CameraNode; for (int i = 0; i < 10; i++) GameObjectService.Objects.Add(new DynamicObject(Services, 1)); GameObjectService.Objects.Add(new DynamicSkyObject(Services, true, false, true)); // Create a simple flat terrain. var terrain = new Terrain(); _terrainTile = new TerrainTile(GraphicsService) { OriginX = -100, OriginZ = -100, CellSize = 1, }; terrain.Tiles.Add(_terrainTile); // Create a flat dummy height texture. float[] heights = new float[200 * 200]; Texture2D heightTexture = null; TerrainHelper.CreateHeightTexture( GraphicsService.GraphicsDevice, heights, 200, 200, false, ref heightTexture); _terrainTile.HeightTexture = heightTexture; var shadowMapEffect = ContentManager.Load<Effect>("DigitalRune/Terrain/TerrainShadowMap"); var gBufferEffect = ContentManager.Load<Effect>("DigitalRune/Terrain/TerrainGBuffer"); var materialEffect = ContentManager.Load<Effect>("DigitalRune/Terrain/TerrainMaterial"); var material = new Material { { "ShadowMap", new EffectBinding(GraphicsService, shadowMapEffect, null, EffectParameterHint.Material) }, { "GBuffer", new EffectBinding(GraphicsService, gBufferEffect, null, EffectParameterHint.Material) }, { "Material", new EffectBinding(GraphicsService, materialEffect, null, EffectParameterHint.Material) } }; var terrainNode = new TerrainNode(terrain, material) { DetailClipmap = { CellsPerLevel = 1364, NumberOfLevels = 9, EnableMipMap = true, }, }; scene.Children.Add(terrainNode); // Add 3 detail textures layers: gravel, rock, snow. float detailCellSize = terrainNode.DetailClipmap.CellSizes[0]; var materialGravel = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load<Texture2D>("Terrain/Gravel-Diffuse"), NormalTexture = ContentManager.Load<Texture2D>("Terrain/Gravel-Normal"), SpecularTexture = ContentManager.Load<Texture2D>("Terrain/Gravel-Specular"), TileSize = detailCellSize * 512, BlendRange = 0.1f, }; _terrainTile.Layers.Add(materialGravel); var noiseTexture = NoiseHelper.GetNoiseTexture(GraphicsService, 128, 60); var materialRock = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load<Texture2D>("Terrain/Rock-02-Diffuse"), NormalTexture = ContentManager.Load<Texture2D>("Terrain/Rock-02-Normal"), SpecularTexture = ContentManager.Load<Texture2D>("Terrain/Rock-02-Specular"), HeightTexture = ContentManager.Load<Texture2D>("Terrain/Rock-02-Height"), TileSize = detailCellSize * 1024, DiffuseColor = new Vector3F(1 / 0.702f), BlendTexture = noiseTexture, BlendTextureChannel = 0, BlendRange = 0.1f, TerrainHeightBlendRange = 0.1f, }; _terrainTile.Layers.Add(materialRock); var materialSnow = new TerrainMaterialLayer(GraphicsService) { DiffuseTexture = ContentManager.Load<Texture2D>("Terrain/Snow-Diffuse"), NormalTexture = ContentManager.Load<Texture2D>("Terrain/Snow-Normal"), SpecularTexture = ContentManager.Load<Texture2D>("Terrain/Snow-Specular"), TileSize = detailCellSize * 512, BlendTexture = noiseTexture, BlendTextureChannel = 1, BlendRange = 0.1f, }; _terrainTile.Layers.Add(materialSnow); // Create a flat plane for collision detection. var rigidBody = new RigidBody(new PlaneShape(), new MassFrame(), null) { MotionType = MotionType.Static, }; Simulation.RigidBodies.Add(rigidBody); CreateGuiControls(); }