コード例 #1
0
        //Loadup our content
        private void LoadContent()
        {
            //Create a root node
            _rootNode = new Node("Scene");

            //Simple point light
            PointLight pl = new PointLight();

            pl.Attenuate = false;
            pl.Position  = new Vector3(-20, 0, 20); //Put the light in the lower-left corner of the screen for this example
            _rootNode.AddLight(pl);

            //Create a rotating box
            Box box = new Box("Mybox", 10, 10, 10);

            //Set it 10 units down the -Z-axis
            box.Translation = new Vector3(0, 0, -10);
            //Add a controller that rotates it 25 degrees per second. This is updated every time the scene graph is updated.
            box.AddController(new RotateController(Vector3.UnitX, 25));
            //Create a material for the box, make sure we clone it otherwise we reuse the cached object
            box.Material = _content.Load <Material>("LitBasicColor.tem").Clone();
            //Set a red diffuse color to the effect parameter
            box.Material.SetParameter("MatDiffuse", Color.DarkRed.ToVector3());

            //Note on materials: You can programmatically create them, or define them in material files (.tem). Material files
            //can inherit from another, and you're able to set parameters, render states, and engine values. A benefit of TEM files
            //is that because you're describing them in a plain-text file, you can actually change how your objects are rendered without
            //writing code or re-compiling your application. They also serve as templates to streamline your content creation, since a lot
            //of your geometry may use the same material, or most of the same material (e.g. a color or texture change).

            _rootNode.AddChild(box);
        }
コード例 #2
0
        protected override void LoadContent()
        {
            Window.Title = "Render Target Sample";

            //Create the box we'll render off screen
            _offscreenCube          = new Box("Offscreen box", 10, 10, 10);
            _offscreenCube.Material = ContentManager.Load <Material>("LitBasicTexture.tem");
            _offscreenCube.Material.SetParameter("DiffuseMap", ContentManager.Load <Texture2D>("Textures//rock_diff.dds"));
            _offscreenCube.AddController(new RotateController(Vector3.Normalize(Vector3.Add(Vector3.Up, Vector3.Right)), 45.0f));

            PointLight pl = new PointLight();

            pl.Diffuse  = Color.CornflowerBlue;
            pl.Position = new Vector3(0, 25, 25);
            pl.Ambient  = Color.LightBlue;
            _offscreenCube.AddLight(pl);
            _offscreenCube.SceneHints.LightCombineHint = LightCombineHint.Local;
            _offscreenCube.RenderBucketType            = RenderBucketType.Skip;

            //Create a render target that also has a depth stencil.
            _renderTarget = new RenderTarget2D(512, 512, true, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

            //Camera we'll use for the off screen rendering
            _targetCamera          = new Camera(new Viewport(0, 0, 512, 512));
            _targetCamera.Position = new Vector3(0, 0, 50);
            _targetCamera.SetProjection(45.0f, 0.1f, 5000.0f);
            _targetCamera.Update();

            //Create a box that we'll attach to the scene graph and render as normal.
            _box          = new Box("OnScreen box", 50, 50, 50);
            _box.Material = ContentManager.Load <Material>("BasicTexture.tem");
            //Since render target is a texture, we can set it to the material's effect.
            _box.Material.SetParameter("DiffuseMap", _renderTarget);
            RootNode.AddChild(_box);
        }
コード例 #3
0
        protected override void LoadContent()
        {
            Window.Title = "Spatial Controller Sample";

            //Create a box with a simple color material
            Box box = new Box("MyBox", 20, 20, 20);

            box.Material = ContentManager.Load <Material>("LitBasicColor.tem");
            box.Material.SetParameter("MatDiffuse", Color.Crimson.ToVector3());
            //Set the custom controller to the box, this will get updated everytime the scene graph is updated.
            box.AddController(new RotateScaleController(.5f, new Vector2(.2f, 3), 45, Vector3.Up));
            RootNode.AddChild(box);
        }