namespace DarkWynterEngine.ObjectLib { #region Using Statements using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using System.Xml; #endregion using Globals; using GameObjects; /// /// Class which manages a list of our billboard objects /// public class BillboardList { List billboardList; /// /// The common texture drawn on the billboards /// public Texture2D texture; /// /// The common bump map texture used on all the billboards /// public Texture2D bump; VertexPositionTexture[] vertSprites = null; VertexDeclaration vertexDeclSprites = null; short[] indexBuffer = null; Model temp; /// /// Constructor /// public BillboardList() { billboardList = new List(); vertexDeclSprites = new VertexDeclaration(Statics.SystemSettings.graphics.GraphicsDevice, VertexPositionTexture.VertexElements); vertSprites = new VertexPositionTexture[] { new VertexPositionTexture(new Vector3(-0.5f, -0.5f, 0), new Vector2(0,1)), new VertexPositionTexture(new Vector3(0.5f, -0.5f, 0), new Vector2(1,1)), new VertexPositionTexture(new Vector3(0.5f, 0.5f, 0), new Vector2(1,0)), new VertexPositionTexture(new Vector3(-0.5f, 0.5f, 0), new Vector2(0,0)) }; indexBuffer = new short[] { 0, 1, 2, 2, 3, 0 }; temp = Statics.SystemSettings.content.Load("Content/_models/GenericQuad"); foreach (ModelMesh mesh in temp.Meshes) { for (int i = 0; i < mesh.MeshParts.Count; i++) { // Add effect to mesh mesh.MeshParts[i].Effect = ShaderParameters.effect_draw; } } } /// /// Load stuff, currently empty /// /// This billboard list's XML node /// ObjectLibrary public void Load(XmlNode objectNode, ObjectLibrary objectLibrary) { } /// /// Adds a List of billboard to our current list /// /// new list of billboards public void Add(List billboard) { billboardList.AddRange(billboard); } /// /// Adds a single new billboard to our current list /// /// New billboard public void Add(Billboard billboard) { billboardList.Add(billboard); } /// /// Removes the billboard from our list /// /// Billboard to be removed public void Remove(Billboard billboard) { billboardList.Remove(billboard); } /// /// Draws all of the current billboards in our list /// /// ObjectLibrary /// The index of the current player whose view is being drawn (for orienting the billboard) public void Draw_Billboards(ObjectLibrary objectLibrary, int playerIndex) { // For each Billboard in the List<> for (int i = 0; i < billboardList.Count; i++) { // Combine current and offset positions Vector3 billboardPosition = billboardList[i].mass.currentPosition + billboardList[i].offset; // Face Billboard Towards The Camera Matrix world = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f)) * Matrix.CreateScale(new Vector3(billboardList[i].width, billboardList[i].height, 0.0f)) * Matrix.CreateBillboard(billboardPosition, objectLibrary.humans[playerIndex].mass.currentPosition, objectLibrary.humans[playerIndex].mass.upVector, objectLibrary.humans[playerIndex].mass.normalVector); // Set Shader Params ShaderParameters.World.SetValue(world); // Set Textures ShaderParameters.modelTexture1.SetValue(billboardList[i].textureList[0]); //ShaderParameters.bumpTexture1.SetValue(billboardList[i].texture); ShaderParameters.ViewProj.SetValue(Statics.RenderSettings.matrixView * Statics.RenderSettings.matrixProjection); billboardList[i].DrawTriStrips(temp, "DrawQuad"); } } private void DrawBillboard(float width, float height) { GraphicsDevice device = Statics.SystemSettings.graphics.GraphicsDevice; //vertSprites[0].Position.X = - width / 2.0f; //vertSprites[0].Position.Y = - height / 2.0f; //vertSprites[0].Position.Z = 0.0f; //vertSprites[1].Position.X = + width / 2.0f; //vertSprites[1].Position.Y = - height / 2.0f; //vertSprites[1].Position.Z = 0.0f; //vertSprites[2].Position.X = + width / 2.0f; //vertSprites[2].Position.Y = + height / 2.0f; //vertSprites[2].Position.Z = 0.0f; //vertSprites[3].Position.X = - width / 2.0f; //vertSprites[3].Position.Y = + height / 2.0f; //vertSprites[3].Position.Z = 0.0f; // Render our quad ShaderParameters.effect_draw.Begin(); foreach (EffectPass pass in ShaderParameters.effect_draw.CurrentTechnique.Passes) { pass.Begin(); device.DrawUserIndexedPrimitives (PrimitiveType.TriangleList, vertSprites, 0, 4, indexBuffer, 0, 2); pass.End(); } ShaderParameters.effect_draw.End(); } } }