BoxCollider.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. namespace BansheeEngine
  4. {
  5. /** @addtogroup Physics
  6. * @{
  7. */
  8. /// <summary>
  9. /// Collider with box geometry.
  10. /// </summary>
  11. public sealed class BoxCollider : Collider
  12. {
  13. [SerializeField]
  14. private Vector3 extents = Vector3.One;
  15. /// <summary>
  16. /// Extents (half size) of the geometry of the box.
  17. /// </summary>
  18. public Vector3 Extents
  19. {
  20. get { return extents; }
  21. set
  22. {
  23. value = new Vector3(MathEx.Max(value.x, 0.01f), MathEx.Max(value.y, 0.01f), MathEx.Max(value.z, 0.01f));
  24. if (extents == value)
  25. return;
  26. extents = value;
  27. if (Native != null)
  28. {
  29. Native.Extents = value;
  30. if (parent != null)
  31. parent.UpdateMassDistribution();
  32. }
  33. }
  34. }
  35. /// <summary>
  36. /// Position of the box shape, relative to the component's scene object.
  37. /// </summary>
  38. public Vector3 Center
  39. {
  40. get { return serializableData.localPosition; }
  41. set
  42. {
  43. if (serializableData.localPosition == value)
  44. return;
  45. serializableData.localPosition = value;
  46. if (Native != null)
  47. UpdateTransform();
  48. }
  49. }
  50. /// <summary>
  51. /// Returns the native box collider wrapped by this component.
  52. /// </summary>
  53. private NativeBoxCollider Native
  54. {
  55. get { return (NativeBoxCollider)native; }
  56. }
  57. /// <inheritdoc/>
  58. internal override NativeCollider CreateCollider()
  59. {
  60. NativeBoxCollider boxCollider = new NativeBoxCollider();
  61. boxCollider.Extents = extents;
  62. return boxCollider;
  63. }
  64. }
  65. /** @} */
  66. }