collisionComponent_ScriptBinding.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "console/engineAPI.h"
  23. #include "T3D/components/collision/collisioncomponent.h"
  24. #include "materials/baseMatInstance.h"
  25. DefineConsoleMethod(CollisionComponent, getNumberOfContacts, S32, (), ,
  26. "Gets the number of contacts this collider has hit.\n"
  27. "@return The number of static fields defined on the object.")
  28. {
  29. return object->getCollisionList()->getCount();
  30. }
  31. DefineConsoleMethod(CollisionComponent, getBestContact, S32, (), ,
  32. "Gets the number of contacts this collider has hit.\n"
  33. "@return The number of static fields defined on the object.")
  34. {
  35. return 0;
  36. }
  37. DefineConsoleMethod(CollisionComponent, getContactNormal, Point3F, (), ,
  38. "Gets the number of contacts this collider has hit.\n"
  39. "@return The number of static fields defined on the object.")
  40. {
  41. if (object->getContactInfo())
  42. {
  43. if (object->getContactInfo()->contactObject)
  44. {
  45. return object->getContactInfo()->contactNormal;
  46. }
  47. }
  48. return Point3F::Zero;
  49. }
  50. DefineConsoleMethod(CollisionComponent, getContactMaterial, S32, (), ,
  51. "Gets the number of contacts this collider has hit.\n"
  52. "@return The number of static fields defined on the object.")
  53. {
  54. if (object->getContactInfo())
  55. {
  56. if (object->getContactInfo()->contactObject)
  57. {
  58. if (object->getContactInfo()->contactMaterial != NULL)
  59. return object->getContactInfo()->contactMaterial->getMaterial()->getId();
  60. }
  61. }
  62. return 0;
  63. }
  64. DefineConsoleMethod(CollisionComponent, getContactObject, S32, (), ,
  65. "Gets the number of contacts this collider has hit.\n"
  66. "@return The number of static fields defined on the object.")
  67. {
  68. if (object->getContactInfo())
  69. {
  70. return object->getContactInfo()->contactObject != NULL ? object->getContactInfo()->contactObject->getId() : 0;
  71. }
  72. return 0;
  73. }
  74. DefineConsoleMethod(CollisionComponent, getContactPoint, Point3F, (), ,
  75. "Gets the number of contacts this collider has hit.\n"
  76. "@return The number of static fields defined on the object.")
  77. {
  78. if (object->getContactInfo())
  79. {
  80. if (object->getContactInfo()->contactObject)
  81. {
  82. return object->getContactInfo()->contactPoint;
  83. }
  84. }
  85. return Point3F::Zero;
  86. }
  87. DefineConsoleMethod(CollisionComponent, getContactTime, S32, (), ,
  88. "Gets the number of contacts this collider has hit.\n"
  89. "@return The number of static fields defined on the object.")
  90. {
  91. if (object->getContactInfo())
  92. {
  93. if (object->getContactInfo()->contactObject)
  94. {
  95. return object->getContactInfo()->contactTimer;
  96. }
  97. }
  98. return 0;
  99. }
  100. DefineEngineMethod(CollisionComponent, hasContact, bool, (), ,
  101. "@brief Apply an impulse to this object as defined by a world position and velocity vector.\n\n"
  102. "@param pos impulse world position\n"
  103. "@param vel impulse velocity (impulse force F = m * v)\n"
  104. "@return Always true\n"
  105. "@note Not all objects that derrive from GameBase have this defined.\n")
  106. {
  107. return object->hasContact();
  108. }
  109. DefineEngineMethod(CollisionComponent, getCollisionCount, S32, (), ,
  110. "@brief Apply an impulse to this object as defined by a world position and velocity vector.\n\n"
  111. "@param pos impulse world position\n"
  112. "@param vel impulse velocity (impulse force F = m * v)\n"
  113. "@return Always true\n"
  114. "@note Not all objects that derrive from GameBase have this defined.\n")
  115. {
  116. return object->getCollisionCount();
  117. }
  118. DefineEngineMethod(CollisionComponent, getCollisionNormal, Point3F, (S32 collisionIndex), ,
  119. "@brief Apply an impulse to this object as defined by a world position and velocity vector.\n\n"
  120. "@param pos impulse world position\n"
  121. "@param vel impulse velocity (impulse force F = m * v)\n"
  122. "@return Always true\n"
  123. "@note Not all objects that derrive from GameBase have this defined.\n")
  124. {
  125. return object->getCollisionNormal(collisionIndex);
  126. }
  127. DefineEngineMethod(CollisionComponent, getCollisionAngle, F32, (S32 collisionIndex, VectorF upVector), ,
  128. "@brief Apply an impulse to this object as defined by a world position and velocity vector.\n\n"
  129. "@param pos impulse world position\n"
  130. "@param vel impulse velocity (impulse force F = m * v)\n"
  131. "@return Always true\n"
  132. "@note Not all objects that derrive from GameBase have this defined.\n")
  133. {
  134. return object->getCollisionAngle(collisionIndex, upVector);
  135. }
  136. DefineEngineMethod(CollisionComponent, getBestCollisionAngle, F32, (VectorF upVector), ,
  137. "@brief Apply an impulse to this object as defined by a world position and velocity vector.\n\n"
  138. "@param pos impulse world position\n"
  139. "@param vel impulse velocity (impulse force F = m * v)\n"
  140. "@return Always true\n"
  141. "@note Not all objects that derrive from GameBase have this defined.\n")
  142. {
  143. return object->getBestCollisionAngle(upVector);
  144. }