//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {License Information: Creative Commons} //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace ElementalGame { #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; using System.Diagnostics; #endregion public class Triangle : GameObject { //int width; //int height; new public float[] materialDiffuse = { 0.7f, 0.7f, 0.7f, 1.0f }; // Diffuse cofactor new public float[] materialSpecular = { 0.1f, 0.1f, 0.1f, 1.0f }; // Specular cofactor public Triangle(Mass darkMass) { mass = darkMass; } public void Rotate(float dVert, float dHoriz) { mass.Rotate(dVert, dHoriz); } public void SetPosition(Vector3 position, Vector3 reference) { mass.SetPosition(position, reference); } public void SetScale(int scale) { mass.scale = scale; } /* GameObject Interface Methods * */ public override void Load(XmlNode node) { base.Load(node); } public override void Update(ObjectLibrary objectLibrary) { //mass.AddForce(Mass.accelDueToGravity); mass.UpdatePosition(); _boundingSphere.Center = mass.currentPosition; objectValues = new VertexFogBinormalTangentWeightTess(); matrix = Matrix.CreateScale(mass.scale) * Matrix.CreateFromQuaternion(mass.currentRotation) * Matrix.CreateTranslation(mass.currentPosition); objectValues.Fog = new Vector4(matrix.M11, matrix.M12, matrix.M13, matrix.M14); // Store the first row objectValues.Binormal = new Vector4(matrix.M21, matrix.M22, matrix.M23, matrix.M24); // Store the second row objectValues.Tangent = new Vector4(matrix.M31, matrix.M32, matrix.M33, matrix.M34); // Store the third row objectValues.BlendWeight = new Vector4(matrix.M41, matrix.M42, matrix.M43, matrix.M44); // Store the fourth row } public override void DrawShadow(ModelManager modelManager) { } // ========================= Distance culling should be done with indexing in Map ========================= public override void Draw(ModelManager modelManager) { ModelInfo modelInfo = new ModelInfo(); // 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 = modelManager.GetModelInfo(objectModelName); // Lighting ShaderParameters.coreShininess.SetValue(7000.0f); ShaderParameters.coreMaterialDiffuse.SetValue(modelInfo.materialDiffuse); ShaderParameters.coreMaterialSpecular.SetValue(modelInfo.materialSpecular); // Load resources for that catagory ShaderParameters.modelTexture1.SetValue(modelInfo.currentTexture); ShaderParameters.bumpTexture1.SetValue(modelInfo.bumpTexture); foreach (ModelMesh mesh in modelInfo.model.Meshes) { ElementalGame.graphics.GraphicsDevice.Indices = mesh.IndexBuffer; foreach (ModelMeshPart part in mesh.MeshParts) { ElementalGame.graphics.GraphicsDevice.VertexDeclaration = part.VertexDeclaration; ElementalGame.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(); ElementalGame.graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.BaseVertex, 0, part.NumVertices, part.StartIndex, part.PrimitiveCount); pass.End(); } part.Effect.End(); } } } public void DrawRTT() { // Setup view and projection matrixes Matrix view = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up); Matrix proj = Matrix.CreateOrthographic(ElementalGame.graphics.GraphicsDevice.Viewport.Width, ElementalGame.graphics.GraphicsDevice.Viewport.Height, 0, 10); } public void DrawOrthographic() { // Setup view and projection matrixes Matrix view = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up); Matrix proj = Matrix.CreateOrthographic(ElementalGame.graphics.GraphicsDevice.Viewport.Width, ElementalGame.graphics.GraphicsDevice.Viewport.Height, 0, 10000); } } }