NoiseGenerator_ScriptBinding.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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(NoiseGenerator, ScriptObject)
  23. /*! Sets the seed for the noise generater.
  24. @param seed An integer seed value.
  25. @return No return value.
  26. */
  27. ConsoleMethodWithDocs(NoiseGenerator, setSeed, ConsoleVoid, 3, 3, (int seed))
  28. {
  29. object->setSeed(dAtoi(argv[2]));
  30. }
  31. //------------------------------------------------------------------------------
  32. /*! Returns the noise for a given x and y value.
  33. * @param x A floating point value.
  34. * @param y A floating point value.
  35. @return A decimal value between 0 and 1.
  36. */
  37. ConsoleMethodWithDocs(NoiseGenerator, getNoise, ConsoleFloat, 3, 4, (float x, float y))
  38. {
  39. // Elements in the first argument.
  40. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  41. if (elementCount == 1 && argc == 4)
  42. {
  43. return object->getNoise(dAtof(argv[2]), dAtof(argv[3]));
  44. }
  45. else if (elementCount == 2 && argc == 3)
  46. {
  47. return object->getNoise(dAtof(Utility::mGetStringElement(argv[2], 0)), dAtof(Utility::mGetStringElement(argv[2], 1)));
  48. }
  49. else
  50. {
  51. Con::warnf("NoiseGenerator::getNoise() - Invalid number of parameters!");
  52. return 0.0f;
  53. }
  54. }
  55. //------------------------------------------------------------------------------
  56. /*! Returns the noise for a given x and y value with multiple octaves applied.
  57. * @param x A floating point value.
  58. * @param y A floating point value.
  59. * @param octaves An integer value between 1 and 8. Each octave is a layer of progressively smaller noise that is applied to the final result.
  60. * @param persistence A decimal value between 0.05 and 0.95. Larger values will cause each octave to have a larger impact on the final result.
  61. @return A decimal value between 0 and 1.
  62. */
  63. ConsoleMethodWithDocs(NoiseGenerator, getComplexNoise, ConsoleFloat, 6, 6, (float x, float y, int octaves, float persistence))
  64. {
  65. if (argc < 6)
  66. {
  67. Con::warnf("NoiseGenerator::getComplexNoise() - Invalid number of parameters!");
  68. return 0.0f;
  69. }
  70. else
  71. {
  72. return object->getComplexNoise(dAtof(argv[2]), dAtof(argv[3]), dAtoi(argv[4]), dAtof(argv[5]));
  73. }
  74. }
  75. ConsoleMethodGroupEndWithDocs(NoiseGenerator)