コード例 #1
0
		//NEW CODE
		protected override void Initialise()
		{
			//draw targets usually need a camera.
			var camera = new Camera3D();
			//look at the sphere, which will be at 0,0,0
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY);


			//create the draw target texture in the same way the DrawSphere sample created the draw target screen
			//creates a 128x128 texture (the pixelation should be visible)
			drawToTexture = new DrawTargetTexture2D(camera, 128, 128, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

			//make the texture clear colour different from the screen, so it's more obvious
			drawToTexture.ClearBuffer.ClearColour = Color.WhiteSmoke;

			//create the sphere (reused from Tutorial_03)
			var sphere = new Tutorial_03.SphereDrawer(Vector3.Zero);

			//Note, the sphere is added to the texture, not the screen
			drawToTexture.Add(sphere);


			//now, create the drawToScreen object..

			//The same camera is being used, although it doesn't have to be.
			drawToScreen = new DrawTargetScreen(camera);
			drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue;


			var sizeInPixels = new Vector2(512,512);

			//Now create a 2D helper element that will display the texture on screen

			Xen.Ex.Graphics2D.TexturedElement displayTexture = null;

			//this helper class can directly take a DrawTargetTexture2D as a constructor parameter.

			//drawToTexture's Texture2D can be accessed with drawToTexture.GetTexture(),

			//However, at this point, drawToTexture.GetTexture() will be null - as the draw
			//target has yet to be drawn to.

			//drawToTexture.Warm() can be called, which will create the resources now.
			//However calling Warm() doesn't totally solve the problem because the texture 
			//will change when content needs reloading (this happens after a device reset, etc)

			//The 2D helper element takes care of this itself.
			//Content loading/reloading and dealing with GetTexture() will be covered in the next example.
			//for now, the helper class will handle things.

			//create the 2D helper element, which will display the texture on the screen.
			displayTexture = new TexturedElement(drawToTexture, sizeInPixels);

			//add it to the screen
			drawToScreen.Add(displayTexture);
		}
コード例 #2
0
		protected override void Initialise()
		{
			var camera = new Camera3D();
			//Look at the mesh
			camera.LookAt(new Vector3(0, 0, 0), new Vector3(4, 6, 2), new Vector3(0, 0, 1));

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

			//NEW CODE
			//create the actor instance
			var actor = new Actor(this.Content, Vector3.Zero);

			//add it to the screen
			drawToScreen.Add(actor);
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		protected override void Initialise()
		{
			//setup ambient lighting
			this.ambientLight = new MaterialLightCollection();
			ambientLight.LightingEnabled = true;
			ambientLight.AmbientLightColour = new Vector3(0.4f, 0.2f, 0.1f);
			ambientLight.CreateDirectionalLight(new Vector3(-1, -1, 0), new Vector3(3,2,1)); // add some backlighting
			ambientLight.SphericalHarmonic.AddLight(new Vector3(2, 0.5f, 0.25f), new Vector3(0, 0, 1), 0.2f);

			//the camera for the shadows point of view, represents the direction of the light.
			Camera3D shadowCamera = new Camera3D();
			shadowCamera.LookAt(new Vector3(1, 1, 3), new Vector3(-15, 20, 20), new Vector3(0, 0, 1));

			//set the clip plane distances
			shadowCamera.Projection.FarClip = 40;
			shadowCamera.Projection.NearClip = 20;
			shadowCamera.Projection.FieldOfView *= 0.25f;


			//8bit is actually enough accuracy for this sample (given the limited range of the shadow)
			var textureFormat = SurfaceFormat.Color;
			const int resolution = 256;

			//create the shadow map texture:
			drawShadowDepth = new DrawTargetTexture2D(shadowCamera, resolution, resolution, textureFormat, DepthFormat.Depth24);
			drawShadowDepth.ClearBuffer.ClearColour = Color.White;

			//for the shadow technique used, the shadow buffer is blurred.
			//this requires an intermediate render target on the PC
			DrawTargetTexture2D blurIntermediate = null;

			//technically not required on the xbox if the render target is small enough to fit in EDRAM in one tile, but xna insists
			blurIntermediate = new DrawTargetTexture2D(shadowCamera, resolution, resolution, textureFormat, DepthFormat.None);

			//create a blur filter
			shadowDepthBlurFilter = new Xen.Ex.Filters.BlurFilter(Xen.Ex.Filters.BlurFilterFormat.SevenSampleBlur,1.0f, drawShadowDepth, blurIntermediate);

			//create the scene camera
			var camera = new Camera3D();
			camera.LookAt(new Vector3(0, 0, 3), new Vector3(10, 10, 6), new Vector3(0, 0, 1));
			camera.Projection.FieldOfView *= 0.55f;

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

			//the 'scene'
			//A DrawList from Tutorial 23 is used here, this stores the 'scene', 
			//which is just a set of actors and the ground
			Tutorials.Tutorial_23.DrawList scene = new Tutorials.Tutorial_23.DrawList();

			for (int x = 0; x < 2; x++)
			for (int y = 0; y < 2; y++)
			{
				//create the actor instances
				if (x != 0 || y != 0)
					scene.Add(new Actor(this.Content, new Vector3(x*6-3, y*6-3, 0), (x + y*2 + 1) * 0.2f, 4-x*2-y));
			}

			//add the ground
			var ground = new GroundDisk(this.Content, 10, ambientLight);
			scene.Add(ground);


			//setup the draw targets...


			//create the shader provider
			var shadowOutputShaderProvider = new ShadowOutputShaderProvider();

			//add a ShadowMapDrawer to the shadow map texture
			drawShadowDepth.Add(new ShadowMapDrawer(scene, shadowOutputShaderProvider));

			//setup the scene to be drawn to the screen
			//draw the scene normally (no shadow, just ambient)
			drawToScreen.Add(scene);

			Vector3 lightColour = new Vector3(2, 1.5f, 1);

			//then draw the scene with a shadow (blended on top)
			drawToScreen.Add(new ShadowedSceneDrawer(scene, shadowOutputShaderProvider, drawShadowDepth, lightColour));

			//add a nice faded background
			Tutorial_20.BackgroundGradient background = new Tutorial_20.BackgroundGradient(new Color(1, 0.5f, 0.3f), new Color(0.2f, 0.1f, 0.2f));
			background.DrawAtMaxZDepth = true;
			drawToScreen.Add(background);


			//create a textured element that will display the shadow map texture
			var shadowDepthDisplay = new TexturedElement(drawShadowDepth, new Vector2(256, 256));
			shadowDepthDisplay.VerticalAlignment = VerticalAlignment.Top;
			this.drawToScreen.Add(shadowDepthDisplay);
		}
コード例 #5
0
		protected override void Initialise()
		{
			var camera = new Camera3D();

			//look at the sphere, which will be at 0,0,0. Look from 0,0,4. 
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY);

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

			//create the sphere at 0,0,0
			var sphere = new SphereDrawer(Vector3.Zero);

			//add it to be drawn to the screen
			drawToScreen.Add(sphere);
		}
コード例 #6
0
		protected override void Initialise()
		{
			var camera = new Camera3D();
			camera.LookAt(new Vector3(0, 0, 4), new Vector3(3, 4, 4), new Vector3(0, 0, 1));

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

			//NEW CODE
			//create the actor instance
			drawToScreen.Add(new Actor(this.Content, null));
		}
コード例 #7
0
		protected override void Initialise()
		{
			//draw targets usually need a camera.
			Camera3D camera = new Camera3D();
			//look at the geometry, which will be at 0,0,0
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY);

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

			//create the geometry
			GeometryDrawer geometry = new GeometryDrawer(Vector3.Zero);

			//add it to be drawn to the screen
			drawToScreen.Add(geometry);
		}
コード例 #8
0
		protected override void Initialise()
		{
			Camera3D camera = new Camera3D();
			camera.LookAt(new Vector3(0, 0, 4), new Vector3(3, 4, 4), new Vector3(0, 0, 1));

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

			//create the actor
			actor = new Actor(this.Content, this.UpdateManager);

			drawToScreen.Add(actor);

			text = new TextElement();
			text.Position = new Vector2(30, -30); // text is aligned to the top left by default

			drawToScreen.Add(text);
		}
コード例 #9
0
		protected override void Initialise()
		{
			//draw targets usually need a camera.
			Camera3D camera = new Camera3D();
			//look at the sphere, which will be at 0,0,0
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY);

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

			//create the sphere
			SphereDrawer sphere = new SphereDrawer(Vector3.Zero);


			//before adding the sphere, add a rect over half the background to show blending is active

			//element covers half the screen
			SolidColourElement element = new SolidColourElement(Color.DarkGray, new Vector2(0.5f, 1), true);
			//element is added before the sphere (so it draws first)
			drawToScreen.Add(element);

			//add it to be drawn to the screen
			drawToScreen.Add(sphere);
		}
コード例 #10
0
		protected override void Initialise()
		{
			//Xen.Ex provides a very useful Camera3D called 'FirstPersonControlledCamera3D'.
			//This camera uses player input to act as a simple first-person style flythrough camera
			Xen.Camera.FirstPersonControlledCamera3D camera = null;

			//it uses player input, so the UpdateManager must be passed in
			camera = new Xen.Camera.FirstPersonControlledCamera3D(this.UpdateManager);

			//in this case, we want the z-axis to be the up/down axis (otherwise it's the Y-axis)
			camera.ZAxisUp = true;
			//also it's default is a bit too fast moving
			camera.MovementSensitivity *= 0.1f;
			camera.LookAt(new Vector3(1, 0, 0), new Vector3(), new Vector3(0, 0, 1));

			this.camera = camera;

			//create the draw target.
			drawToScreen = new DrawTargetScreen(camera);


			//create a large number of actor instance from tutorial 10..
			for (int n = 0; n <= 16; n++)
			{
				//create in a half circle
				float angle = (n / 16.0f) * MathHelper.Pi;
				var position = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0);

				//not too close together
				position *= 10;

				drawToScreen.Add(new Tutorial_10.Actor(this.Content, position));
			}


			//this element will display the camera position
			positionDisplay = new TextElement();

			//TextElement (unlike other Elements) defaults to Top Left alignment
			//So, in order to bring it closer to the centre of the screen (due to potential overscan)
			//it's position needs to be set 'right' and 'down' from 'top left'
			//(this is just an example, see XNA docs for correct overscan compensation behaviour)
			positionDisplay.Position = new Vector2(40, -40); //offset from top left corner alignment

			//add it to the screen
			drawToScreen.Add(positionDisplay);



			var sizeInPixels = new Vector2(400, 200);

			//create the main block of yellow text
			this.yellowElement = new TextElementRect(sizeInPixels);
			this.yellowElement.Colour = Color.Yellow;

			//first line of text... this will have a flashing 2D element embedded
			string embeddedText = @"This is a text box with a large amount of custom text! It also includes an embedded 2D element: , which is a 16x16 SolidColourElement";
			uint insertAtIndex = 96; // Hard coded to insert a 2D element at character index 96               which is about here: ^

			//add a bunch of text...
			this.yellowElement.Text.AppendLine(embeddedText);
			this.yellowElement.Text.AppendLine();
			this.yellowElement.Text.AppendLine(@"This class is:");
			this.yellowElement.Text.AppendLine(this.GetType().FullName);
			this.yellowElement.Text.AppendLine(@"It is located in assembly:");
			this.yellowElement.Text.AppendLine(this.GetType().Assembly.FullName);
			this.yellowElement.Text.AppendLine();

			//add an embedded 2D element within the text
			//create it..
			this.embeddedElement = new SolidColourElement(Color.Red, new Vector2(16, 16)); // quite small
			this.embeddedElement.AlphaBlendState = AlphaBlendState.Alpha;
			//add it.
			this.yellowElement.AddInline(this.embeddedElement, insertAtIndex);


#if XBOX360
			this.yellowElement.Text.AppendLine(@"Press and hold both thumbsticks to show the debug overlay");
#else
			this.yellowElement.Text.AppendLine(@"Press F12 to show the debug overlay");
#endif


			//align the element rectangle to the bottom centre of the screen
			this.yellowElement.VerticalAlignment = VerticalAlignment.Bottom;
			this.yellowElement.HorizontalAlignment = HorizontalAlignment.Centre;

			//centre align the text
			this.yellowElement.TextHorizontalAlignment = TextHorizontalAlignment.Centre;
			//centre the text in the middle of the 400x200 area of the element rectangle
			this.yellowElement.TextVerticalAlignment = VerticalAlignment.Centre;

			//add it to the screen
			drawToScreen.Add(yellowElement);




			//create the statistics display
			//this class will query the DrawState for the previous frames DrawStatistics structure.
			//this structure provides a large number of statistics for the drawn frame.
			//The DrawStatisticsDisplay displays some of the more important statistics. It will also
			//display thread activity on the xbox.

			//DrawStatistics are only available in DEBUG xen builds
			//They can be accessed at runtime with DrawState GetPreviousFrameStatistics()

			//at runtime, pressing 'F12' will toggle the overlay (or holding both thumbsticks on x360)
			this.statisticsOverlay = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager);

			//then add it to the screen
			drawToScreen.Add(statisticsOverlay);
		}
コード例 #11
0
		protected override void Initialise()
		{
			Camera3D camera = new Camera3D();
			camera.LookAt(new Vector3(0, 1, 0), new Vector3(0.5f, 1, -1), new Vector3(0, 1, 0));
			camera.Projection.NearClip = 0.1f;

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

			bool contentLoaded;

			//create the avatar instance
			drawToScreen.Add(new Avatar(this.Content, this.UpdateManager, out contentLoaded));

#if XBOX
			text = new TextElement(@"Press 'A' to display a new Avatar" + Environment.NewLine + "Press 'B' to play the 'Cheer' animation.");
#else
			text = new TextElement(@"Unfortunately, avatars are only supported on the XBOX...." + Environment.NewLine + "AvatarInstance will display a wireframe of an avatar skeleton, using any FBX imported animations." + Environment.NewLine + "XNA preset animations cannot be displayed in this wireframe mode.");
#endif
			if (!contentLoaded)
			{
				//could not load the animation... user needs to download it themselves
				text.Text.AppendLine();
				text.Text.AppendLine(@"ERROR: An additional download is required!");
				text.Text.AppendLine(@"Avatar walk animation could not be loaded! See code comments for details!");
				text.Colour = Color.Red;
			}

			text.Position = new Vector2(50, -50);
			drawToScreen.Add(text);
		}
コード例 #12
0
		protected override void Initialise()
		{
			//draw target camera.
			var camera = new Camera3D();
			camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY);


			//create the draw target texture
			//actual graphics resources are not created yet...
			drawToTexture = new DrawTargetTexture2D(camera, 128, 128, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);

			//make the texture clear colour different from the screen, so it's more obvious
			drawToTexture.ClearBuffer.ClearColour = Color.WhiteSmoke;

			//add a sphere from tutorial 03 to the texture
			drawToTexture.Add(new Tutorial_03.SphereDrawer(Vector3.Zero));



			var sizeInPixels = new Vector2(512,512);

			//NEW CODE
			//create the helper element, but don't give it a texture yet..
			displayElement = new TexturedElement(sizeInPixels);



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

			//add the helper element to the screen
			drawToScreen.Add(displayElement);
		}