Manual_Math.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  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 deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // 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 FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "../Precompiled.h"
  23. #include "../AngelScript/APITemplates.h"
  24. #include "../AngelScript/Manual_Math.h"
  25. namespace Urho3D
  26. {
  27. // This function is called before ASRegisterGenerated()
  28. void ASRegisterManualFirst_Math(asIScriptEngine* engine)
  29. {
  30. }
  31. // ========================================================================================
  32. // This function is called after ASRegisterGenerated()
  33. void ASRegisterManualLast_Math(asIScriptEngine* engine)
  34. {
  35. // template <class T, typename std::enable_if...> T Mod(T x, T y) | File: ../Math/MathDefs.h
  36. engine->RegisterGlobalFunction("float Mod(float, float)", asFUNCTION(Mod<float>), asCALL_CDECL);
  37. }
  38. // ========================================================================================
  39. // explicit IntVector2::IntVector2(const int *data) noexcept | File: ../Math/Vector2.h
  40. void ConstructIntVector2ArrayInit(CScriptArray* data, IntVector2* ptr)
  41. {
  42. new(ptr) IntVector2(static_cast<int*>(data->At(0)));
  43. }
  44. // const int* IntVector2::Data() const | File: ../Math/Vector2.h
  45. CScriptArray* IntVector2Data(IntVector2* ptr)
  46. {
  47. return BufferToArray<int>(ptr->Data(), 2, "int[]");
  48. }
  49. // ========================================================================================
  50. // explicit Vector2::Vector2(const float *data) noexcept | File: ../Math/Vector2.h
  51. void ConstructVector2ArrayInit(CScriptArray* data, Vector2* ptr)
  52. {
  53. new(ptr) Vector2(static_cast<float*>(data->At(0)));
  54. }
  55. // const float* Vector2::Data() const | File: ../Math/Vector2.h
  56. CScriptArray* Vector2Data(Vector2* ptr)
  57. {
  58. return BufferToArray<float>(ptr->Data(), 2, "float[]");
  59. }
  60. // ========================================================================================
  61. // explicit IntVector3::IntVector3(const int *data) noexcept | File: ../Math/Vector3.h
  62. void ConstructIntVector3ArrayInit(CScriptArray* data, IntVector3* ptr)
  63. {
  64. new(ptr) IntVector3(static_cast<int*>(data->At(0)));
  65. }
  66. // const int* IntVector3::Data() const | File: ../Math/Vector3.h
  67. CScriptArray* IntVector3Data(IntVector3* ptr)
  68. {
  69. return BufferToArray<int>(ptr->Data(), 3, "int[]");
  70. }
  71. // ========================================================================================
  72. // explicit Vector3::Vector3(const float *data) noexcept | File: ../Math/Vector3.h
  73. void ConstructVector3ArrayInit(CScriptArray* data, Vector3* ptr)
  74. {
  75. new(ptr) Vector3(static_cast<float*>(data->At(0)));
  76. }
  77. // const float* Vector3::Data() const | File: ../Math/Vector3.h
  78. CScriptArray* Vector3Data(Vector3* ptr)
  79. {
  80. return BufferToArray<float>(ptr->Data(), 3, "float[]");
  81. }
  82. // ========================================================================================
  83. // explicit Vector4::Vector4(const float *data) noexcept | File: ../Math/Vector4.h
  84. void ConstructVector4ArrayInit(CScriptArray* data, Vector4* ptr)
  85. {
  86. new(ptr) Vector4(static_cast<float*>(data->At(0)));
  87. }
  88. // const float* Vector4::Data() const | File: ../Math/Vector4.h
  89. CScriptArray* Vector4Data(Vector4* ptr)
  90. {
  91. return BufferToArray<float>(ptr->Data(), 4, "float[]");
  92. }
  93. // ========================================================================================
  94. // explicit IntRect::IntRect(const int *data) noexcept | File: ../Math/Rect.h
  95. void ConstructIntRectArrayInit(CScriptArray* data, IntRect* ptr)
  96. {
  97. new(ptr) IntRect(static_cast<int*>(data->At(0)));
  98. }
  99. // const int* IntRect::Data() const | File: ../Math/Rect.h
  100. CScriptArray* IntRectData(IntRect* ptr)
  101. {
  102. return BufferToArray<int>(ptr->Data(), 4, "int[]");
  103. }
  104. // ========================================================================================
  105. // explicit Color::Color(const float *data) noexcept | File: ../Math/Color.h
  106. void ConstructColorArrayInit(CScriptArray* data, Color* ptr)
  107. {
  108. new(ptr) Color(static_cast<float*>(data->At(0)));
  109. }
  110. // const float* Color::Data() const | File: ../Math/Color.h
  111. CScriptArray* ColorData(Color* ptr)
  112. {
  113. return BufferToArray<float>(ptr->Data(), 4, "float[]");
  114. }
  115. // ========================================================================================
  116. // Vector3 Frustum::vertices_[NUM_FRUSTUM_VERTICES] | File: ../Math/Frustum.h
  117. Vector3 FrustumGetVertex(unsigned index, Frustum* ptr)
  118. {
  119. if (index >= NUM_FRUSTUM_VERTICES)
  120. return Vector3::ZERO;
  121. return ptr->vertices_[index];
  122. }
  123. // ========================================================================================
  124. // Vector<PODVector<Vector3> > Polyhedron::faces_ | File: ../Math/Polyhedron.h
  125. unsigned PolyhedronGetNumFaces(Polyhedron* ptr)
  126. {
  127. return ptr->faces_.Size();
  128. }
  129. // Vector<PODVector<Vector3> > Polyhedron::faces_ | File: ../Math/Polyhedron.h
  130. CScriptArray* PolyhedronGetFace(unsigned index, Polyhedron* ptr)
  131. {
  132. PODVector<Vector3> face;
  133. if (index < ptr->faces_.Size())
  134. face = ptr->faces_[index];
  135. return VectorToArray<Vector3>(face, "Array<Vector3>");
  136. }
  137. }