PointForceController_ScriptBinding.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. ConsoleMethodGroupBeginWithDocs(PointForceController, PickingSceneController)
  23. /*! Sets the position of the force center.
  24. @param x The position along the horizontal axis.
  25. @param y The position along the vertical axis.
  26. @return No return value.
  27. */
  28. ConsoleMethodWithDocs(PointForceController, setPosition, ConsoleVoid, 3, 4, (float x, float y))
  29. {
  30. // The new position.
  31. b2Vec2 position;
  32. // Elements in the first argument.
  33. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  34. // ("x y")
  35. if ((elementCount == 2) && (argc == 3))
  36. position = Utility::mGetStringElementVector(argv[2]);
  37. // (x, y)
  38. else if ((elementCount == 1) && (argc == 4))
  39. position.Set(dAtof(argv[2]), dAtof(argv[3]));
  40. // Invalid
  41. else
  42. {
  43. Con::warnf("PointForceController::setPosition() - Invalid number of parameters!");
  44. return;
  45. }
  46. // Set Position.
  47. object->setPosition(position);
  48. }
  49. //-----------------------------------------------------------------------------
  50. /*! Gets the position of the force center.
  51. @return (float x/float y) The x and y (horizontal and vertical) position of the force center.
  52. */
  53. ConsoleMethodWithDocs(PointForceController, PointForceController, ConsoleString, 2, 2, ())
  54. {
  55. // Get position.
  56. return object->getPosition().scriptThis();
  57. }
  58. //-----------------------------------------------------------------------------
  59. /*! Sets the radius of the point force to use.
  60. @param radius The radius of the point force to use.
  61. @return No return value.
  62. */
  63. ConsoleMethodWithDocs(PointForceController, setRadius, ConsoleVoid, 3, 3, (radius))
  64. {
  65. object->setRadius( dAtof(argv[2]) );
  66. }
  67. //-----------------------------------------------------------------------------
  68. /*! Gets the radius of the point force being used.
  69. @return The radius of the point force being used.
  70. */
  71. ConsoleMethodWithDocs(PointForceController, getRadius, ConsoleFloat, 2, 2, ())
  72. {
  73. return object->getRadius();
  74. }
  75. //-----------------------------------------------------------------------------
  76. /*! Sets the point force to use.
  77. @param force The point force to use.
  78. @return No return value.
  79. */
  80. ConsoleMethodWithDocs(PointForceController, setForce, ConsoleVoid, 3, 3, (force))
  81. {
  82. object->setForce( dAtof(argv[2]) );
  83. }
  84. //-----------------------------------------------------------------------------
  85. /*! Gets the point force being used.
  86. @return The point force being used.
  87. */
  88. ConsoleMethodWithDocs(PointForceController, getForce, ConsoleFloat, 2, 2, ())
  89. {
  90. return object->getForce();
  91. }
  92. //-----------------------------------------------------------------------------
  93. /*! Sets the linear drag coefficient (0.0 to 1.0).
  94. @param linearDrag The linear drag coefficient
  95. @return No return value.
  96. */
  97. ConsoleMethodWithDocs(PointForceController, setLinearDrag, ConsoleVoid, 3, 3, (linearDrag))
  98. {
  99. object->setLinearDrag( dAtof(argv[2]) );
  100. }
  101. //-----------------------------------------------------------------------------
  102. /*! Gets the linear drag coefficient.
  103. @return The linear drag coefficient.
  104. */
  105. ConsoleMethodWithDocs(PointForceController, getLinearDrag, ConsoleFloat, 2, 2, ())
  106. {
  107. return object->getLinearDrag();
  108. }
  109. //-----------------------------------------------------------------------------
  110. /*! Sets the angular drag coefficient (0.0 to 1.0).
  111. @param angularDrag The angular drag coefficient
  112. @return No return value.
  113. */
  114. ConsoleMethodWithDocs(PointForceController, setAngularDrag, ConsoleVoid, 3, 3, (angularDrag))
  115. {
  116. object->setAngularDrag( dAtof(argv[2]) );
  117. }
  118. //-----------------------------------------------------------------------------
  119. /*! Gets the angular drag coefficient.
  120. @return The angular drag coefficient.
  121. */
  122. ConsoleMethodWithDocs(PointForceController, getAngularDrag, ConsoleFloat, 2, 2, ())
  123. {
  124. return object->getAngularDrag();
  125. }
  126. //-----------------------------------------------------------------------------
  127. /*! Sets whether to apply the force non-linearly (using the inverse square law) or linearly.
  128. @param nonLinear whether to apply the force non-linearly (using the inverse square law) or linearly.
  129. @return No return value.
  130. */
  131. ConsoleMethodWithDocs(PointForceController, setNonLinear, ConsoleVoid, 3, 3, (nonLinear))
  132. {
  133. object->setNonLinear( dAtob(argv[2]) );
  134. }
  135. //-----------------------------------------------------------------------------
  136. /*! Gets whether to apply the force non-linearly (using the inverse square law) or linearly.
  137. @return Whether to apply the force non-linearly (using the inverse square law) or linearly.
  138. */
  139. ConsoleMethodWithDocs(PointForceController, getNonLinear, ConsoleBool, 2, 2, ())
  140. {
  141. return object->getNonLinear();
  142. }
  143. //-----------------------------------------------------------------------------
  144. /*! Sets a scene object from which the position will be tracked.
  145. @param sceneObject The scene object from which the position will be tracked. An empty string will stop tracking.
  146. @return No return value.
  147. */
  148. ConsoleMethodWithDocs(PointForceController, setTrackedObject, ConsoleVoid, 3, 3, (sceneObject))
  149. {
  150. // Find the scene object.
  151. SceneObject* pSceneObject = Sim::findObject<SceneObject>( argv[2] );
  152. object->setTrackedObject( pSceneObject );
  153. }
  154. //-----------------------------------------------------------------------------
  155. /*! Gets the scene object from which the position will be tracked.
  156. @return The scene object from which the position will be tracked or an empty string if nothing is being tracked.
  157. */
  158. ConsoleMethodWithDocs(PointForceController, getTrackedObject, ConsoleString, 2, 2, ())
  159. {
  160. // Fetch the scene object.
  161. SceneObject* pSceneObject = object->getTrackedObject();
  162. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  163. }
  164. ConsoleMethodGroupEndWithDocs(PointForceController)