PointForceController_ScriptBinding.h 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. ConsoleMethod(PointForceController, setPosition, void, 3, 4, "(float x, float y) - Sets the position of the force center.\n"
  23. "@param x The position along the horizontal axis.\n"
  24. "@param y The position along the vertical axis.\n"
  25. "@return No return value.")
  26. {
  27. // The new position.
  28. b2Vec2 position;
  29. // Elements in the first argument.
  30. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  31. // ("x y")
  32. if ((elementCount == 2) && (argc == 3))
  33. position = Utility::mGetStringElementVector(argv[2]);
  34. // (x, y)
  35. else if ((elementCount == 1) && (argc == 4))
  36. position.Set(dAtof(argv[2]), dAtof(argv[3]));
  37. // Invalid
  38. else
  39. {
  40. Con::warnf("PointForceController::setPosition() - Invalid number of parameters!");
  41. return;
  42. }
  43. // Set Position.
  44. object->setPosition(position);
  45. }
  46. //-----------------------------------------------------------------------------
  47. ConsoleMethod(PointForceController, PointForceController, const char*, 2, 2, "() Gets the position of the force center.\n"
  48. "@return (float x/float y) The x and y (horizontal and vertical) position of the force center.")
  49. {
  50. // Get position.
  51. return object->getPosition().scriptThis();
  52. }
  53. //-----------------------------------------------------------------------------
  54. ConsoleMethod(PointForceController, setRadius, void, 3, 3, "(radius) - Sets the radius of the point force to use.\n"
  55. "@param radius The radius of the point force to use.\n"
  56. "@return No return value.")
  57. {
  58. object->setRadius( dAtof(argv[2]) );
  59. }
  60. //-----------------------------------------------------------------------------
  61. ConsoleMethod(PointForceController, getRadius, F32, 2, 2, "() Gets the radius of the point force being used.\n"
  62. "@return The radius of the point force being used.")
  63. {
  64. return object->getRadius();
  65. }
  66. //-----------------------------------------------------------------------------
  67. ConsoleMethod(PointForceController, setForce, void, 3, 3, "(force) - Sets the point force to use.\n"
  68. "@param force The point force to use.\n"
  69. "@return No return value.")
  70. {
  71. object->setForce( dAtof(argv[2]) );
  72. }
  73. //-----------------------------------------------------------------------------
  74. ConsoleMethod(PointForceController, getForce, F32, 2, 2, "() Gets the point force being used.\n"
  75. "@return The point force being used.")
  76. {
  77. return object->getForce();
  78. }