コード例 #1
0
ファイル: ThickWireframe.cs プロジェクト: chuz/tesla-engine
        protected override void LoadContent()
        {
            Window.Title = "Thick Wireframes";
            Mesh teapot = new Teapot("Utah Teapot");

            teapot.SetScale(30f);
            teapot.Translation = new Vector3(0, -50, 0);
            teapot.Material    = ContentManager.Load <Material>("LitBasicColor.tem").Clone();
            teapot.Material.SetRenderState(RasterizerState.CullNone);

            Mesh wireframe = CreateWireframeData("Utah Wireframe", teapot.MeshData);

            wireframe.RenderBucketType = RenderBucketType.PostBucket;
            wireframe.Transform.Set(teapot.Transform);

            Material wireMat = new Material("WireMaterial");

            wireMat.LoadEffect(ContentManager.Load <Effect>("Shaders//WireframeEffect.fx").Clone());
            wireMat.SetEngineParameter("WVP", EngineValue.WorldViewProjection);
            wireMat.SetParameter("WinScale", new Vector2(Renderer.CurrentCamera.Viewport.Width / 2, Renderer.CurrentCamera.Viewport.Height / 2));
            wireMat.SetParameter("WireColor", new Vector3(.8f, .1f, .1f));
            wireMat.SetParameter("FillColor", new Vector4(.7f, .8f, .9f, .5f));
            wireMat.SetRenderState(BlendState.AlphaBlendNonPremultiplied);
            wireMat.SetRenderState(RasterizerState.CullNone);
            wireframe.SetMaterial(wireMat);

            RootNode.AddChild(teapot);
            RootNode.AddChild(wireframe);

            RootNode.AddController(new RotateController(Vector3.Up, 25));
        }
コード例 #2
0
ファイル: SceneGraphSample.cs プロジェクト: chuz/tesla-engine
        /// <summary>
        /// Please see the SceneGraph.rtf description for scene graph organization.
        /// </summary>
        protected override void LoadContent()
        {
            ClearColor   = Color.CornflowerBlue;
            Window.Title = "Scene Graph Sample";

            //Create the teapot sub-tree, we're also creating a small box showing the position of
            //the node in world space
            Node teapotParent       = new Node("TeapotParent");
            Box  teapotParentVisual = new Box("TeapotParentVisual", 1f, 1f, 1f);

            teapotParentVisual.Material = ContentManager.Load <Material>("LitBasicColor.tem").Clone();
            teapotParent.AddChild(teapotParentVisual);

            //Set a rotate controller onto the teapot parent, so it'll rotate every frame
            teapotParent.AddController(new RotateController(Vector3.UnitY, 25));

            //Create the teapot mesh
            Teapot teapot = new Teapot("Teapot");

            //Load up a default lit color material
            teapot.Material = ContentManager.Load <Material>("LitBasicColor.tem").Clone();
            //Create another rotate controller that will rotate the teapot about its X-Axis
            //45 degrees per second. This shows how we can -easily- concatenate transforms
            //using the hierarchy of the scene graph.
            teapot.AddController(new RotateController(Vector3.UnitX, 45f));

            //Set a red color to the material.
            teapot.Material.SetParameter("MatDiffuse", Color.Crimson.ToVector3());
            teapot.Scale = new Vector3(5f, 5f, 5f);

            //Position and add to parent
            teapot.Translation = new Vector3(-50, 0, 0);
            teapotParent.AddChild(teapot);

            //Add the teapot sub tree to the root.
            RootNode.AddChild(teapotParent);

            //Add a white light to the root node
            RootNode.RemoveAllLights();
            PointLight pl = new PointLight();

            pl.Attenuate = false;
            pl.Position  = new Vector3(-100, 50, 100);
            RootNode.AddLight(pl);

            //Create the box
            Box box = new Box("Box", 10, 10, 10);

            box.Translation = new Vector3(50, -50, 0);
            box.Material    = ContentManager.Load <Material>("LitBasicColor.tem").Clone();
            box.Material.SetParameter("MatDiffuse", Color.Gray.ToVector3());

            //Set the box to only use lights that are attached to it
            box.SceneHints.LightCombineHint = LightCombineHint.Local;

            //Create a green point light
            PointLight pl2 = new PointLight();

            pl2.Attenuate = false;
            pl2.Diffuse   = Color.Green;
            pl2.Position  = new Vector3(100, 50, 100);
            box.AddLight(pl2);

            //Add the box to the root
            RootNode.AddChild(box);

            //Set a bounding box to be used as the volume for each node/mesh in the scene graph.
            RootNode.SetModelBound(new BoundingBox());

            //Create some input handling to show how you can apply
            //a scaling value to a parent node (this case the scene Root),
            //and see it be applied to all children.
            InputLayer.RegisterTrigger(new InputTrigger(new KeyPressedCondition(Keys.J, false), new InputAction(delegate(GameTime time) {
                if (RootNode.Controllers.Count > 0)
                {
                    RootNode.RemoveAllControllers();
                    RootNode.SetScale(1.0f);
                    scaleOn = false;
                }
                else
                {
                    RootNode.AddController(new ScaleController(1.0f, .1f, 2.0f));
                    scaleOn = true;
                }
            })));

            batch = new SpriteBatch();
            font  = ContentManager.Load <SpriteFont>("Fonts//comicsans.fnt");
        }