Пример #1
0
        //load the avatar
        public Avatar(ContentRegister content, UpdateManager update)
        {
            //create a random avatar description...
            Microsoft.Xna.Framework.GamerServices.AvatarDescription description;
            description = Microsoft.Xna.Framework.GamerServices.AvatarDescription.CreateRandom();

            //Create the avatar instance
            avatar = new AvatarInstance(description, true);


            //Create the animation controller.
            animationController = avatar.GetAnimationController();

            //NOTE: Animations cannot be played until the avatar animation data has been loaded...
            content.Add(this);             // this will call LoadContent
            update.Add(this);

            //At this point in this tutorial, the animation is now loaded.

            //get the index of the walk animation
            int animationIndex = animationController.AnimationIndex("Walk");

            //begin playing the animation, looping
            walkAnimation = animationController.PlayLoopingAnimation(animationIndex);
        }
Пример #2
0
        //construct the displayer.
        //Because this class needs to load content, a ContentRegister is a required
        //constructor parameter. This makes sure it will always load content
        public ImageDisplayer(ContentRegister contentRegister)
        {
            if (contentRegister == null)
            {
                throw new ArgumentNullException();
            }

            //create the element that will display the texture
            Vector2 sizeInPixels = new Vector2(768, 384);

            //create an instance of the shader
            //The texture will be assigned to the shader in LoadContent
            this.shader = new Shader.Tutorial09Technique();

            //create the element which will display the shader
            this.element = new ShaderElement(shader, sizeInPixels);

            //place the element in the centre of the screen
            this.element.HorizontalAlignment = HorizontalAlignment.Centre;
            this.element.VerticalAlignment   = VerticalAlignment.Centre;

            //add this object to the content register
            //items added to a content register do not need to be removed, as they
            //are tracked by a weak reference.
            //LoadContent() will be called whenever the device is created/reset.
            contentRegister.Add(this);

            //At this point, since the device has been created, LoadContent() will have
            //been called already. If the device hadn't been created yet, then
            //LoadContent() would be called at a later time.

            //LoadContent() will always be called before the first time Draw() is called.
        }
Пример #3
0
        public Skydome(ContentRegister content, Vector3 position, float scale)
        {
            model = new ModelInstance();

            Matrix.CreateTranslation(ref position, out worldMatrix);
            Matrix.CreateScale(scale, out scaleMatrix);

            content.Add(this);
        }
Пример #4
0
		public Scene(ContentRegister content, Camera3D camera)
		{
			this.camera = camera;

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

			InitializePhysics();

			content.Add(this);
		}
Пример #5
0
        public Actor(ContentRegister content, Vector3 position)
        {
            Matrix.CreateTranslation(ref position, out this.worldMatrix);

            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set

            model = new ModelInstance();

            //add to the content register
            content.Add(this);
        }
Пример #6
0
        public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex)
        {
            Matrix.CreateRotationZ(1 - (float)animationIndex, out this.worldMatrix);
            this.worldMatrix.Translation = position;

            model = new ModelInstance();
            this.animationController = model.GetAnimationController();

            content.Add(this);

            this.animation = this.animationController.PlayLoopingAnimation(animationIndex);
            this.animation.PlaybackSpeed = animationSpeed;
        }
Пример #7
0
        public RenderConfigEditor(ContentRegister content)
        {
            //setup the text elements
            this.stateText         = new List <TextElement>();
            this.visibleElementGap = new List <bool>();

#if XBOX360
            this.helpText = new TextElement("Use 'A' and the DPad to interact with the menu");
#else
            this.helpText = new TextElement("Use the Arrow Keys and 'Enter' to interact with the menu");
#endif
            this.helpText.HorizontalAlignment = HorizontalAlignment.Left;
            this.helpText.VerticalAlignment   = VerticalAlignment.Bottom;
            this.helpText.Colour = Color.Black;

            this.backgroundContainer = new SolidColourElement(new Color(0, 0, 0, 200), new Vector2(0, 0));
            this.backgroundContainer.AlphaBlendState = Xen.Graphics.State.AlphaBlendState.Alpha;

            foreach (string name in ConfigProperties.Keys)
            {
                //create the text
                TextElement text = new TextElement();

                //if it's a ediable value, then put a '[X]' infront
                if (ConfigProperties[name].CanRead)
                {
                    text.Text.SetText("[ ] " + name);
                }
                else
                {
                    text.Text.SetText(name);
                }

                text.VerticalAlignment = VerticalAlignment.Bottom;
                this.stateText.Add(text);

                bool gap = false;
                if (ConfigProperties[name].GetCustomAttributes(typeof(RenderConfiguration.GapAttribute), false).Length > 0)
                {
                    gap = true;
                }

                this.visibleElementGap.Add(gap);
            }

            //select top instance
            this.editSelection = this.stateText.Count - 1;

            //sizes of the elements are setup in LoadContent()
            content.Add(this);
        }
Пример #8
0
        /// <summary>
        /// create a new actor
        /// </summary>
        /// <param name="content"></param>
        /// <param name="modelfile">model file to be loaded</param>
        /// <param name="position">position</param>
        /// <param name="scale_factor">scale</param>
        public Actor(ContentRegister content,String modelfile, Vector3 position, float scale_factor)
        {
            this.scale = scale_factor;
            this.position = position;

            Matrix.CreateTranslation(ref position, out this.worldMatrix);
            Matrix.CreateScale(scale_factor,out this.scaleMatrix);

            this.filename = modelfile;

            this.model = new ModelInstance();

            content.Add(this);
        }
Пример #9
0
        public Actor(ContentRegister content)
        {
            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set

            model = new ModelInstance();

            content.Add(this);

            //play an animation
            model.GetAnimationController().PlayLoopingAnimation(3);

            //This method creates a Cube for each bone in the mesh
            BuildBoundingBoxGeometry();
        }
		public Actor(ContentRegister content)
		{
			//A ModelInstance can be created without any content...
			//However it cannot be used until the content is set

			model = new ModelInstance();

			content.Add(this);

			//play an animation
			model.GetAnimationController().PlayLoopingAnimation(3);

			//This method creates a Cube for each bone in the mesh
			BuildBoundingBoxGeometry();
		}
Пример #11
0
        public SimpleTerrain(ContentRegister content, Vector3 position, string modelDataName)
        {
            this.modelDataName = modelDataName;

            //Matrix.CreateTranslation(ref position, out this.worldMatrix);
            this.worldMatrix = Matrix.CreateTranslation(position);// *Matrix.CreateScale(2.0f); // needed for physics

            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set
            this.model = new ModelInstance();

            this.terrainShader = new Shaders.SimpleTerrain();

            PickingDrawer = new LightSourceDrawer(Vector3.Zero, new Xen.Ex.Geometry.Sphere(new Vector3(3), 8, true, false, false), Color.Red);

            //add to the content register and load textures/etc
            content.Add(this);
        }
		//load the avatar
		public Avatar(ContentRegister content, UpdateManager update, out bool contentLoaded)
		{
			//create a random avatar description...
			Microsoft.Xna.Framework.GamerServices.AvatarDescription description;
			description = Microsoft.Xna.Framework.GamerServices.AvatarDescription.CreateRandom();

			//Create the avatar instance
			avatar = new AvatarInstance(description, true);


			//Create the animation controller.
			animationController = avatar.GetAnimationController();

			//NOTE: Animations cannot be played until the avatar animation data has been loaded...
			update.Add(this);

			//to play animations from a file, the user must download additional content.
			//however, we don't want to crash if they haven't... so only crash if the debugger is present
			//this will allow the user to download the content.
			contentLoaded = false;

			try
			{
				content.Add(this);
				contentLoaded = true;
			}
			catch
			{
				content.Remove(this);	//failed! but don't crash
			}

			if (contentLoaded)
			{
				//At this point in this tutorial, the animation is now loaded.

				//get the index of the walk animation
				int animationIndex = animationController.AnimationIndex("Walk");

				//begin playing the animation, looping
				walkAnimation = animationController.PlayLoopingAnimation(animationIndex);
			}
		}
Пример #13
0
        public GroundDisk(ContentRegister content, float radius, MaterialLightCollection lights)
        {
            //build the disk
            VertexPositionNormalTexture[] vertexData = new VertexPositionNormalTexture[256];

            for (int i = 0; i < vertexData.Length; i++)
            {
                //a bunch of vertices, in a circle!
                float   angle    = (float)i / (float)vertexData.Length * MathHelper.TwoPi;
                Vector3 position = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0);

                vertexData[i] = new VertexPositionNormalTexture(position * radius, new Vector3(0, 0, 1), new Vector2(position.X, position.Y));
            }
            this.vertices = new Vertices <VertexPositionNormalTexture>(vertexData);

            //create the material, and add to content
            this.material        = new MaterialShader();
            this.material.Lights = lights;
            content.Add(this);
        }
		public Actor(ContentRegister content, Vector3 position)
		{
			//set the world matrix
			Matrix.CreateTranslation(ref position, out this.worldMatrix);

			//A ModelInstance can be created without any content...
			//However it cannot be used until the content is set

			this.model = new ModelInstance();

			//Note:
			// When a model is drawn, by default it will bind and use a MaterialShader.
			// This shader uses the material properties stored in the original mesh.
			// If you don't want to use the MaterialShader, simply set the property
			// model.ShaderProvider to null.
			

			//add to the content register
			content.Add(this);
		}
		//NEW CODE
		public Actor(ContentRegister content, MaterialLightCollection lights)
		{
			//A ModelInstance can be created without any content...
			//However it cannot be used until the content is set

			model = new ModelInstance();
			model.LightCollection = lights;	//this class is reused by later tutorials, which require lights

			//get and create the animation controller for this model.
			animationController = model.GetAnimationController();

			//NOTE: Animations cannot be played until the model data has been loaded...

			content.Add(this);

			//At this point in this tutorial, the model is now loaded.

			//get the index of the walk animation
			//this model has 4 animations, Wave, Jog, Walk and Loiter
			//The animations are stored in model.ModelData.Animations
			int animationIndex = animationController.AnimationIndex("Walk");

			//begin playing the animation, looping
			animation = animationController.PlayLoopingAnimation(animationIndex);

			//as many animations as you want can be played at any one time
			//to blend between animations, adjust their weighting with:
			//animation.Weighting = ...;
			//Combined weightings usually should add up to 1.0
			//A weighting of 0 means the animation has no effect, 1 has normal effect.
			//Values outside the 0-1 range usually produces undesirable results.

			//Note:
			//Animations in xen are lossy compressed.
			//For the model used here, the animation data is reduced from nearly 2mb
			//down to around 200kb. (The model geometry is less than 300kb)
			//The amount of compression change can be configured in the content's properties
			//The 'Animation Compression Tolerance' value is a percentage
			//The default is .5%. This means the animation will always be within .5%
			//of the source. Setting this value to 0 will save a lossless animation.
		}
Пример #16
0
        public GroundDisk(ContentRegister content, MaterialLightCollection lights, float radius)
        {
            this.radius = radius;

            int vertexCount = 256;

            //create the vertices. Note the DiskVertex() constructor takes an angle/size
            DiskVertex[] verts = new DiskVertex[vertexCount];
            for (int i = 0; i < vertexCount; i++)
            {
                verts[i] = new DiskVertex((i / (float)(vertexCount - 1)) * MathHelper.TwoPi, radius, 0.05f);
            }

            //create the vertex buffer
            this.vertices = new Vertices <DiskVertex>(verts);


            //create the custom material for this geometry
            //the light collection has been passed into the constructor, although it
            //could easily be changed later (by changing material.Lights)
            this.material = new MaterialShader(lights);

            //By default, per-pixel lighting in the material shader does not do
            //specular reflection. This is because specular nearly triples the
            //complexity of the lighting calculation - which makes rendering slower
            //and reduces the maximum number of per-pixel lights supported from 4 to 2.
            material.UsePerPixelSpecular = true;

            //give the disk really bright specular for effect
            material.SpecularColour = new Vector3(1, 1, 1);
            material.DiffuseColour  = new Vector3(0.6f, 0.6f, 0.6f);
            material.SpecularPower  = 64;

            //setup the texture samples to use high quality anisotropic filtering
            material.TextureMapSampler = TextureSamplerState.AnisotropicHighFiltering;
            material.NormalMapSampler  = TextureSamplerState.AnisotropicLowFiltering;

            //load the textures for this material
            content.Add(this);
        }
Пример #17
0
        //NEW CODE
        public Actor(ContentRegister content)
        {
            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set

            model = new ModelInstance();

            //create the animation controller.
            animationController = model.GetAnimationController();

            //NOTE: Animations cannot be played until the model data has been loaded...

            content.Add(this);

            //At this point in this tutorial, the model is now loaded.

            //get the index of the walk animation
            //this model has 4 animations, Wave, Jog, Walk and Loiter
            //The animations are stored in model.ModelData.Animations
            int animationIndex = animationController.AnimationIndex("Walk");

            //begin playing the animation, looping
            animation = animationController.PlayLoopingAnimation(animationIndex);

            //as many animations as you want can be played at any one time
            //to blend between animations, adjust their weighting with:
            //animation.Weighting = ...;
            //Combined weightings usually should add up to 1.
            //A weighting of 0 means the animation has no effect, 1 has normal effect.
            //Values outside the 0-1 range usually produces undesirable results.

            //Note:
            //Animations in xen are lossy compressed.
            //For the model used here, the animation data is reduced from nearly 2mb
            //down to around 200kb. (The model geometry is less than 300kb)
            //The amount of compression change can be configured in the content's properties
            //The 'Animation Compression Tolerance' value is a percentage
            //The default is .5%. This means the animation will always be within .5%
            //of the source. Setting this value to 0 will save a lossless animation.
        }
Пример #18
0
        public Actor(ContentRegister content, UpdateManager updateManager)
        {
            //load the model
            model = new ModelInstance();
            content.Add(this);

            //create the animation controller
            animationController = model.GetAsyncAnimationController(updateManager);

            //NEW CODE
            //create the animation modifier

            int rotateBoneIndex = model.ModelData.Skeleton.GetBoneIndexByName("Bip01_Spine2");

            this.animationModifer = new AnimationModifier(rotateBoneIndex, model.ModelData);

            //set the modifier on the animation controller
            this.animationController.AnimationBoneModifier = this.animationModifer;

            //play the run animation
            int animationIndex = animationController.AnimationIndex("Jog");

            this.animation = animationController.PlayLoopingAnimation(animationIndex);
        }
Пример #19
0
        private bool worldMatrixDirty = true;         // set to true if worldMatrix is no longer valid, see 'UpdateWorldMatrix()'

        //create the actor
        public Actor(ContentRegister content, UpdateManager updateManager, MaterialLightCollection lights, float groundRadius)
        {
            this.groundRadius = groundRadius;

            model = new ModelInstance();
            model.LightCollection = lights;

            //random starting position
            position = GetRandomPosition();

            //initially target the current position
            //the 'move to next target' timer will wind down and then the actor will move
            target = position;

            //randomize a bit
            lookAngle = (float)random.NextDouble() * MathHelper.TwoPi;
            moveSpeed = (float)random.NextDouble() * 0.9f + 0.1f;

            content.Add(this);
            updateManager.Add(this);


            InitaliseAnimations(updateManager);
        }
		public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex)
		{
			Matrix.CreateRotationZ(1-(float)animationIndex, out this.worldMatrix);
			this.worldMatrix.Translation = position;

			model = new ModelInstance();
			this.animationController = model.GetAnimationController();

			content.Add(this);

			this.animation = this.animationController.PlayLoopingAnimation(animationIndex);
			this.animation.PlaybackSpeed = animationSpeed;
		}
		public GroundDisk(ContentRegister content, MaterialLightCollection lights, float radius)
		{
			this.radius = radius;

			int vertexCount = 256;
			var indices = new List<int>();

			//create the vertices. Note the DiskVertex() constructor takes an angle/size
			var verts = new DiskVertex[vertexCount];

			for (int i = 0; i < vertexCount; i++)
			{
				verts[i] = new DiskVertex((i / (float)(vertexCount - 1)) * MathHelper.TwoPi, radius, 0.05f);
				
				if (i != 0)	//add the tirangle indices
				{
					indices.Add(0);
					indices.Add(i - 1);
					indices.Add(i);
				}
			}

			//create the vertex buffer
			this.vertices = new Vertices<DiskVertex>(verts);
			this.indices = new Indices<int>(indices);


			//create the custom material for this geometry
			//the light collection has been passed into the constructor, although it
			//could easily be changed later (by changing material.Lights)
			this.Material = new MaterialShader(lights);
			
			//give the disk really bright specular for effect
			Material.SpecularColour = new Vector3(1,1,1);
			Material.DiffuseColour = new Vector3(0.6f, 0.6f, 0.6f);
			Material.SpecularPower = 64;

			//setup the texture samples to use high quality anisotropic filtering
			//the textures are assigned in LoadContent
			Material.Textures = new MaterialTextures();
			Material.Textures.TextureMapSampler = TextureSamplerState.AnisotropicHighFiltering;
			Material.Textures.NormalMapSampler = TextureSamplerState.AnisotropicLowFiltering;

			//load the textures for this material
			content.Add(this);
		}
		public Actor(ContentRegister content, UpdateManager updateManager)
		{
			//load the model
			model = new ModelInstance();
			content.Add(this);

			//create the animation controller
			animationController = model.GetAsyncAnimationController(updateManager);

			//NEW CODE
			//create the animation modifier

			int rotateBoneIndex = model.ModelData.Skeleton.GetBoneIndexByName("Bip01_Spine2");
			this.animationModifer = new AnimationModifier(rotateBoneIndex, model.ModelData);

			//set the modifier on the animation controller
			this.animationController.AnimationBoneModifier = this.animationModifer;

			//play the run animation
			int animationIndex = animationController.AnimationIndex("Jog");
			this.animation = animationController.PlayLoopingAnimation(animationIndex);
		}
		private bool worldMatrixDirty = true; // set to true if worldMatrix is no longer valid, see 'UpdateWorldMatrix()'

		//create the actor
		public Actor(ContentRegister content, UpdateManager updateManager, MaterialLightCollection lights, float groundRadius)
		{
			this.groundRadius = groundRadius;

			model = new ModelInstance();
			model.LightCollection = lights;

			//force the model to render using spherical harmonic lighting
			//this will significantly improve performance on some hardware when GPU limited
			model.ShaderProvider = new Xen.Ex.Graphics.Provider.LightingDisplayShaderProvider(LightingDisplayModel.ForceSphericalHarmonic, model.ShaderProvider);

			//random starting position
			position = GetRandomPosition();

			//initially target the current position
			//the 'move to next target' timer will wind down and then the actor will move
			target = position;

			//randomize a bit
			lookAngle = (float)random.NextDouble() * MathHelper.TwoPi;
			moveSpeed = (float)random.NextDouble() * 0.9f + 0.1f;

			content.Add(this);
			updateManager.Add(this);


			InitaliseAnimations(updateManager);
		}
Пример #24
0
		public RenderConfigEditor(ContentRegister content)
		{
			//setup the text elements
			this.stateText = new List<TextElement>();
			this.visibleElementGap = new List<bool>();

#if XBOX360
			this.helpText = new TextElement("Use 'A' and the DPad to interact with the menu");
#else
			this.helpText = new TextElement("Use the Arrow Keys and 'Enter' to interact with the menu");
#endif
			this.helpText.HorizontalAlignment = HorizontalAlignment.Left;
			this.helpText.VerticalAlignment = VerticalAlignment.Bottom;
			this.helpText.Colour = Color.Black;

			this.backgroundContainer = new SolidColourElement(new Color(0, 0, 0, 200), new Vector2(0, 0));
			this.backgroundContainer.AlphaBlendState = AlphaBlendState.Alpha;

			foreach (string name in ConfigProperties.Keys)
			{
				//create the text
				TextElement text = new TextElement();

				//if it's a ediable value, then put a '[X]' infront
				if (ConfigProperties[name].CanRead)
					text.Text.SetText("[ ] " + name);
				else
					text.Text.SetText(name);

				text.VerticalAlignment = VerticalAlignment.Bottom;
				this.stateText.Add(text);

				bool gap = false;
				if (ConfigProperties[name].GetCustomAttributes(typeof(RenderConfiguration.GapAttribute), false).Length > 0)
					gap = true;

				this.visibleElementGap.Add(gap);
			}

			//select top instance
			this.editSelection = this.stateText.Count - 1;

			//sizes of the elements are setup in LoadContent()
			content.Add(this);
		}
		internal void Run(GameComponentHost host)
		{
			if (host == null)
				throw new ArgumentNullException();
			if (xnaLogic != null)
				throw new InvalidOperationException("Application is already initalised");

			xnaLogic = new XNALogic(this, host, out this.gamerServicesComponent);
			xnaLogic.Services.AddService(typeof(ApplicationProviderService), new ApplicationProviderService(this));
			xnaLogic.Exiting += new EventHandler(ShutdownThreadPool);
			xnaLogic.Content.RootDirectory += "Content";

			content = new ContentRegister(this, xnaLogic.Content);
			content.Add(this);

			xnaLogic.Run();
		}
		/// <summary>
		/// Start the main application loop. This method should be called from the entry point of the application
		/// </summary>
		public void Run()
		{
			if (xnaLogic != null)
				throw new InvalidOperationException("Application is already initalised");

			xnaLogic = new XNALogic(this, null, out gamerServicesComponent);

			this.XnaComponents.ComponentAdded += delegate(object sender, GameComponentCollectionEventArgs e) { if (e.GameComponent is DrawableGameComponent) drawableComponents++; };
			this.XnaComponents.ComponentRemoved += delegate(object sender,GameComponentCollectionEventArgs e) { if (e.GameComponent is DrawableGameComponent) drawableComponents--; };

			xnaLogic.Services.AddService(typeof(ApplicationProviderService), new ApplicationProviderService(this));
			xnaLogic.Exiting += new EventHandler(ShutdownThreadPool);
			xnaLogic.Content.RootDirectory += "Content";

			content = new ContentRegister(this, xnaLogic.Content);
			content.Add(this);

			xnaLogic.Run();
		}
		public GroundDisk(ContentRegister content, float radius, MaterialLightCollection lights)
		{
			//build the disk
			var vertexData = new VertexPositionNormalTexture[256];
			var indices = new List<int>();

			for (int i = 1; i < vertexData.Length; i++)
			{
				//a bunch of vertices, in a circle!
				float angle = (float)(i-1) / (float)(vertexData.Length-2) * MathHelper.TwoPi;
				Vector3 position = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0);

				vertexData[i] = new VertexPositionNormalTexture(position * radius, new Vector3(0, 0, 1), new Vector2(position.X, position.Y));
				if (i > 1)
				{
					indices.Add(0);
					indices.Add(i - 1);
					indices.Add(i);
				}
			}
			vertexData[0] = new VertexPositionNormalTexture(new Vector3(), new Vector3(0, 0, 1), new Vector2());

			this.vertices = new Vertices<VertexPositionNormalTexture>(vertexData);
			this.indices = new Indices<int>(indices);

			//create the material, and add to content
			this.material = new MaterialShader();
			this.material.LightCollection = lights;
			this.material.Textures = new MaterialTextures();

			content.Add(this);
		}