PhysicsMaterial.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using System.Runtime.CompilerServices;
  5. namespace BansheeEngine
  6. {
  7. /** @addtogroup Physics
  8. * @{
  9. */
  10. /// <summary>
  11. /// Material that controls how two physical objects interact with each other. Materials of both objects are used during
  12. /// their interaction and their combined values are used.
  13. /// </summary>
  14. public class PhysicsMaterial : Resource
  15. {
  16. /// <summary>
  17. /// Constructor for internal use by the runtime.
  18. /// </summary>
  19. private PhysicsMaterial(int dummy)
  20. { }
  21. /// <summary>
  22. /// Creates a brand new physics material.
  23. /// </summary>
  24. /// <param name="staticFriction">Controls friction when two in-contact objects are not moving lateral to each other.
  25. /// </param>
  26. /// <param name="dynamicFriction">Controls friction when two in-contact objects are moving lateral to each other.
  27. /// </param>
  28. /// <param name="restitution">Controls "bounciness" of an object during a collision. Value of 1 means the collision
  29. /// is elastic, and value of 0 means the value is inelastic.</param>
  30. public PhysicsMaterial(float staticFriction = 0.0f, float dynamicFriction = 0.0f, float restitution = 0.0f)
  31. {
  32. Internal_CreateInstance(this, staticFriction, dynamicFriction, restitution);
  33. }
  34. /// <summary>
  35. /// Controls friction when two in-contact objects are not moving lateral to each other (for example how difficult is
  36. /// to get an object moving from a static state while it is in contact other object(s)).
  37. /// </summary>
  38. public float StaticFriction
  39. {
  40. get { return Internal_GetStaticFriction(mCachedPtr); }
  41. set { Internal_SetStaticFriction(mCachedPtr, value); }
  42. }
  43. /// <summary>
  44. /// Controls friction when two in-contact objects are moving lateral to each other (for example how quickly does an
  45. /// object slow down when sliding along another object).
  46. /// </summary>
  47. public float DynamicFriction
  48. {
  49. get { return Internal_GetDynamicFriction(mCachedPtr); }
  50. set { Internal_SetDynamicFriction(mCachedPtr, value); }
  51. }
  52. /// <summary>
  53. /// Controls "bounciness" of an object during a collision. Value of 1 means the collision is elastic, and value
  54. /// of 0 means the value is inelastic. Must be in [0, 1] range.
  55. /// </summary>
  56. public float Restitution
  57. {
  58. get { return Internal_GetRestitution(mCachedPtr); }
  59. set { Internal_SetRestitution(mCachedPtr, value); }
  60. }
  61. [MethodImpl(MethodImplOptions.InternalCall)]
  62. private static extern void Internal_CreateInstance(PhysicsMaterial instance, float staticFriction,
  63. float dynamicFriction, float restitution);
  64. [MethodImpl(MethodImplOptions.InternalCall)]
  65. private static extern float Internal_GetStaticFriction(IntPtr thisPtr);
  66. [MethodImpl(MethodImplOptions.InternalCall)]
  67. private static extern void Internal_SetStaticFriction(IntPtr thisPtr, float value);
  68. [MethodImpl(MethodImplOptions.InternalCall)]
  69. private static extern float Internal_GetDynamicFriction(IntPtr thisPtr);
  70. [MethodImpl(MethodImplOptions.InternalCall)]
  71. private static extern void Internal_SetDynamicFriction(IntPtr thisPtr, float value);
  72. [MethodImpl(MethodImplOptions.InternalCall)]
  73. private static extern float Internal_GetRestitution(IntPtr thisPtr);
  74. [MethodImpl(MethodImplOptions.InternalCall)]
  75. private static extern void Internal_SetRestitution(IntPtr thisPtr, float value);
  76. }
  77. /** @} */
  78. }