Advertisement
Guest User

ModelRotation

a guest
Apr 26th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.Xna.Framework;
  5. using Microsoft.Xna.Framework.Audio;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.GamerServices;
  8. using Microsoft.Xna.Framework.Graphics;
  9. using Microsoft.Xna.Framework.Input;
  10. using Microsoft.Xna.Framework.Media;
  11.  
  12. namespace GyroGUI_v3
  13. {
  14.     public class Game1 : Microsoft.Xna.Framework.Game
  15.     {
  16.         GraphicsDeviceManager graphics;
  17.         SpriteBatch spriteBatch;
  18.  
  19.         public Game1()
  20.         {
  21.             graphics = new GraphicsDeviceManager(this);
  22.             Content.RootDirectory = "Content";
  23.         }
  24.         protected override void Initialize()
  25.         {
  26.             modelOrientation = Matrix.Identity;
  27.             modelOrientation *= Matrix.CreateScale(1);
  28.  
  29.             base.Initialize();
  30.         }
  31.         Model myModel;
  32.         float aspectRatio;
  33.         Matrix modelOrientation;
  34.         Vector3 modelPosition = Vector3.Zero;
  35.         protected override void LoadContent()
  36.         {
  37.             spriteBatch = new SpriteBatch(GraphicsDevice);
  38.  
  39.             myModel = Content.Load<Model>("Models\\p1_wedge");
  40.             aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width /
  41.             (float)graphics.GraphicsDevice.Viewport.Height;
  42.         }
  43.  
  44.         protected override void Update(GameTime gameTime)
  45.         {
  46.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
  47.                 this.Exit();
  48.  
  49.             Vector3 position = modelOrientation.Translation;
  50.             modelOrientation *= Matrix.CreateFromAxisAngle(new Vector3(1.0f, 1.0f, 0.0f), 0.2f);
  51.             modelOrientation.Translation = position;
  52.             base.Update(gameTime);
  53.         }
  54.  
  55.         protected override void Draw(GameTime gameTime)
  56.         {
  57.             GraphicsDevice.Clear(Color.CornflowerBlue);
  58.             foreach (ModelMesh mesh in myModel.Meshes)
  59.             {
  60.                 foreach (BasicEffect effect in mesh.Effects)
  61.                 {
  62.                     effect.EnableDefaultLighting();
  63.                     effect.World = modelOrientation;
  64.                     effect.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, 5000.0f), Vector3.Zero, Vector3.Up);
  65.                     effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
  66.                         aspectRatio, 1.0f, 10000.0f);
  67.                 }
  68.                 mesh.Draw();
  69.             }
  70.  
  71.             base.Draw(gameTime);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement