Ejemplo n.º 1
0
        protected override void Initialise()
        {
            Resource.EnableResourceTracking();


            Camera3D camera = new Camera3D();

            camera.LookAt(Vector3.Zero, new Vector3(0, 0, 5), Vector3.UnitY);

            //create the draw target.
            drawToScreen = new DrawTargetScreen(this, camera);
            drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue;



            //create a shader to display the geometry (this is the same as tutorial 02)
            Vector3        lightDirection = new Vector3(1.0f, 0.5f, 0.5f);
            MaterialShader material       = new MaterialShader(new MaterialLightCollection());

            material.UsePerPixelSpecular       = true;
            material.Lights.AmbientLightColour = Color.CornflowerBlue.ToVector3() * 0.5f;               //set the ambient
            material.Lights.AddDirectionalLight(true, lightDirection, Color.Gray);                      //add the first of two light sources
            material.Lights.AddDirectionalLight(true, -lightDirection, Color.DarkSlateBlue);
            material.SpecularColour = Color.LightYellow.ToVector3();                                    //give the material a nice sheen

            //create a simpler shader to display the wireframe (and also used for the bounding cube)
            Xen.Ex.Shaders.FillSolidColour simpleShader = new Xen.Ex.Shaders.FillSolidColour();
            simpleShader.FillColour = Vector4.One * 0.01f;


            Vector3 sphereSize = new Vector3(0.5f, 0.5f, 0.5f);

            //create the complex sphere, this will have ~100k triangles.
            //pass in a shader for wireframe rendering
            sphere = new GeometryDrawer(new Xen.Ex.Geometry.Sphere(sphereSize, 200), material, simpleShader);

            //create the bounding cube
            sphereBoundingBox = new GeometryDrawer(new Xen.Ex.Geometry.Cube(sphereSize), simpleShader, null);

            //create the occluding cube, and position it close to the camera
            cube          = new GeometryDrawer(new Xen.Ex.Geometry.Cube(Vector3.One), material, null);
            cube.position = new Vector3(0, 0, 2.75f);


            //add the cube first (so it can draw first, potentially occluding the sphere)
            //if the cube was added second, it would have no effect, as it would draw after the sphere
            drawToScreen.Add(cube);


            //create the predicate, passing in the sphere and bounding box
            Xen.Ex.Scene.DrawPredicate predicate = new Xen.Ex.Scene.DrawPredicate(sphere, sphereBoundingBox);

            //add the DrawPredicate (the DrawPredicate draws it's children)
            drawToScreen.Add(predicate);


            //statistic overlay
            statOverlay = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
            drawToScreen.Add(statOverlay);
        }
		protected override void Initialise()
		{
			Camera3D camera = new Camera3D();
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 5), Vector3.UnitY);

			//create the draw target.
			drawToScreen = new DrawTargetScreen(camera);
			drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue;



			//create a shader to display the geometry (this is the same as tutorial 02)
			var lightDirection = new Vector3(1.0f, 0.5f, 0.5f);
			var material = new MaterialShader();
			material.SpecularColour = Color.LightYellow.ToVector3();				//give the material a nice sheen

			var lights = new MaterialLightCollection();

			lights.AmbientLightColour = Color.CornflowerBlue.ToVector3() * 0.5f;	//set the ambient
			lights.CreateDirectionalLight(lightDirection, Color.Gray);				//add the first of two light sources
			lights.CreateDirectionalLight(-lightDirection, Color.DarkSlateBlue);

			material.LightCollection = lights;

			//create a simpler shader to display the wireframe (and also used for the bounding cube)
			var simpleShader = new Xen.Ex.Shaders.FillSolidColour();
			simpleShader.FillColour = Vector4.One * 0.01f;


			var sphereSize = new Vector3(0.5f, 0.5f, 0.5f);

			//create the complex sphere, this will have ~100k triangles.
			//pass in a shader for wireframe rendering
			sphere = new GeometryDrawer(new Xen.Ex.Geometry.Sphere(sphereSize, 200), material, simpleShader);

			//create the bounding cube
			sphereBoundingBox = new GeometryDrawer(new Xen.Ex.Geometry.Cube(sphereSize), simpleShader, null);

			//create the occluding cube, and position it close to the camera
			cube = new GeometryDrawer(new Xen.Ex.Geometry.Cube(Vector3.One), material, null);
			cube.position = new Vector3(0, 0, 2.75f);


			//add the cube first (so it can draw first, potentially occluding the sphere)
			//if the cube was added second, it would have no effect, as it would draw after the sphere
			drawToScreen.Add(cube);


			//create the predicate, passing in the sphere and bounding box
			var predicate = new Xen.Ex.Scene.DrawPredicate(sphere, sphereBoundingBox);

			//add the DrawPredicate (the DrawPredicate draws it's children)
			drawToScreen.Add(predicate);


			//statistic overlay
			statOverlay = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);
			drawToScreen.Add(statOverlay);
		}