Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 BootHillHeroes.GameScreens;
- using BootHillHeroes.Components;
- //using Microsoft.Xna.Framework.Net;
- //using Microsoft.Xna.Framework.Storage;
- namespace BHB_Code.Hall.FirstShader
- {
- /// <summary>
- /// This is the main type for your game
- /// </summary>
- public class FirstShader
- {
- GraphicsDeviceManager graphics;
- SpriteBatch spriteBatch;
- Matrix world = Matrix.CreateTranslation(0, 0, 0);
- Matrix view = Matrix.CreateLookAt(new Vector3(0, 0, 10), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
- Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), 800f / 600f, 0.1f, 100f);
- Effect effect;
- float angle = 0;
- float distance = 10;
- Model model;
- Vector3 viewVector;
- //public FirstShader(GraphicsDeviceManager Graphics, SpriteBatch SpriteBatch)
- public FirstShader()
- {
- //graphics = new GraphicsDeviceManager(this);
- //spriteBatch = SpriteBatch;
- model = DataManager.GetModel("Helicopter2", BaseGameState.PlayerContent);
- effect = DataManager.GetEffect("Specular", BaseGameState.PlayerContent);
- }
- public void Update(GameTime gameTime)
- {
- angle += 0.01f;
- view = Matrix.CreateLookAt(distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle)), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
- Vector3 cameraLocation = distance * new Vector3((float)Math.Sin(angle), 0, (float)Math.Cos(angle));
- Vector3 cameraTarget = new Vector3(0, 0, 0);
- viewVector = Vector3.Transform(cameraTarget - cameraLocation, Matrix.CreateRotationY(0));
- viewVector.Normalize();
- view = Matrix.CreateLookAt(cameraLocation, cameraTarget, new Vector3(0, 1, 0));
- }
- public void Draw(GameTime gameTime)
- {
- //GraphicsDevice.Clear(Color.Black);
- DrawModelWithEffect(model, world, view, projection);
- }
- private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
- {
- foreach (ModelMesh mesh in model.Meshes)
- {
- foreach (BasicEffect effect in mesh.Effects)
- {
- effect.EnableDefaultLighting();
- effect.PreferPerPixelLighting = true;
- effect.World = world * mesh.ParentBone.Transform;
- effect.View = view;
- effect.Projection = projection;
- }
- mesh.Draw();
- }
- }
- private void DrawModelWithEffect(Model model, Matrix world, Matrix view, Matrix projection)
- {
- foreach (ModelMesh mesh in model.Meshes)
- {
- foreach (ModelMeshPart part in mesh.MeshParts)
- {
- part.Effect = effect;
- effect.Parameters["World"].SetValue(world * mesh.ParentBone.Transform);
- effect.Parameters["View"].SetValue(view);
- effect.Parameters["Projection"].SetValue(projection);
- effect.Parameters["ViewVector"].SetValue(viewVector);
- //Ambient
- // effect.Parameters["AmbientColor"].SetValue(Color.Green.ToVector4());
- // effect.Parameters["AmbientIntensity"].SetValue(0.5f);
- //Diffuse
- Matrix worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(mesh.ParentBone.Transform * world));
- effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix);
- }
- mesh.Draw();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement