Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1.         public override void Update(GameTime gameTime)
  2.         {
  3.             float elapsedSec = (float)gameTime.ElapsedGameTime.TotalSeconds;
  4.             keyboard = Keyboard.GetState();
  5.             mouse = Mouse.GetState();
  6.             rotazione -= (float)(mouse.X - game.Window.ClientBounds.Width / 2)/4 * elapsedSec;
  7.             beccheggio += (float)(mouse.Y - game.Window.ClientBounds.Height / 2)/4 * elapsedSec;
  8.  
  9.             // Riposiziona il mouse al centro del viewport per le successive letture.
  10.             Mouse.SetPosition(game.Window.ClientBounds.Width / 2, game.Window.ClientBounds.Height / 2);
  11.  
  12.             // Crea una matrice di rotazione secondo i vari angoli di rotazione
  13.             Matrix rot = Matrix.CreateFromYawPitchRoll(rotazione, beccheggio, rollio);
  14.  
  15.             // Calcola i vettori per la matrice di rotazione corrente.
  16.             Vector3 camUp = Vector3.Transform(Vector3.UnitY, rot);
  17.             Vector3 camLook = Vector3.Transform(Vector3.UnitZ, rot);
  18.             Vector3 camLeft = Vector3.Cross(camUp, camLook);
  19.  
  20.             //La velocità di movimento.
  21.             float speed = 600.0f;
  22.  
  23.             // Pulsante per uscire dal gioco.
  24.             if (keyboard.IsKeyDown(Keys.Escape))
  25.                 game.Exit();
  26.  
  27.             //Raddoppia la velocità se premuto il tasto lo Shift sinistro.
  28.             if (keyboard.IsKeyDown(Keys.LeftShift))
  29.                 speed *= 2.0f;
  30.  
  31.  
  32.  
  33.             // Controlla la pressione dei tasti A W S D per lo spostamento
  34.             // moltiplica per elapsedSec per rendere la velocità di spostamento indipendente
  35.             // dal framerate.
  36.             ////////////////////////////////////////////////////////////////////////////
  37.             if (keyboard.IsKeyDown(Keys.A))
  38.                 posizione += speed * elapsedSec * camLeft;
  39.  
  40.             if (keyboard.IsKeyDown(Keys.D))
  41.                 posizione -= speed * elapsedSec * camLeft;
  42.  
  43.             if (keyboard.IsKeyDown(Keys.W))
  44.                 posizione += speed * elapsedSec * camLook;
  45.  
  46.             if (keyboard.IsKeyDown(Keys.S))
  47.                 posizione -= speed * elapsedSec * camLook;
  48.             ////////////////////////////////////////////////////////////////////////////
  49.  
  50.  
  51.  
  52.  
  53.             // Crea la matrice per il punto di vista corrente
  54.             //Si trova nel metodo Update perchè essa verrà aggiornata ad ogni fotogramma
  55.             gioco.View = Matrix.CreateLookAt(posizione, posizione + camLook, camUp);
  56.             base.Update(gameTime);
  57.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement