using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; namespace WindowsGame1 { class EntityModel : DrawableGameComponent { protected Vector2 m_TextureOffset = Vector2.Zero; public Vector2 TextureOffset { get { return new Vector2((float)(m_TextureOffset.X * m_Texture.Width), (float)(m_TextureOffset.Y * m_Texture.Height)); } set { m_TextureOffset = new Vector2(value.X/m_Texture.Width, value.Y/m_Texture.Height); } } protected Model m_Model; /// /// This is the reference to the XNA model that the class uses. /// public Model Model { get { return m_Model; } set { m_Model = value; } } protected Texture2D m_Texture; /// /// This is the texture that the model will use. /// public Texture2D Texture { get { return m_Texture; } set { m_Texture = value; } } protected float m_SpecularIntensity = 0f; public float SpecularIntensity { get { return m_SpecularIntensity; } set { m_SpecularIntensity = value; } } protected float m_SpecularPower = 0f; public float SpecularPower { get { return m_SpecularPower; } set { m_SpecularPower = value; } } protected Matrix m_TransformationMatrix = Matrix.Identity; /// /// This is the transformation matrix applied to the model to scale, rotate, and translate it. /// public Matrix TransformationMatrix { get { return m_TransformationMatrix; } set { m_TransformationMatrix = value; } } /// /// Constructor /// /// The reference to the game object that this Game component is registered with /// The XNA model that this EntityModel will use. public EntityModel(Game p_Game, Model p_Model) : base(p_Game) { m_Model = p_Model; } /// /// Constructor /// /// The game reference that this object will be associated with. /// The /// public EntityModel(Game p_Game, Model p_Model, Matrix p_TransformationMatrix) : base(p_Game) { m_Model = p_Model; m_TransformationMatrix = p_TransformationMatrix; } public override void Initialize() { base.Initialize(); } /// /// This is the draw method that will be called during the XNA draw cycle. /// /// The game time object passed in by XNA. public override void Draw(GameTime gameTime) { GraphicsDevice.RenderState.DepthBufferEnable = true; GraphicsDevice.RenderState.DepthBufferWriteEnable = true; GraphicsDevice.RenderState.DepthBufferFunction = CompareFunction.LessEqual; //GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; foreach (ModelMesh mesh in m_Model.Meshes) { GraphicsDevice.RenderState.FillMode = FillMode.Solid; foreach (Effect effect in mesh.Effects) { effect.Parameters["World"].SetValue(m_TransformationMatrix); effect.Parameters["inTexture"].SetValue(m_Texture); effect.Parameters["UVoffSet"].SetValue(m_TextureOffset); effect.Parameters["specularPower"].SetValue(m_SpecularPower); effect.Parameters["specularIntensity"].SetValue(m_SpecularIntensity); } mesh.Draw(); } } /// /// The Update method called during XNA's update cycle. /// /// The game time object passed in by XNA. public override void Update(GameTime gameTime) { base.Update(gameTime); //m_TransformationMatrix = m_TransformationMatrix * Matrix.CreateRotationY(.01f); //m_TransformationMatrix = m_TransformationMatrix * Matrix.CreateRotationX(.01f); //m_TextureOffset.X += .01f; //m_TextureOffset.Y += .01f; //Visible = !Visible; } } }