PointForceController_ScriptBinding.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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, getPosition, 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. }
  79. //-----------------------------------------------------------------------------
  80. ConsoleMethod(PointForceController, setLinearDrag, void, 3, 3, "(linearDrag) - Sets the linear drag coefficient (0.0 to 1.0).\n"
  81. "@param linearDrag The linear drag coefficient\n"
  82. "@return No return value.")
  83. {
  84. object->setLinearDrag( dAtof(argv[2]) );
  85. }
  86. //-----------------------------------------------------------------------------
  87. ConsoleMethod(PointForceController, getLinearDrag, F32, 2, 2, "() Gets the linear drag coefficient.\n"
  88. "@return The linear drag coefficient.")
  89. {
  90. return object->getLinearDrag();
  91. }
  92. //-----------------------------------------------------------------------------
  93. ConsoleMethod(PointForceController, setAngularDrag, void, 3, 3, "(angularDrag) - Sets the angular drag coefficient (0.0 to 1.0).\n"
  94. "@param angularDrag The angular drag coefficient\n"
  95. "@return No return value.")
  96. {
  97. object->setAngularDrag( dAtof(argv[2]) );
  98. }
  99. //-----------------------------------------------------------------------------
  100. ConsoleMethod(PointForceController, getAngularDrag, F32, 2, 2, "() Gets the angular drag coefficient.\n"
  101. "@return The angular drag coefficient.")
  102. {
  103. return object->getAngularDrag();
  104. }
  105. //-----------------------------------------------------------------------------
  106. ConsoleMethod(PointForceController, setNonLinear, void, 3, 3, "(nonLinear) - Sets whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  107. "@param nonLinear whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  108. "@return No return value.")
  109. {
  110. object->setNonLinear( dAtob(argv[2]) );
  111. }
  112. //-----------------------------------------------------------------------------
  113. ConsoleMethod(PointForceController, getNonLinear, bool, 2, 2, "() Gets whether to apply the force non-linearly (using the inverse square law) or linearly.\n"
  114. "@return Whether to apply the force non-linearly (using the inverse square law) or linearly.")
  115. {
  116. return object->getNonLinear();
  117. }
  118. //-----------------------------------------------------------------------------
  119. ConsoleMethod(PointForceController, setTrackedObject, void, 3, 3, "(sceneObject) - Sets a scene object from which the position will be tracked.\n"
  120. "@param sceneObject The scene object from which the position will be tracked. An empty string will stop tracking.\n"
  121. "@return No return value.")
  122. {
  123. // Find the scene object.
  124. SceneObject* pSceneObject = Sim::findObject<SceneObject>( argv[2] );
  125. object->setTrackedObject( pSceneObject );
  126. }
  127. //-----------------------------------------------------------------------------
  128. ConsoleMethod(PointForceController, getTrackedObject, const char*, 2, 2, "() - Gets the scene object from which the position will be tracked.\n"
  129. "@return The scene object from which the position will be tracked or an empty string if nothing is being tracked.")
  130. {
  131. // Fetch the scene object.
  132. SceneObject* pSceneObject = object->getTrackedObject();
  133. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  134. }