//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynterEngine.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 System.Xml; #endregion using Globals; using ObjectLib; using Physics; /// /// Creates a single generic prop object. /// Props require no additional code, and are loaded using the Prop tag in XML. /// Simply fill out the required fields and create a Location Map, and voila. /// public class Prop : GameObject { /// /// Prop constructor. /// public Prop() { mass.COR = 0.99999f; mass.objectType = Enums.ObjectType.PROP; } /// /// Generic loading for props. /// /// Xml node describing this type of prop. /// ObjectLibrary that this prop belong to. /// True if load was successful public override bool Load(XmlNode node, ObjectLibrary objectLibrary) { if (!base.Load(node, objectLibrary)) { return false; } mass.boundingVolume = new BoundingVolume(new BoundingSphere(mass.currentPosition + new Vector3(0.0f, mass.scale.Y / 2.0f, 0.0f), mass.scale.Y)); mass.dynamicFrictionCoefficient = 0.0f; mass.isMoving = true; mass.objectType = Enums.ObjectType.PROP; mass.objectHeight = 5; return true; } /// /// Draws this Prop::GameObject. /// /// Model Manager /// Draw technique to use public override void Draw(ModelManager modelManager, string technique) { // Lighting ShaderParameters.shininess.SetValue(7000.0f); // Calculate ObjectSpace(Rotation) and WorldSpace(Translation) Transformation Matrix matrix = Matrix.CreateScale(mass.scale) * Matrix.CreateFromQuaternion(mass.currentRotation) * Matrix.CreateTranslation(mass.currentPosition); // Matricies ShaderParameters.World.SetValue(matrix); ModelInfo modelInfo = modelManager.GetModelInfo(objectModelName); // Load resources for that catagory ShaderParameters.modelTexture1.SetValue(modelInfo.currentTexture); ShaderParameters.bumpTexture1.SetValue(modelInfo.bumpTexture); foreach (ModelMesh mesh in modelInfo.model.Meshes) { Statics.SystemSettings.graphics.GraphicsDevice.Indices = mesh.IndexBuffer; foreach (ModelMeshPart part in mesh.MeshParts) { Statics.SystemSettings.graphics.GraphicsDevice.VertexDeclaration = part.VertexDeclaration; Statics.SystemSettings.graphics.GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride); part.Effect.CurrentTechnique = part.Effect.Techniques["BasicLightingShaderMain"]; part.Effect.Begin(); for (int k = 0; k < part.Effect.CurrentTechnique.Passes.Count; k++) { EffectPass pass = part.Effect.CurrentTechnique.Passes[k]; pass.Begin(); Statics.SystemSettings.graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.BaseVertex, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount); pass.End(); } part.Effect.End(); } } } } }