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(); } }
public WindowsPhoneSample(Microsoft.Xna.Framework.Game game) : base(game) { // Disable mouse centering and show the mouse cursor. EnableMouseCentering = false; // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. _graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, _graphicsScreen); // Load a UI theme, which defines the appearance and default values of UI controls. _uiContentManager = new ContentManager(Services, "WindowsPhone7Theme"); Theme theme = _uiContentManager.Load <Theme>("ThemeDark"); // Create a UI renderer, which uses the theme info to renderer UI controls. UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. The screen is the root of the // tree of UI controls. Each screen can have its own renderer. _uiScreen = new UIScreen("SampleUIScreen", renderer) { // Make the screen transparent. Background = new Color(0, 0, 0, 0), }; UIService.Screens.Add(_uiScreen); // Open a window. var window = new WpWindow(Game); window.Show(_uiScreen); }
public CustomCommandSample(Microsoft.Xna.Framework.Game game) : base(game) { // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. var graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render }; GraphicsService.Screens.Insert(0, graphicsScreen); _spriteBatch = GraphicsService.GetSpriteBatch(); // Load a few SpriteFonts for rendering. _textFont = UIContentManager.Load <SpriteFont>("UI Themes/WindowsPhone7/Segoe15"); _buttonFont = ContentManager.Load <SpriteFont>("ButtonImages/xboxControllerSpriteFont"); // Add custom commands to input service. _buttonHoldCommand = new ButtonHoldCommand(Buttons.A, 1.0f) { Name = "Hold A" }; _buttonTapCommand = new ButtonTapCommand(Buttons.A, 0.2f, 1.0f) { Name = "Tap A" }; _buttonSequenceCommand = new ButtonSequenceCommand(new [] { Buttons.A, Buttons.B, Buttons.A, Buttons.B }, 2.0f) { Name = "A-B-A-B" }; InputService.Commands.Add(_buttonHoldCommand); InputService.Commands.Add(_buttonTapCommand); InputService.Commands.Add(_buttonSequenceCommand); }
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(); }
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); }
public Editor2D(Microsoft.Xna.Framework.Game game) : base(game) { // Create a simple delegate graphics screen to handle figure rendering var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; // TODO - make sure we don't just want to put this under the controls screen? // make sure to insert it on top? GraphicsService.Screens.Insert(0, delegateGraphicsScreen); _cameraObject = new Editor2DCameraObject(Services); GameObjectService.Objects.Add(_cameraObject); CreateGrid(); CreateGate(); // Add a game object which handles the picking: GameObjectService.Objects.Add(new FigurePickerObject(GraphicsService, Scene, _cameraObject, DebugRenderer)); var test = new GridSettingsWindow(); UIScreen.Children.Add(test); }
public ScreenInScreenSample(Microsoft.Xna.Framework.Game game) : base(game) { // The first screen. _screen1 = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = RenderScreen1, }; GraphicsService.Screens.Insert(0, _screen1); // The second screen. _screen2 = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = RenderScreen2, // A graphics screen should let the graphics service know if it renders // to the whole screen, thereby hiding any graphics screens in the background. Coverage = GraphicsScreenCoverage.Full, // Tell the graphics service to render the previous screens into a render // target with a custom format. RenderPreviousScreensToTexture = true, SourceTextureFormat = new RenderTargetFormat(800, 600, false, SurfaceFormat.Color, DepthFormat.Depth24), }; GraphicsService.Screens.Insert(1, _screen2); // Create a sprite batch. _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); // Load a sprite font. _spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); }
public GameStatesSample(Microsoft.Xna.Framework.Game game) : base(game) { // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. var graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, graphicsScreen); // Load a UI theme, which defines the appearance and default values of UI controls. Theme theme = ContentManager.Load<Theme>("UI Themes/GameStatesSample/Theme"); // Create a UI renderer, which uses the theme info to renderer UI controls. UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. The screen is the root of the // tree of UI controls. Each screen can have its own renderer. _uiScreen = new UIScreen("SampleUIScreen", renderer) { // Make the screen transparent. Background = new Color(0, 0, 0, 0), }; UIService.Screens.Add(_uiScreen); CreateStateMachine(); }
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, }; }
protected override void Dispose(bool disposing) { if (disposing) { _graphicsService.Screens.Remove(_graphicsScreen); _graphicsScreen = null; } base.Dispose(disposing); }
public TilingSample(Microsoft.Xna.Framework.Game game) : base(game) { // Disable mouse centering and show the mouse cursor. EnableMouseCentering = false; // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. _graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, _graphicsScreen); // Load a UI theme, which defines the appearance and default values of UI controls. _uiContentManager = new ContentManager(Services, "TilingSampleTheme"); Theme theme = _uiContentManager.Load <Theme>("Theme"); // Create a UI renderer, which uses the theme info to renderer UI controls. UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. The screen is the root of the // tree of UI controls. Each screen can have its own renderer. _uiScreen = new UIScreen("SampleUIScreen", renderer); UIService.Screens.Add(_uiScreen); // Create a window using the default style "Window". var stretchedWindow = new Window { X = 100, Y = 100, Width = 480, Height = 320, CanResize = true, }; _uiScreen.Children.Add(stretchedWindow); // Create a window using the style "TiledWindow". var tiledWindow = new Window { X = 200, Y = 200, Width = 480, Height = 320, CanResize = true, Style = "TiledWindow", }; _uiScreen.Children.Add(tiledWindow); // Check file TilingSampleContent/Theme.xml to see how the styles are defined. }
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), }; }
public ControlsSample(Microsoft.Xna.Framework.Game game) : base(game) { // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. var graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, graphicsScreen); CreateGui(); }
protected override void Dispose(bool disposing) { if (disposing) { if (_uiScreen != null) // This check is necessary because Dispose() might be called more than once. { _uiService.Screens.Remove(_uiScreen); _uiScreen = null; _graphicsService.Screens.Remove(_graphicsScreen); _graphicsScreen = null; } } base.Dispose(disposing); }
public ControlsSample(Microsoft.Xna.Framework.Game game) : base(game) { // Disable mouse centering and show the mouse cursor. EnableMouseCentering = false; // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. _graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(0, _graphicsScreen); CreateGui(); }
public DebugRendererSample(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 a sprite font. var spriteFont = UIContentManager.Load <SpriteFont>("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. HeightField heightField = new HeightField { WidthX = 120, WidthZ = 120, Array = new float[20, 20] }; for (int row = 0; row < heightField.Array.GetLength(0); row++) { for (int column = 0; column < heightField.Array.GetLength(1); column++) { heightField.Array[row, column] = 1.0f + (float)(Math.Cos(column / 2f) * Math.Sin(row / 2f) * 1.0f); } } _geometricObject = new GeometricObject(heightField, new Pose(new Vector3F(5, 0, -5))) { Scale = new Vector3F(0.01f, 0.05f, 0.02f), }; }
public FigureSample(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 spriteFont = UIContentManager.Load <SpriteFont>("Default"); var spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); _figureRenderer = new FigureRenderer(GraphicsService, 2048); _spriteRenderer = new SpriteRenderer(GraphicsService, spriteBatch, spriteFont); _debugRenderer = new DebugRenderer(GraphicsService, spriteBatch, 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: _figurePickerObject = new FigurePickerObject(GraphicsService, _scene, _cameraObject, _debugRenderer); GameObjectService.Objects.Add(_figurePickerObject); }
public override void Initialize() { base.Initialize(); // Add a DelegateGraphicsScreen as the first graphics screen to the graphics // service. This lets us do the rendering in the Render method of this class. _graphicsScreen = new DelegateGraphicsScreen(_graphicsService) { RenderCallback = Render, }; _graphicsService.Screens.Insert(0, _graphicsScreen); // Get the "SampleUI" screen that was created by the StartScreenComponent. _uiScreen = _uiService.Screens["SampleUI"]; // Show the main menu window. _mainMenuWindow = new MainMenuWindow(); _mainMenuWindow.Show(_uiScreen); }
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); }
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 Vector3(0.7f); SetRandomColorAndAlpha(clone); _scene.Children.Add(clone); } } SceneSample.InitializeDefaultXnaLights(_scene); _meshRenderer = new MeshRenderer(); }
protected AnimationSample(Microsoft.Xna.Framework.Game game) : base(game) { // Add a DelegateGraphicsScreen and use the OnRender method of this class to // do the rendering. _graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = OnRender, }; // The order of the graphics screens is back-to-front. Add the screen at index 0, // i.e. behind all other screens. The screen should be rendered first and all other // screens (menu, GUI, help, ...) should be on top. GraphicsService.Screens.Insert(0, _graphicsScreen); // Provide a SpriteBatch, SpriteFont and images for rendering. SpriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); SpriteFont = UIContentManager.Load <SpriteFont>("Default"); Logo = ContentManager.Load <Texture2D>("Logo"); Reticle = ContentManager.Load <Texture2D>("Reticle"); }
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(); }
public DelegateGraphicsScreenSample(Microsoft.Xna.Framework.Game game) : base(game) { // Create the DelegateGraphicsService and add it to the graphics service. var delegateGraphicsScreen = new DelegateGraphicsScreen(GraphicsService) { UpdateCallback = Update, RenderCallback = Render, }; // Graphics screens are rendered in the order in which they appear in the // IGraphicsService.Screens collection. We insert our screen at the beginning // of the collection to render our screen before the other screens (e.g. menu, // help text, profiling). GraphicsService.Screens.Insert(0, delegateGraphicsScreen); // Create a sprite batch. _spriteBatch = new SpriteBatch(GraphicsService.GraphicsDevice); // Load a sprite font. _spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); }
public SceneSample(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); // Create a new empty scene. _scene = new Scene(); // Add the camera node to the scene. _scene.Children.Add(_cameraObject.CameraNode); // Load a model. This model uses the DigitalRune Model Processor. Several XML // files (*.drmdl and *.drmat) in the folder of dude.fbx define the materials and other properties. // The DigitalRune Model Processor also imports the animations of the dude model. var model = ContentManager.Load <ModelNode>("Dude/Dude"); // Add two clones of the model to the scene. _model0 = model.Clone(); _model1 = model.Clone(); _scene.Children.Add(_model0); _scene.Children.Add(_model1); // The dude model contains a single mesh node. var meshNode0 = (MeshNode)_model0.Children[0]; var meshNode1 = (MeshNode)_model1.Children[0]; // The imported animation data (skeleton and animations) is stored with the mesh. var animations = meshNode0.Mesh.Animations; // The MeshNodes of skinned models has a SkeletonPose which can be animated. // Let's start the first animation. var timeline0 = new TimelineClip(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, // Loop animation... Duration = TimeSpan.MaxValue, // ...forever. }; _animationController0 = AnimationService.StartAnimation(timeline0, (IAnimatableProperty)meshNode0.SkeletonPose); _animationController0.UpdateAndApply(); var timeline1 = new TimelineClip(animations.Values.First()) { LoopBehavior = LoopBehavior.Cycle, Duration = TimeSpan.MaxValue, // Start second animation at a different animation time to add some variety. Delay = TimeSpan.FromSeconds(-1), }; _animationController1 = AnimationService.StartAnimation(timeline1, (IAnimatableProperty)meshNode1.SkeletonPose); _animationController1.UpdateAndApply(); // Add some lights to the scene which have the same properties as the lights // of BasicEffect.EnableDefaultLighting(). InitializeDefaultXnaLights(_scene); _meshRenderer = new MeshRenderer(); var spriteFont = UIContentManager.Load <SpriteFont>("Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); }
public DebuggingComponent(Microsoft.Xna.Framework.Game game, IServiceLocator services) : base(game) { _inputService = services.GetInstance <IInputService>(); _graphicsService = services.GetInstance <IGraphicsService>(); _uiService = services.GetInstance <IUIService>(); // Get graphics service and add a DelegateGraphicsScreen as the first // graphics screen. This lets us do the rendering in the Render method of // this class. _graphicsScreen = new DelegateGraphicsScreen(_graphicsService) { RenderCallback = Render, }; _graphicsService.Screens.Insert(0, _graphicsScreen); // Load a UI theme and create a renderer. // We could use the same renderer as the "Default" screen (see StartScreenComponent.cs). // But usually, the debug screen will use a more efficient theme (smaller fonts, no // fancy graphics). Here, we simply use the Neoforce theme again. _uiContentManager = new ContentManager(services, "NeoforceTheme"); var theme = _uiContentManager.Load <Theme>("ThemeRed"); UIRenderer renderer = new UIRenderer(Game, theme); // Create a UIScreen and add it to the UI service. _uiScreen = new UIScreen("Debug", renderer) { // A transparent background. Background = new Color(0, 0, 0, 0), // The z-index is equal to the draw order. The z-index defines in which order the // screens are updated. This screen with the debug console should be updated before // the actual game under this screen. ZIndex = 10, // Hide the screen. The user has to press a button to make the debug screen visible. IsVisible = false, }; // Optional: // The debug screen handles gamepad input first, then the other screens and game components // can handle input. We do not want that the game is controllable when the debug screen is // visible, therefore we set the IsHandled flags when the screen is finished with the input. _uiScreen.InputProcessed += (s, e) => _inputService.SetGamePadHandled(LogicalPlayerIndex.Any, true); // Add a console control on the left. _console = new Console { HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Stretch, Width = 500, Margin = new Vector4F(20), }; _uiScreen.Children.Add(_console); // Print a few info messages in the console. _console.WriteLine("Press TAB or ChatPadGreen to display/hide console."); _console.WriteLine("Enter 'help' to view console commands."); // Add a custom command: _console.Interpreter.Commands.Add(new ConsoleCommand("greet", "greet [<name>] ... Prints a greeting message.", Greet)); // Add the screen to the UI service. _uiService.Screens.Add(_uiScreen); }
private readonly LensFlareRenderer _lensFlareRenderer; // Handles LensFlareNodes. public LensFlareSample(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 models to the scene. var ground = ContentManager.Load <ModelNode>("Ground/Ground").Clone(); _scene.Children.Add(ground); var box = ContentManager.Load <ModelNode>("MetalGrateBox/MetalGrateBox").Clone(); box.PoseLocal = new Pose(new Vector3(0.5f, 0.5f, 0.5f), Matrix.CreateRotationY(0.1f)); _scene.Children.Add(box); // Add some lights to the scene which have the same properties as the lights // of BasicEffect.EnableDefaultLighting(). SceneSample.InitializeDefaultXnaLights(_scene); // Add a lens flare for the sun light. var lensFlare = new LensFlare(true); // The sun is a directional light source. lensFlare.Name = "Sun Flare"; // The Size determines the screen size of the lens flare elements. The value // is relative to the viewport height. lensFlare.Size = 0.28f; // 0.28 * viewport height // The QuerySize of a directional light is the estimated size relative to the // viewport. This value is used in the hardware occlusion query, which determines // whether the lens flare is visible. lensFlare.QuerySize = 0.18f; // 0.18 * viewport height // All lens flare elements are packed into one texture ("texture atlas"). // The PackedTexture identifies an element within the texture atlas. // See file Media/LensFlare/LensFlares.png. // (Credits: The sun lens flare was copied from the XNA racing game - http://exdream.com/XnaRacingGame/.) var lensFlareTexture = ContentManager.Load <Texture2D>("LensFlare/LensFlares"); var circleTexture = new PackedTexture("Circle", lensFlareTexture, new Vector2F(0, 0), new Vector2F(0.25f, 0.5f)); var glowTexture = new PackedTexture("Glow", lensFlareTexture, new Vector2F(0.25f, 0), new Vector2F(0.25f, 0.5f)); var ringTexture = new PackedTexture("Ring", lensFlareTexture, new Vector2F(0.5f, 0), new Vector2F(0.25f, 0.5f)); var haloTexture = new PackedTexture("Halo", lensFlareTexture, new Vector2F(0.75f, 0), new Vector2F(0.25f, 0.5f)); var sunTexture = new PackedTexture("Sun", lensFlareTexture, new Vector2F(0, 0.5f), new Vector2F(0.25f, 0.5f)); var streaksTexture = new PackedTexture("Streaks", lensFlareTexture, new Vector2F(0.25f, 0.5f), new Vector2F(0.25f, 0.5f)); var flareTexture = new PackedTexture("Flare", lensFlareTexture, new Vector2F(0.5f, 0.5f), new Vector2F(0.25f, 0.5f)); // Add a few elements (circles, glow, rings, halos, streaks, ...) to the lens flare. lensFlare.Elements.Add(new LensFlareElement(-0.2f, 0.55f, 0.0f, new Color(175, 175, 255, 20), new Vector2F(0.5f, 0.5f), circleTexture)); lensFlare.Elements.Add(new LensFlareElement(0.0f, 0.9f, 0.0f, new Color(255, 255, 255, 255), new Vector2F(0.5f, 0.5f), sunTexture)); lensFlare.Elements.Add(new LensFlareElement(0.0f, 1.8f, 0.0f, new Color(255, 255, 255, 128), new Vector2F(0.5f, 0.5f), streaksTexture)); lensFlare.Elements.Add(new LensFlareElement(0.0f, 2.6f, 0.0f, new Color(255, 255, 200, 64), new Vector2F(0.5f, 0.5f), glowTexture)); lensFlare.Elements.Add(new LensFlareElement(0.5f, 0.12f, 0.0f, new Color(60, 60, 180, 35), new Vector2F(0.5f, 0.5f), circleTexture)); lensFlare.Elements.Add(new LensFlareElement(0.55f, 0.46f, 0.0f, new Color(100, 100, 200, 60), new Vector2F(0.5f, 0.5f), circleTexture)); lensFlare.Elements.Add(new LensFlareElement(0.6f, 0.17f, 0.0f, new Color(120, 120, 220, 40), new Vector2F(0.5f, 0.5f), circleTexture)); lensFlare.Elements.Add(new LensFlareElement(0.85f, 0.2f, 0.0f, new Color(60, 60, 255, 100), new Vector2F(0.5f, 0.5f), ringTexture)); lensFlare.Elements.Add(new LensFlareElement(1.5f, 0.2f, 0.0f, new Color(255, 60, 60, 130), new Vector2F(0.5f, 0.5f), flareTexture)); lensFlare.Elements.Add(new LensFlareElement(0.15f, 0.15f, 0.0f, new Color(255, 60, 60, 90), new Vector2F(0.5f, 0.5f), flareTexture)); lensFlare.Elements.Add(new LensFlareElement(1.3f, 0.6f, 0.0f, new Color(60, 60, 255, 180), new Vector2F(0.5f, 0.5f), haloTexture)); lensFlare.Elements.Add(new LensFlareElement(1.4f, 0.2f, 0.0f, new Color(220, 80, 80, 98), new Vector2F(0.5f, 0.5f), haloTexture)); lensFlare.Elements.Add(new LensFlareElement(1.5f, 0.1f, 0.0f, new Color(220, 80, 80, 85), new Vector2F(0.5f, 0.5f), circleTexture)); lensFlare.Elements.Add(new LensFlareElement(1.6f, 0.5f, 0.0f, new Color(60, 60, 255, 80), new Vector2F(0.5f, 0.5f), haloTexture)); lensFlare.Elements.Add(new LensFlareElement(1.8f, 0.3f, 0.0f, new Color(90, 60, 255, 110), new Vector2F(0.5f, 0.5f), ringTexture)); lensFlare.Elements.Add(new LensFlareElement(1.95f, 0.5f, 0.0f, new Color(60, 60, 255, 120), new Vector2F(0.5f, 0.5f), haloTexture)); lensFlare.Elements.Add(new LensFlareElement(2.0f, 0.15f, 0.0f, new Color(60, 60, 255, 85), new Vector2F(0.5f, 0.5f), circleTexture)); // The scene node "KeyLight" (defined in SceneSample.InitializeDefaultXnaLights()) // is the main directional light source. var keyLightNode = _scene.GetDescendants().First(n => n.Name == "KeyLight"); // Let's attach the lens flare to the "KeyLight" node. // (Note: It is not necessary to attach a lens flare to a light node. Lens flares // can be added anywhere within the scene. But attaching the lens flare to the // light node ensures that the lens flare always has the same position and direction // as the light source.) var lensFlareNode = new LensFlareNode(lensFlare); keyLightNode.Children = new SceneNodeCollection(); keyLightNode.Children.Add(lensFlareNode); // Add a second lens flare. // The previous lens flare was a caused by a directional light source (distance = infinite). // This time we add a local lens flare. lensFlare = new LensFlare(false); lensFlare.Name = "Anamorphic Flare"; lensFlare.Size = 0.3f; // 0.3 * viewport height // The QuerySize of a local lens flare is estimated size of the light source // in world space. lensFlare.QuerySize = 0.2f; // 0.2 meters // Add some elements (glow, horizontal streaks, ...) to the lens flare effect. var anamorphicFlareTexture = ContentManager.Load <Texture2D>("LensFlare/AnamorphicFlare"); flareTexture = new PackedTexture("AnamorphicFlare", anamorphicFlareTexture, new Vector2F(0, 0), new Vector2F(1.0f, 87f / 256f)); var flare1Texture = new PackedTexture("Flare0", anamorphicFlareTexture, new Vector2F(227f / 512f, 88f / 256f), new Vector2F(285f / 512f, 15f / 256f)); var flare2Texture = new PackedTexture("Flare1", anamorphicFlareTexture, new Vector2F(0, 87f / 256f), new Vector2F(226f / 512f, 168f / 256f)); lensFlare.Elements.Add(new LensFlareElement(0.0f, 0.8f, 0.0f, new Color(255, 255, 255, 255), new Vector2F(0.5f, 0.5f), flareTexture)); lensFlare.Elements.Add(new LensFlareElement(1.0f, new Vector2F(0.6f, 0.5f), 0.0f, new Color(172, 172, 255, 32), new Vector2F(0.5f, 0.5f), flare1Texture)); lensFlare.Elements.Add(new LensFlareElement(1.5f, 1.2f, float.NaN, new Color(200, 200, 255, 24), new Vector2F(0.5f, 0.2f), flare2Texture)); lensFlare.Elements.Add(new LensFlareElement(2.0f, 2.0f, float.NaN, new Color(172, 172, 255, 48), new Vector2F(0.5f, 0.2f), flare2Texture)); // Position the lens flare near the origin. lensFlareNode = new LensFlareNode(lensFlare); lensFlareNode.PoseWorld = new Pose(new Vector3(-0.5f, 1, 0)); _scene.Children.Add(lensFlareNode); // In this example we need two renderers: // The MeshRenderer handles MeshNodes. _meshRenderer = new MeshRenderer(); // The LensFlareRenderer handles LensFlareNodes. _lensFlareRenderer = new LensFlareRenderer(GraphicsService); }
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 Vector3(-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 Vector3(2, 0, 0), Matrix.CreateRotationY(ConstantsF.Pi)), ScaleLocal = new Vector3(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); }
public BillboardSample(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); // In this example we need three renderers: // The MeshRenderer handles MeshNodes. _meshRenderer = new MeshRenderer(); // The BillboardRenderer handles BillboardNodes and ParticleSystemNodes. _billboardRenderer = new BillboardRenderer(GraphicsService, 2048); // The DebugRenderer is used to draw text. var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); // Create a new empty scene. _scene = new Scene(); // Add the camera node to the scene. _scene.Children.Add(_cameraObject.CameraNode); // Add a few models to the scene. var sandbox = ContentManager.Load <ModelNode>("Sandbox/Sandbox").Clone(); _scene.Children.Add(sandbox); // Add some lights to the scene which have the same properties as the lights // of BasicEffect.EnableDefaultLighting(). SceneSample.InitializeDefaultXnaLights(_scene); var texture = new PackedTexture(ContentManager.Load <Texture2D>("Billboard/BillboardReference")); // ----- View plane-aligned billboards with variations. // View plane-aligned billboards are rendered parallel to the screen. // The up-axis of the BillboardNode determines the up direction of the // billboard. var pose0 = new Pose(new Vector3(-9, 1.0f, 1.5f)); var pose1 = pose0; var billboard = new ImageBillboard(texture); var billboardNode = new BillboardNode(billboard); billboardNode.Name = "View plane-aligned\nVarying color\nVarying alpha"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; billboardNode.Color = new Vector3(1, 0, 0); billboardNode.Alpha = 0.9f; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; billboardNode.Color = new Vector3(0, 1, 0); billboardNode.Alpha = 0.7f; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; billboardNode.Color = new Vector3(0, 0, 1); billboardNode.Alpha = 0.3f; _scene.Children.Add(billboardNode); // ----- View plane-aligned billboards with different blend modes // blend mode = 0 ... additive blend // blend mode = 1 ... alpha blend pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.BlendMode = 0.0f; billboardNode = new BillboardNode(billboard); billboardNode.Name = "View plane-aligned\nVarying blend mode"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.BlendMode = 0.333f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.BlendMode = 0.667f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.BlendMode = 1.0f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- View plane-aligned billboards with alpha test pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.AlphaTest = 0.9f; billboardNode = new BillboardNode(billboard); billboardNode.Name = "View plane-aligned\nVarying reference alpha"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.AlphaTest = 0.667f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.AlphaTest = 0.333f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboard = new ImageBillboard(texture); billboard.AlphaTest = 0.0f; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- View plane-aligned billboards with different scale and rotation pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.ViewPlaneAligned; billboardNode = new BillboardNode(billboard); billboardNode.Name = "View plane-aligned\nVarying scale\nVarying rotation"; billboardNode.PoseWorld = pose1; billboardNode.ScaleLocal = new Vector3(0.4f); _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = billboardNode.Clone(); billboardNode.Name = null; billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-15))); billboardNode.ScaleLocal = new Vector3(0.6f); _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = billboardNode.Clone(); billboardNode.Name = null; billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-30))); billboardNode.ScaleLocal = new Vector3(0.8f); _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = billboardNode.Clone(); billboardNode.Name = null; billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(-45))); billboardNode.ScaleLocal = new Vector3(1.0f); _scene.Children.Add(billboardNode); // ----- Viewpoint-oriented billboards // Viewpoint-orientated billboards always face the player. (The face normal // points directly to the camera.) pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.ViewpointOriented; billboardNode = new BillboardNode(billboard); billboardNode.Name = "Viewpoint-oriented"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- Screen-aligned billboards // View plane-aligned billboards and screen-aligned billboards are similar. The // billboards are rendered parallel to the screen. The orientation can be changed // by rotating the BillboardNode. The difference is that the orientation of view // plane-aligned billboards is relative to world space and the orientation of // screen-aligned billboards is relative to view space. // Screen-aligned billboards are, for example, used for text label. pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.ScreenAligned; billboardNode = new BillboardNode(billboard); billboardNode.Name = "Screen-aligned"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- Axial, view plane-aligned billboards pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.AxialViewPlaneAligned; billboardNode = new BillboardNode(billboard); billboardNode.Name = "Axial, view plane-aligned"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = billboardNode.Clone(); billboardNode.Name = null; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- Axial, viewpoint-oriented billboards pose0.Position.X += 2; pose1 = pose0; billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.AxialViewpointOriented; billboardNode = new BillboardNode(billboard); billboardNode.Name = "Axial, viewpoint-oriented"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // ----- World-oriented billboards // World-oriented billboards have a fixed orientation in world space. The // orientation is determine by the BillboardNode. pose0.Position.X += 2; pose1 = pose0; pose1.Orientation *= Matrix.CreateRotationY(0.2f); billboard = new ImageBillboard(texture); billboard.Orientation = BillboardOrientation.WorldOriented; billboardNode = new BillboardNode(billboard); billboardNode.Name = "World-oriented"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; pose1.Orientation *= Matrix.CreateRotationY(0.2f); billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(15))); _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; pose1.Orientation *= Matrix.CreateRotationY(0.2f); billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(30))); _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; pose1.Orientation *= Matrix.CreateRotationY(0.2f); billboardNode = new BillboardNode(billboard); billboardNode.PoseWorld = pose1 * new Pose(Matrix.CreateRotationZ(MathHelper.ToRadians(45))); _scene.Children.Add(billboardNode); // ----- Animated billboards // DigitalRune Graphics supports "texture atlases". I.e. textures can be packed // together into a single, larger texture file. A PackedTexture can describe a // single texture packed into a texture atlas or a tile set packed into a // texture atlas. In this example the "beeWingFlap" is a set of three tiles. // Tile sets can be used for sprite animations. (The animation is set below in // Update().) pose0.Position.X += 2; pose1 = pose0; texture = new PackedTexture("Bee", ContentManager.Load <Texture2D>("Particles/beeWingFlap"), Vector2F.Zero, Vector2F.One, 3, 1); _animatedBillboard = new ImageBillboard(texture); billboardNode = new BillboardNode(_animatedBillboard); billboardNode.Name = "Animated billboards"; billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(_animatedBillboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); pose1.Position.Z -= 1; billboardNode = new BillboardNode(_animatedBillboard); billboardNode.PoseWorld = pose1; _scene.Children.Add(billboardNode); // Use DebugRenderer to draw node names above billboard nodes. foreach (var node in _scene.GetDescendants().OfType <BillboardNode>()) { _debugRenderer.DrawText(node.Name, node.PoseWorld.Position + new Vector3(0, 1, 0), new Vector2F(0.5f), Color.Yellow, false); } }
public MeshNodeSample(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); // For advanced users: Set this flag if you want to analyze the imported opaque data of // effect bindings. //EffectBinding.KeepOpaqueData = true; // Load a model. The model is processed using the DigitalRune Model Processor - not // the default XNA model processor! // In the folder that contains tank.fbx, there is an XML file tank.drmdl which defines // properties of the model. These XML files are automatically processed by the // DigitalRune Model Processor. // Each model itself is a tree of scene nodes. The grid model contains one mesh // node. The tank model contains several mesh nodes (turret, cannon, hatch, // wheels, ...). _model = ContentManager.Load <ModelNode>("Tank/tank"); // The XNA ContentManager manages a single instance of each model. We clone // the model, to get a copy that we can modify without changing the original // instance. Cloning is fast because it only duplicates the scene nodes - but // not the mesh and material information. _model = _model.Clone(); // _model is the root of a tree of scene nodes. The mesh nodes are the child // nodes. When we scale or move the _model, we automatically scale and move // all child nodes. _model.ScaleLocal = new Vector3F(0.8f); _model.PoseWorld = new Pose(new Vector3F(0, 0, -2), Matrix33F.CreateRotationY(-0.3f)); // Let's loop through the mesh nodes of the model: foreach (var meshNode in _model.GetSubtree().OfType <MeshNode>()) { // Each MeshNode references a Mesh. Mesh mesh = meshNode.Mesh; // The mesh consists of several submeshes and several materials - usually // one material per submesh, but several submeshes could reference the same // materials. // Let's loop through the materials of this mesh. foreach (var material in mesh.Materials) { // A material is a collection of EffectBindings - one EffectBinding for each // render pass. For example, a complex game uses several render passes, like // a pre-Z pass, a G-buffer pass, a shadow map pass, a deferred material pass, // etc.In simple games there is only one pass which is called "Default". var effectBinding = material["Default"]; // An EffectBinding references an Effect (the XNA Effect class) and it has // "parameter bindings" and "technique bindings". These bindings select the // values for the shader parameters when the mesh node is rendered. // Let's change the binding for the DiffuseColor of the shader to give tank // a red color. effectBinding.Set("DiffuseColor", new Vector4(1, 0.7f, 0.7f, 1)); // The tank uses the default effect binding which is a BasicEffectBinding - this // effect binding uses the XNA BasicEffect. // In this sample we do not define any lights, therefore we disable the lighting // in the shader. ((BasicEffectBinding)effectBinding).LightingEnabled = false; } } _meshRenderer = new MeshRenderer(); var spriteFont = UIContentManager.Load <SpriteFont>("UI Themes/BlendBlue/Default"); _debugRenderer = new DebugRenderer(GraphicsService, spriteFont); }
public HealthBarSample(Microsoft.Xna.Framework.Game game) : base(game) { SampleFramework.IsMouseVisible = false; // The base class has created the graphics screen for the 3D objects. GraphicsScreen.ClearBackground = true; GraphicsScreen.BackgroundColor = Color.CornflowerBlue; SetCamera(new Vector3(0, 1, 3), 0, 0); _cameraObject = GameObjectService.Objects.OfType <CameraObject>().First(); // We add another graphics screen on top which renders the GUI. var graphicsScreen = new DelegateGraphicsScreen(GraphicsService) { RenderCallback = Render, }; GraphicsService.Screens.Insert(1, graphicsScreen); // Create a UIScreen. Theme theme = ContentManager.Load <Theme>("UI Themes/BlendBlue/Theme"); UIRenderer renderer = new UIRenderer(Game, theme); _uiScreen = new UIScreen("HealthBarScreen", renderer) { Background = Color.Transparent, // Background must not hide the 3D graphics screen. }; UIService.Screens.Add(_uiScreen); // Standard force effects. Simulation.ForceEffects.Add(new Gravity()); Simulation.ForceEffects.Add(new Damping()); // Standard game objects. GameObjectService.Objects.Add(new GroundObject(Services)); // Create a new game object property. This allows to attach a z value to all UIControls. _zPropertyId = UIControl.CreateProperty <float>( typeof(UIControl), "Z", GamePropertyCategories.Appearance, "The layer depth. Objects with lower depth value are in front.", 0.0f, UIPropertyOptions.AffectsRender); // Create 3D objects and a progress bar for each object. for (int i = 0; i < 10; i++) { var dynamicObject = new DynamicObject(Services, 1); GameObjectService.Objects.Add(dynamicObject); var progressBar = new ProgressBar { Value = RandomHelper.Random.NextFloat(0, 100), Maximum = 100, X = 100, Y = 100, Width = 100, Height = 20, Margin = new Vector4(-50, -10, 0, 0), // Use a margin to center the control. }; _uiScreen.Children.Add(progressBar); _objects.Add(new Pair <DynamicObject, ProgressBar>(dynamicObject, progressBar)); } }