PhysicsMaterial.cs 4.0 KB

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