//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Game.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 DarkWynter.Engine.GameObjects; using DarkWynter.Engine.ObjectLib; using DarkWynter.Engine.Globals; using DarkWynter.Engine.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, IBillboard { /// /// 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) { this.draw = new Draw(Enums_Stream.DrawMethod.BillBoards_Draw, "DrawQuad"); this.draw.model = Statics_Engine.SystemSettings.content.Load("Content/_models/GenericQuad"); foreach (ModelMesh mesh in this.draw.model.Meshes) { for (int i = 0; i < mesh.MeshParts.Count; i++) { // Add effect to mesh mesh.MeshParts[i].Effect = ShaderParameters.DrawFX.effect; } } this.mass.currentPosition = Position; this.offset = Offset; this.draw.textureList.Add(Image); this.width = Width; this.height = Height; } /// /// Sets the current position of the billboard /// /// The new Vector3 position of the billboard public Vector3 Position { get { return this.mass.currentPosition; } set { this.mass.currentPosition = value; } } /// /// Sets the current position of the billboard /// /// The new Vector3 position of the billboard public void SetTexture(Texture2D texture) { this.draw.textureList.Clear(); this.draw.textureList.Add(texture); } /// /// Set the draw location relative to the current position. /// Makes it easy to create jitter, rotation, or other simple animations without effecting currentPosition. /// /// public void SetOffset(Vector3 locationOffset) { this.offset = locationOffset; } /// /// 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 = this.mass.currentPosition + this.offset; // Face Billboard Towards The Camera this.draw.matrix = draw.initialTransform * Matrix.CreateScale(new Vector3(this.width, this.height, 0.0f)) * Matrix.CreateBillboard(billboardPosition, objectLibrary.humans[playerIndex].mass.currentPosition, objectLibrary.humans[playerIndex].mass.upVector, objectLibrary.humans[playerIndex].mass.normalVector)* Matrix.CreateTranslation(new Vector3(-0.5f, -0.5f, -0.5f)); return this.draw; } } }