| using System; |
| using System.Collections.Generic; |
| using System.Linq; |
| using Microsoft.Xna.Framework; |
| using Microsoft.Xna.Framework.Audio; |
| using Microsoft.Xna.Framework.Content; |
| using Microsoft.Xna.Framework.GamerServices; |
| using Microsoft.Xna.Framework.Graphics; |
| using Microsoft.Xna.Framework.Input; |
| using Microsoft.Xna.Framework.Media; |
| using Microsoft.Xna.Framework.Net; |
| using Microsoft.Xna.Framework.Storage; |
| |
| namespace loderunner3d |
| { |
| public class ladrillo |
| { |
| //variables pricipales |
| Model brick; |
| Vector3 posicion_brick; |
| Effect efecto; |
| Texture2D color_difuse, normal_map; |
| float aspectratio = 0.0f; |
| //variables para el render |
| Matrix renderMatrix, worldMatrix, viewMatrix, projMatrix; |
| Matrix[] bones; |
| |
| public ladrillo(ContentManager content, GraphicsDeviceManager graphics) |
| { |
| brick = content.Load<Model>("inanimados/brick"); |
| efecto = content.Load<Effect>("normal_map"); |
| color_difuse = content.Load<Texture2D>("inanimados/normal2"); |
| normal_map = content.Load<Texture2D>("inanimados/bumped_normal"); |
| bones = new Matrix[brick.Bones.Count]; |
| brick.CopyAbsoluteBoneTransformsTo(bones); |
| |
| aspectratio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height; |
| posicion_brick = new Vector3(0.0f, 0.0f, 0.0f); |
| |
| worldMatrix = Matrix.Identity; |
| |
| float FieldOfView = MathHelper.ToRadians(45.0f), NearPlane = 1.0f, FarPlane = 10000.0f; |
| |
| projMatrix = Matrix.CreatePerspectiveFieldOfView(FieldOfView, aspectratio, NearPlane, FarPlane); |
| |
| graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionNormalTexture.VertexElements); |
| } |
| |
| public void SetPosition(Vector3 posicion) |
| { |
| posicion_brick = posicion; |
| } |
| |
| public void SetPosition(float x, float y, float z) |
| { |
| posicion_brick.X = x; |
| posicion_brick.Y = y; |
| posicion_brick.Z = z; |
| } |
| |
| public void render(GraphicsDeviceManager graphics) |
| { |
| renderMatrix = Matrix.CreateScale(8.0f); |
| viewMatrix = Matrix.CreateLookAt(new Vector3(0.0f, 1500.0f, 5000.0f), new Vector3(5.0f, 10.0f, 10.0f), Vector3.Up); |
| |
| |
| |
| efecto.CurrentTechnique = efecto.Techniques["NormalMapping"]; |
| |
| efecto.Begin(); |
| |
| |
| foreach (EffectPass pass in efecto.CurrentTechnique.Passes) |
| { |
| pass.Begin(); |
| |
| foreach (ModelMesh mesh in brick.Meshes) |
| { |
| foreach (ModelMeshPart part in mesh.MeshParts) |
| { |
| worldMatrix = bones[mesh.ParentBone.Index] * renderMatrix; |
| |
| Vector4 vecEye = new Vector4(0.0f, 1500.0f, 5000.0f, 0); |
| Matrix worldInverse = Matrix.Invert(worldMatrix); |
| Vector4 vLightDirection = new Vector4(1.0f, 1.0f, 1.0f, 0.0f); |
| efecto.Parameters["matWorldViewProj"].SetValue(worldMatrix * viewMatrix * projMatrix); |
| efecto.Parameters["matWorld"].SetValue(worldMatrix); |
| efecto.Parameters["vecEye"].SetValue(vecEye); |
| efecto.Parameters["vecLightDir"].SetValue(vLightDirection); |
| efecto.Parameters["ColorMap"].SetValue(color_difuse); |
| efecto.Parameters["NormalMap"].SetValue(normal_map); |
| |
| graphics.GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride); |
| graphics.GraphicsDevice.Indices = mesh.IndexBuffer; |
| graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, |
| part.BaseVertex, 0, part.NumVertices, |
| part.StartIndex, part.PrimitiveCount); |
| } |
| } |
| |
| pass.End(); |
| } |
| efecto.End(); |
| |
| } |
| |
| } |
| } |