2
0

SpriteEntity.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // SpriteEntity.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Graphics;
  12. #endregion
  13. namespace Audio3D
  14. {
  15. /// <summary>
  16. /// Base class for game entities that are displayed as billboard sprites,
  17. /// and which can emit 3D sounds. The Cat and Dog classes both derive from this.
  18. /// </summary>
  19. abstract class SpriteEntity : IAudioEmitter
  20. {
  21. #region Properties
  22. /// <summary>
  23. /// Gets or sets the 3D position of the entity.
  24. /// </summary>
  25. public Vector3 Position
  26. {
  27. get { return position; }
  28. set { position = value; }
  29. }
  30. Vector3 position;
  31. /// <summary>
  32. /// Gets or sets which way the entity is facing.
  33. /// </summary>
  34. public Vector3 Forward
  35. {
  36. get { return forward; }
  37. set { forward = value; }
  38. }
  39. Vector3 forward;
  40. /// <summary>
  41. /// Gets or sets the orientation of this entity.
  42. /// </summary>
  43. public Vector3 Up
  44. {
  45. get { return up; }
  46. set { up = value; }
  47. }
  48. Vector3 up;
  49. /// <summary>
  50. /// Gets or sets how fast this entity is moving.
  51. /// </summary>
  52. public Vector3 Velocity
  53. {
  54. get { return velocity; }
  55. protected set { velocity = value; }
  56. }
  57. Vector3 velocity;
  58. /// <summary>
  59. /// Gets or sets the texture used to display this entity.
  60. /// </summary>
  61. public Texture2D Texture
  62. {
  63. get { return texture; }
  64. set { texture = value; }
  65. }
  66. Texture2D texture;
  67. #endregion
  68. /// <summary>
  69. /// Updates the position of the entity, and allows it to play sounds.
  70. /// </summary>
  71. public abstract void Update(GameTime gameTime, AudioManager audioManager);
  72. /// <summary>
  73. /// Draws the entity as a billboard sprite.
  74. /// </summary>
  75. public void Draw(QuadDrawer quadDrawer, Vector3 cameraPosition,
  76. Matrix view, Matrix projection)
  77. {
  78. Matrix world = Matrix.CreateTranslation(0, 1, 0) *
  79. Matrix.CreateScale(800) *
  80. Matrix.CreateConstrainedBillboard(Position, cameraPosition,
  81. Up, null, null);
  82. quadDrawer.DrawQuad(Texture, 1, world, view, projection);
  83. }
  84. }
  85. }