namespace DarkWynter.Engine.GameObjects { #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 ObjectLib; using Globals; using Init; using DarkWynter.Stream; #endregion /// /// A Billboard Sprite places a Texture in 3D space that is always oriented towards the user. /// This makes an effective tool to do lightweight props such as brush, clouds, smoke, or fire. /// GameObjects cann add Billboards to ObjectLibrary's BillboardList in the Draw_Billboards method. /// public class Billboard : GameObject { /// /// Offset Position of the Sprite /// public Vector3 offset; /// /// Width of the Billboard /// public float width; /// /// Height of the Billboard /// public float height; public Billboard(Load gameObjectLoader) : base(gameObjectLoader) { } /// /// Create a Billboard Object with it's own texture /// /// Location of the Billboard in 3D space. /// Position relative to CurrentPosition, used to modulate motion. /// Width of the Billboard. /// Height of the Billboard. /// Texture to use with this Billboard. public void Load(Vector3 Position, Vector3 Offset, float Width, float Height, Texture2D Image) { draw = new Draw(Enums_Stream.DrawMethod.BillBoards_Draw, "DrawQuad"); draw.model = Statics_Engine.SystemSettings.content.Load("Content/_models/GenericQuad"); foreach (ModelMesh mesh in draw.model.Meshes) { for (int i = 0; i < mesh.MeshParts.Count; i++) { // Add effect to mesh mesh.MeshParts[i].Effect = ShaderParameters.DrawFX.effect; } } mass.currentPosition = Position; offset = Offset; draw.textureList.Add(Image); width = Width; height = Height; } /// /// Sets the current position of the billboard /// /// The new Vector3 position of the billboard public void SetPosition(Vector3 position) { mass.currentPosition = position; } /// /// Sets the current position of the billboard /// /// The new Vector3 position of the billboard public void SetTexture(Texture2D texture) { draw.textureList.Clear(); draw.textureList.Add(texture); } /// /// Draws the current billboard /// /// ObjectLibrary /// The index of the current player whose view is being drawn (for orienting the billboard) public Draw Draw_Billboards(ObjectLibrary objectLibrary, int playerIndex) { // Combine current and offset positions Vector3 billboardPosition = mass.currentPosition + offset; // Face Billboard Towards The Camera draw.matrix = Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f)) * Matrix.CreateScale(new Vector3(width, height, 0.0f)) * Matrix.CreateBillboard(billboardPosition, objectLibrary.humans[playerIndex].mass.currentPosition, objectLibrary.humans[playerIndex].mass.upVector, objectLibrary.humans[playerIndex].mass.normalVector); return draw; } } }