PointForceController_ScriptBinding.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <<<<<<< HEAD
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2013 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. ConsoleMethodGroupBeginWithDocs(PointForceController, PickingSceneController)
  24. /*! Sets the position of the force center.
  25. @param x The position along the horizontal axis.
  26. @param y The position along the vertical axis.
  27. @return No return value.
  28. */
  29. ConsoleMethodWithDocs(PointForceController, setPosition, ConsoleVoid, 3, 4, (float x, float y))
  30. {
  31. // The new position.
  32. b2Vec2 position;
  33. // Elements in the first argument.
  34. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  35. // ("x y")
  36. if ((elementCount == 2) && (argc == 3))
  37. position = Utility::mGetStringElementVector(argv[2]);
  38. // (x, y)
  39. else if ((elementCount == 1) && (argc == 4))
  40. position.Set(dAtof(argv[2]), dAtof(argv[3]));
  41. // Invalid
  42. else
  43. {
  44. Con::warnf("PointForceController::setPosition() - Invalid number of parameters!");
  45. return;
  46. }
  47. // Set Position.
  48. object->setPosition(position);
  49. }
  50. //-----------------------------------------------------------------------------
  51. /*! Gets the position of the force center.
  52. @return (float x/float y) The x and y (horizontal and vertical) position of the force center.
  53. */
  54. ConsoleMethodWithDocs(PointForceController, PointForceController, ConsoleString, 2, 2, ())
  55. {
  56. // Get position.
  57. return object->getPosition().scriptThis();
  58. }
  59. //-----------------------------------------------------------------------------
  60. /*! Sets the radius of the point force to use.
  61. @param radius The radius of the point force to use.
  62. @return No return value.
  63. */
  64. ConsoleMethodWithDocs(PointForceController, setRadius, ConsoleVoid, 3, 3, (radius))
  65. {
  66. object->setRadius( dAtof(argv[2]) );
  67. }
  68. //-----------------------------------------------------------------------------
  69. /*! Gets the radius of the point force being used.
  70. @return The radius of the point force being used.
  71. */
  72. ConsoleMethodWithDocs(PointForceController, getRadius, ConsoleFloat, 2, 2, ())
  73. {
  74. return object->getRadius();
  75. }
  76. //-----------------------------------------------------------------------------
  77. /*! Sets the point force to use.
  78. @param force The point force to use.
  79. @return No return value.
  80. */
  81. ConsoleMethodWithDocs(PointForceController, setForce, ConsoleVoid, 3, 3, (force))
  82. {
  83. object->setForce( dAtof(argv[2]) );
  84. }
  85. //-----------------------------------------------------------------------------
  86. /*! Gets the point force being used.
  87. @return The point force being used.
  88. */
  89. ConsoleMethodWithDocs(PointForceController, getForce, ConsoleFloat, 2, 2, ())
  90. {
  91. return object->getForce();
  92. }
  93. //-----------------------------------------------------------------------------
  94. /*! Sets the linear drag coefficient (0.0 to 1.0).
  95. @param linearDrag The linear drag coefficient
  96. @return No return value.
  97. */
  98. ConsoleMethodWithDocs(PointForceController, setLinearDrag, ConsoleVoid, 3, 3, (linearDrag))
  99. {
  100. object->setLinearDrag( dAtof(argv[2]) );
  101. }
  102. //-----------------------------------------------------------------------------
  103. /*! Gets the linear drag coefficient.
  104. @return The linear drag coefficient.
  105. */
  106. ConsoleMethodWithDocs(PointForceController, getLinearDrag, ConsoleFloat, 2, 2, ())
  107. {
  108. return object->getLinearDrag();
  109. }
  110. //-----------------------------------------------------------------------------
  111. /*! Sets the angular drag coefficient (0.0 to 1.0).
  112. @param angularDrag The angular drag coefficient
  113. @return No return value.
  114. */
  115. ConsoleMethodWithDocs(PointForceController, setAngularDrag, ConsoleVoid, 3, 3, (angularDrag))
  116. {
  117. object->setAngularDrag( dAtof(argv[2]) );
  118. }
  119. //-----------------------------------------------------------------------------
  120. /*! Gets the angular drag coefficient.
  121. @return The angular drag coefficient.
  122. */
  123. ConsoleMethodWithDocs(PointForceController, getAngularDrag, ConsoleFloat, 2, 2, ())
  124. {
  125. return object->getAngularDrag();
  126. }
  127. //-----------------------------------------------------------------------------
  128. /*! Sets whether to apply the force non-linearly (using the inverse square law) or linearly.
  129. @param nonLinear whether to apply the force non-linearly (using the inverse square law) or linearly.
  130. @return No return value.
  131. */
  132. ConsoleMethodWithDocs(PointForceController, setNonLinear, ConsoleVoid, 3, 3, (nonLinear))
  133. {
  134. object->setNonLinear( dAtob(argv[2]) );
  135. }
  136. //-----------------------------------------------------------------------------
  137. /*! Gets whether to apply the force non-linearly (using the inverse square law) or linearly.
  138. @return Whether to apply the force non-linearly (using the inverse square law) or linearly.
  139. */
  140. ConsoleMethodWithDocs(PointForceController, getNonLinear, ConsoleBool, 2, 2, ())
  141. {
  142. return object->getNonLinear();
  143. }
  144. //-----------------------------------------------------------------------------
  145. /*! Sets a scene object from which the position will be tracked.
  146. @param sceneObject The scene object from which the position will be tracked. An empty string will stop tracking.
  147. @return No return value.
  148. */
  149. ConsoleMethodWithDocs(PointForceController, setTrackedObject, ConsoleVoid, 3, 3, (sceneObject))
  150. {
  151. // Find the scene object.
  152. SceneObject* pSceneObject = Sim::findObject<SceneObject>( argv[2] );
  153. object->setTrackedObject( pSceneObject );
  154. }
  155. //-----------------------------------------------------------------------------
  156. /*! Gets the scene object from which the position will be tracked.
  157. @return The scene object from which the position will be tracked or an empty string if nothing is being tracked.
  158. */
  159. ConsoleMethodWithDocs(PointForceController, getTrackedObject, ConsoleString, 2, 2, ())
  160. {
  161. // Fetch the scene object.
  162. SceneObject* pSceneObject = object->getTrackedObject();
  163. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  164. }
  165. ConsoleMethodGroupEndWithDocs(PointForceController)
  166. =======
  167. //-----------------------------------------------------------------------------
  168. // Copyright (c) 2013 GarageGames, LLC
  169. //
  170. // Permission is hereby granted, free of charge, to any person obtaining a copy
  171. // of this software and associated documentation files (the "Software"), to
  172. // deal in the Software without restriction, including without limitation the
  173. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  174. // sell copies of the Software, and to permit persons to whom the Software is
  175. // furnished to do so, subject to the following conditions:
  176. //
  177. // The above copyright notice and this permission notice shall be included in
  178. // all copies or substantial portions of the Software.
  179. //
  180. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  181. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  182. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  183. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  184. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  185. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  186. // IN THE SOFTWARE.
  187. //-----------------------------------------------------------------------------
  188. ConsoleMethod(PointForceController, setPosition, void, 3, 4, "(float x, float y) - Sets the position of the force center.\n"
  189. "@param x The position along the horizontal axis.\n"
  190. "@param y The position along the vertical axis.\n"
  191. "@return No return value.")
  192. {
  193. // The new position.
  194. b2Vec2 position;
  195. // Elements in the first argument.
  196. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  197. // ("x y")
  198. if ((elementCount == 2) && (argc == 3))
  199. position = Utility::mGetStringElementVector(argv[2]);
  200. // (x, y)
  201. else if ((elementCount == 1) && (argc == 4))
  202. position.Set(dAtof(argv[2]), dAtof(argv[3]));
  203. // Invalid
  204. else
  205. {
  206. Con::warnf("PointForceController::setPosition() - Invalid number of parameters!");
  207. return;
  208. }
  209. // Set Position.
  210. object->setPosition(position);
  211. }
  212. //-----------------------------------------------------------------------------
  213. ConsoleMethod(PointForceController, getPosition, const char*, 2, 2, "() Gets the position of the force center.\n"
  214. "@return (float x/float y) The x and y (horizontal and vertical) position of the force center.")
  215. {
  216. // Get position.
  217. return object->getPosition().scriptThis();
  218. }
  219. //-----------------------------------------------------------------------------
  220. ConsoleMethod(PointForceController, setRadius, void, 3, 3, "(radius) - Sets the radius of the point force to use.\n"
  221. "@param radius The radius of the point force to use.\n"
  222. "@return No return value.")
  223. {
  224. object->setRadius( dAtof(argv[2]) );
  225. }
  226. //-----------------------------------------------------------------------------
  227. ConsoleMethod(PointForceController, getRadius, F32, 2, 2, "() Gets the radius of the point force being used.\n"
  228. "@return The radius of the point force being used.")
  229. {
  230. return object->getRadius();
  231. }
  232. //-----------------------------------------------------------------------------
  233. ConsoleMethod(PointForceController, setForce, void, 3, 3, "(force) - Sets the point force to use.\n"
  234. "@param force The point force to use.\n"
  235. "@return No return value.")
  236. {
  237. object->setForce( dAtof(argv[2]) );
  238. }
  239. //-----------------------------------------------------------------------------
  240. ConsoleMethod(PointForceController, getForce, F32, 2, 2, "() Gets the point force being used.\n"
  241. "@return The point force being used.")
  242. {
  243. return object->getForce();
  244. }
  245. //-----------------------------------------------------------------------------
  246. ConsoleMethod(PointForceController, setLinearDrag, void, 3, 3, "(linearDrag) - Sets the linear drag coefficient (0.0 to 1.0).\n"
  247. "@param linearDrag The linear drag coefficient\n"
  248. "@return No return value.")
  249. {
  250. object->setLinearDrag( dAtof(argv[2]) );
  251. }
  252. //-----------------------------------------------------------------------------
  253. ConsoleMethod(PointForceController, getLinearDrag, F32, 2, 2, "() Gets the linear drag coefficient.\n"
  254. "@return The linear drag coefficient.")
  255. {
  256. return object->getLinearDrag();
  257. }
  258. //-----------------------------------------------------------------------------
  259. ConsoleMethod(PointForceController, setAngularDrag, void, 3, 3, "(angularDrag) - Sets the angular drag coefficient (0.0 to 1.0).\n"
  260. "@param angularDrag The angular drag coefficient\n"
  261. "@return No return value.")
  262. {
  263. object->setAngularDrag( dAtof(argv[2]) );
  264. }
  265. //-----------------------------------------------------------------------------
  266. ConsoleMethod(PointForceController, getAngularDrag, F32, 2, 2, "() Gets the angular drag coefficient.\n"
  267. "@return The angular drag coefficient.")
  268. {
  269. return object->getAngularDrag();
  270. }
  271. //-----------------------------------------------------------------------------
  272. ConsoleMethod(PointForceController, setNonLinear, void, 3, 3, "(nonLinear) - Sets whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  273. "@param nonLinear whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  274. "@return No return value.")
  275. {
  276. object->setNonLinear( dAtob(argv[2]) );
  277. }
  278. //-----------------------------------------------------------------------------
  279. ConsoleMethod(PointForceController, getNonLinear, bool, 2, 2, "() Gets whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  280. "@return Whether to apply the force non-linearly (using the inverse square law) or linearly.")
  281. {
  282. return object->getNonLinear();
  283. }
  284. //-----------------------------------------------------------------------------
  285. ConsoleMethod(PointForceController, setTrackedObject, void, 3, 3, "(sceneObject) - Sets a scene object from which the position will be tracked.\n"
  286. "@param sceneObject The scene object from which the position will be tracked. An empty string will stop tracking.\n"
  287. "@return No return value.")
  288. {
  289. // Find the scene object.
  290. SceneObject* pSceneObject = Sim::findObject<SceneObject>( argv[2] );
  291. object->setTrackedObject( pSceneObject );
  292. }
  293. //-----------------------------------------------------------------------------
  294. ConsoleMethod(PointForceController, getTrackedObject, const char*, 2, 2, "() - Gets the scene object from which the position will be tracked.\n"
  295. "@return The scene object from which the position will be tracked or an empty string if nothing is being tracked.")
  296. {
  297. // Fetch the scene object.
  298. SceneObject* pSceneObject = object->getTrackedObject();
  299. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  300. }
  301. >>>>>>> 6e2964681666532c99f49535de98f93c3b6dfb24