Advertisement
zamarok

DebugFarseer.cs

May 27th, 2011
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 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. using FarseerPhysics.DebugViews;
  12. using FarseerPhysics;
  13.  
  14. namespace Bounce
  15. {
  16.     public class DebugFarseer : Microsoft.Xna.Framework.GameComponent
  17.     {
  18.         DebugViewXNA DebugViewXNA;
  19.         public DebugFarseer(Game game)
  20.             : base(game)
  21.         {
  22.             DebugViewXNA = new DebugViewXNA(BounceGame.World);
  23.             DebugViewXNA.LoadContent(game.GraphicsDevice, game.Content);
  24.             DebugViewXNA.RemoveFlags(DebugViewFlags.Shape);
  25.             this.InitializeDraw();
  26.             game.Components.Add(this);
  27.         }
  28.  
  29.         private Matrix projection, view;
  30.  
  31.         public override void Initialize()
  32.         {
  33.            
  34.             base.Initialize();
  35.         }
  36.        
  37.         public override void Update(GameTime gameTime)
  38.         {
  39.             HandleInput(gameTime);
  40.             base.Update(gameTime);
  41.         }
  42.  
  43.         public void HandleInput(GameTime gameTime)
  44.         {
  45.             if (BounceGame.KeyboardState.GetPressedKeys().Length != 0)
  46.             {
  47.                 if (InputHelper.KeyPressUnique(Keys.F1))
  48.                 {
  49.                     EnableOrDisableFlag(DebugViewFlags.Shape);
  50.                 }
  51.                 if (InputHelper.KeyPressUnique(Keys.F2))
  52.                 {
  53.                     EnableOrDisableFlag(DebugViewFlags.DebugPanel);
  54.                     EnableOrDisableFlag(DebugViewFlags.PerformanceGraph);
  55.                 }
  56.                 if (InputHelper.KeyPressUnique(Keys.F3))
  57.                 {
  58.                     EnableOrDisableFlag(DebugViewFlags.Joint);
  59.                 }
  60.                 if (InputHelper.KeyPressUnique(Keys.F4))
  61.                 {
  62.                     EnableOrDisableFlag(DebugViewFlags.ContactPoints);
  63.                     EnableOrDisableFlag(DebugViewFlags.ContactNormals);
  64.                 }
  65.                 if (InputHelper.KeyPressUnique(Keys.F5))
  66.                 {
  67.                     EnableOrDisableFlag(DebugViewFlags.PolygonPoints);
  68.                 }
  69.                 if (InputHelper.KeyPressUnique(Keys.F6))
  70.                 {
  71.                     EnableOrDisableFlag(DebugViewFlags.Controllers);
  72.                 }
  73.                 if (InputHelper.KeyPressUnique(Keys.F7))
  74.                 {
  75.                     EnableOrDisableFlag(DebugViewFlags.CenterOfMass);
  76.                 }
  77.                 if (InputHelper.KeyPressUnique(Keys.F8))
  78.                 {
  79.                     EnableOrDisableFlag(DebugViewFlags.AABB);
  80.                 }
  81.             }
  82.         }
  83.  
  84.         private void EnableOrDisableFlag(DebugViewFlags flag)
  85.         {
  86.             if ((DebugViewXNA.Flags & flag) == flag)
  87.             {
  88.                 DebugViewXNA.RemoveFlags(flag);
  89.             }
  90.             else
  91.             {
  92.                 DebugViewXNA.AppendFlags(flag);
  93.             }
  94.         }
  95.  
  96.         public void Draw()
  97.         {
  98.             DebugViewXNA.RenderDebugData(ref projection, ref view);
  99.         }
  100.         protected void InitializeDraw()
  101.         {
  102.             projection = Matrix.CreateOrthographic(
  103.                 BounceGame.Graphics.PreferredBackBufferWidth / 100.0f,
  104.                 -BounceGame.Graphics.PreferredBackBufferHeight / 100.0f, 0, 1000000);
  105.  
  106.             Vector3 campos = new Vector3();
  107.             campos.X = (-BounceGame.Graphics.PreferredBackBufferWidth / 2) / 100.0f;
  108.             campos.Y = (BounceGame.Graphics.PreferredBackBufferHeight / 2) / -100.0f;
  109.             campos.Z = 0;
  110.             Matrix tran = Matrix.Identity;
  111.             tran.Translation = campos;
  112.             view = tran;
  113.         }
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement