CollideSphere.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // CollideSphere.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 System;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. #endregion
  16. namespace RobotGameData.Collision
  17. {
  18. /// <summary>
  19. /// It's a collision sphere.
  20. /// </summary>
  21. public class CollideSphere : CollideElement
  22. {
  23. #region Fields
  24. /// <summary>
  25. /// local center of the bounding sphere
  26. /// </summary>
  27. protected Vector3 localCenter = Vector3.Zero;
  28. /// <summary>
  29. /// Bounding sphere
  30. /// </summary>
  31. protected BoundingSphere boundingSphere;
  32. #endregion
  33. #region Properties
  34. public BoundingSphere BoundingSphere
  35. {
  36. get { return boundingSphere; }
  37. }
  38. public Vector3 LocalCenter
  39. {
  40. get { return localCenter; }
  41. }
  42. public Vector3 WorldCenter
  43. {
  44. get { return BoundingSphere.Center; }
  45. }
  46. /// <summary>
  47. /// Collision Radius of this sphere
  48. /// </summary>
  49. public float Radius
  50. {
  51. get { return BoundingSphere.Radius; }
  52. }
  53. #endregion
  54. /// <summary>
  55. /// Constructor.
  56. /// </summary>
  57. /// <param name="center">center position of the sphere</param>
  58. /// <param name="radius">radius of the sphere</param>
  59. public CollideSphere(Vector3 center, float radius)
  60. : base()
  61. {
  62. localCenter = center;
  63. boundingSphere = new BoundingSphere(localCenter, radius);
  64. }
  65. /// <summary>
  66. /// Transform the bounding sphere.
  67. /// </summary>
  68. public override void Transform(Matrix matrix)
  69. {
  70. boundingSphere.Center = Vector3.Transform(localCenter, matrix);
  71. matrix.Translation = boundingSphere.Center;
  72. base.Transform(matrix);
  73. }
  74. }
  75. }