Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Content;
  7. using Microsoft.Xna.Framework.Graphics;
  8. using Microsoft.Xna.Framework.Input;
  9.  
  10. namespace Games_Game_1
  11. {
  12.     class player
  13.     {
  14.         private Model myModel;
  15.         public Matrix[] Transforms;
  16.  
  17.         //Position of the model in world space
  18.         public Vector3 Position = Vector3.Zero;
  19.  
  20.         //Velocity of the model, applied each frame to the model's position
  21.         public Vector3 Velocity = Vector3.Zero;
  22.  
  23.         public Matrix RotationMatrix = Matrix.Identity;
  24.         private float rotation;
  25.         public float Rotation
  26.         {
  27.             get { return rotation; }
  28.             set
  29.             {
  30.                 float newVal = value;
  31.                 while (newVal >= MathHelper.TwoPi)
  32.                 {
  33.                     newVal -= MathHelper.TwoPi;
  34.                 }
  35.                 while (newVal < 0)
  36.                 {
  37.                     newVal += MathHelper.TwoPi;
  38.                 }
  39.  
  40.                 if (rotation != newVal)
  41.                 {
  42.                     rotation = newVal;
  43.                     RotationMatrix = Matrix.CreateRotationY(rotation);
  44.                 }
  45.  
  46.             }
  47.         }
  48.  
  49.         public void Update(GamePadState controllerState)
  50.         {
  51.             // Rotate the model using the left thumbstick, and scale it down.
  52.             Rotation -= controllerState.ThumbSticks.Left.X * 0.10f;
  53.  
  54.             // Finally, add this vector to our velocity.
  55.             Velocity += RotationMatrix.Forward * 1.0f *
  56.                 controllerState.Triggers.Right;
  57.         }
  58.  
  59.         Vector3 modelPosition = Vector3.Zero;
  60.         float modelRotation = 0.0f;
  61.  
  62.         Vector3 cameraPosition = new Vector3(0.0f, 50.0f, 5000.0f);
  63.  
  64.         public void Draw(GameTime gameTime)
  65.         {
  66.        
  67.  
  68.             // TODO: Add your drawing code here
  69.  
  70.  
  71.  
  72.  
  73.             Matrix[] transforms = new Matrix[myModel.Bones.Count];
  74.             myModel.CopyAbsoluteBoneTransformsTo(transforms);
  75.  
  76.  
  77.             foreach (ModelMesh mesh in myModel.Meshes)
  78.             {
  79.                 foreach (BasicEffect effect in mesh.Effects)
  80.                 {
  81.                     effect.EnableDefaultLighting();
  82.                     effect.World = transforms[mesh.ParentBone.Index] *
  83.                         Matrix.CreateRotationY(modelRotation)
  84.                         * Matrix.CreateTranslation(modelPosition);
  85.                     effect.View = Matrix.CreateLookAt(cameraPosition,
  86.                         Vector3.Zero, Vector3.Up);
  87.                     effect.Projection = Matrix.CreatePerspectiveFieldOfView(
  88.                         MathHelper.ToRadians(45.0f), aspectRatio,
  89.                         1.0f, 10000.0f);
  90.                 }
  91.                 mesh.Draw();
  92.             }
  93.  
  94.  
  95.  
  96.  
  97.             base.Draw(gameTime);
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement