MathAPI.cpp 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  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 deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // 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 FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Frustum.h"
  25. #include "StringUtils.h"
  26. #include <angelscript.h>
  27. static float Sin(float angle)
  28. {
  29. return sinf(angle * M_DEGTORAD);
  30. }
  31. static float Cos(float angle)
  32. {
  33. return cosf(angle * M_DEGTORAD);
  34. }
  35. static float Tan(float angle)
  36. {
  37. return tanf(angle * M_DEGTORAD);
  38. }
  39. static float Asin(float x)
  40. {
  41. return M_RADTODEG * asinf(Clamp(x, -1.0f, 1.0f));
  42. }
  43. static float Acos(float x)
  44. {
  45. return M_RADTODEG * acosf(Clamp(x, -1.0f, 1.0f));
  46. }
  47. static float Atan(float x)
  48. {
  49. return M_RADTODEG * atanf(x);
  50. }
  51. static float Atan2(float y, float x)
  52. {
  53. return M_RADTODEG * atan2f(y, x);
  54. }
  55. static void RegisterMathFunctions(asIScriptEngine* engine)
  56. {
  57. engine->RegisterGlobalProperty("const float M_INFINITY", (void*)&M_INFINITY);
  58. engine->RegisterGlobalProperty("const float M_EPSILON", (void*)&M_EPSILON);
  59. engine->RegisterGlobalFunction("bool Equals(float, float)", asFUNCTION(Equals), asCALL_CDECL);
  60. engine->RegisterGlobalFunction("float Sin(float)", asFUNCTION(Sin), asCALL_CDECL);
  61. engine->RegisterGlobalFunction("float Cos(float)", asFUNCTION(Cos), asCALL_CDECL);
  62. engine->RegisterGlobalFunction("float Tan(float)", asFUNCTION(Tan), asCALL_CDECL);
  63. engine->RegisterGlobalFunction("float Asin(float)", asFUNCTION(Asin), asCALL_CDECL);
  64. engine->RegisterGlobalFunction("float Acos(float)", asFUNCTION(Acos), asCALL_CDECL);
  65. engine->RegisterGlobalFunction("float Atan(float)", asFUNCTION(Atan), asCALL_CDECL);
  66. engine->RegisterGlobalFunction("float Atan2(float, float)", asFUNCTION(Atan2), asCALL_CDECL);
  67. engine->RegisterGlobalFunction("float Abs(float)", asFUNCTION(fabsf), asCALL_CDECL);
  68. engine->RegisterGlobalFunction("float Sqrt(float)", asFUNCTION(sqrtf), asCALL_CDECL);
  69. engine->RegisterGlobalFunction("float Pow(float)", asFUNCTION(powf), asCALL_CDECL);
  70. engine->RegisterGlobalFunction("float Random()", asFUNCTIONPR(Random, (), float), asCALL_CDECL);
  71. engine->RegisterGlobalFunction("float Random(float)", asFUNCTIONPR(Random, (float), float), asCALL_CDECL);
  72. engine->RegisterGlobalFunction("int RandomInt()", asFUNCTION(rand), asCALL_CDECL);
  73. engine->RegisterGlobalFunction("int RandomInt(int)", asFUNCTIONPR(Random, (int), int), asCALL_CDECL);
  74. engine->RegisterGlobalFunction("void SetRandomSeed(int)", asFUNCTION(srand), asCALL_CDECL);
  75. engine->RegisterGlobalFunction("float Min(float, float)", asFUNCTIONPR(Min, (float, float), float), asCALL_CDECL);
  76. engine->RegisterGlobalFunction("float Max(float, float)", asFUNCTIONPR(Max, (float, float), float), asCALL_CDECL);
  77. engine->RegisterGlobalFunction("float Clamp(float, float, float)", asFUNCTIONPR(Clamp, (float, float, float), float), asCALL_CDECL);
  78. engine->RegisterGlobalFunction("float Lerp(float, float, float)", asFUNCTIONPR(Lerp, (float, float, float), float), asCALL_CDECL);
  79. engine->RegisterGlobalFunction("float Mod(float, float)", asFUNCTION(fmodf), asCALL_CDECL);
  80. engine->RegisterGlobalFunction("float Floor(float)", asFUNCTION(floorf), asCALL_CDECL);
  81. engine->RegisterGlobalFunction("float Ceil(float)", asFUNCTION(ceilf), asCALL_CDECL);
  82. }
  83. static void ConstructIntRect(IntRect* ptr)
  84. {
  85. // Init to zero because performance is not critical
  86. new(ptr) IntRect(IntRect::ZERO);
  87. }
  88. static void ConstructIntRectCopy(const IntRect& rect, IntRect* ptr)
  89. {
  90. new(ptr) IntRect(rect);
  91. }
  92. static void ConstructIntRectInit(int left, int top, int right, int bottom, IntRect* ptr)
  93. {
  94. new(ptr) IntRect(left, top, right, bottom);
  95. }
  96. static void RegisterIntRect(asIScriptEngine* engine)
  97. {
  98. engine->RegisterObjectType("IntRect", sizeof(IntRect), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  99. engine->RegisterObjectBehaviour("IntRect", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructIntRect), asCALL_CDECL_OBJLAST);
  100. engine->RegisterObjectBehaviour("IntRect", asBEHAVE_CONSTRUCT, "void f(const IntRect&in)", asFUNCTION(ConstructIntRectCopy), asCALL_CDECL_OBJLAST);
  101. engine->RegisterObjectBehaviour("IntRect", asBEHAVE_CONSTRUCT, "void f(int, int, int, int)", asFUNCTION(ConstructIntRectInit), asCALL_CDECL_OBJLAST);
  102. engine->RegisterObjectMethod("IntRect", "IntRect &opAssign(const IntRect&in)", asMETHOD(IntRect, operator =), asCALL_THISCALL);
  103. engine->RegisterObjectMethod("IntRect", "bool opEquals(const IntRect&in) const", asMETHOD(IntRect, operator ==), asCALL_THISCALL);
  104. engine->RegisterObjectProperty("IntRect", "int left", offsetof(IntRect, left_));
  105. engine->RegisterObjectProperty("IntRect", "int top", offsetof(IntRect, top_));
  106. engine->RegisterObjectProperty("IntRect", "int right", offsetof(IntRect, right_));
  107. engine->RegisterObjectProperty("IntRect", "int bottom", offsetof(IntRect, bottom_));
  108. }
  109. static void ConstructIntVector2(IntVector2* ptr)
  110. {
  111. // Init to zero because performance is not critical
  112. new(ptr) IntVector2(IntVector2::ZERO);
  113. }
  114. static void ConstructIntVector2Copy(const IntVector2& vector, IntVector2* ptr)
  115. {
  116. new(ptr) IntVector2(vector);
  117. }
  118. static void ConstructIntVector2Init(int x, int y, IntVector2* ptr)
  119. {
  120. new(ptr) IntVector2(x, y);
  121. }
  122. static void RegisterIntVector2(asIScriptEngine* engine)
  123. {
  124. engine->RegisterObjectType("IntVector2", sizeof(IntVector2), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  125. engine->RegisterObjectBehaviour("IntVector2", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructIntVector2), asCALL_CDECL_OBJLAST);
  126. engine->RegisterObjectBehaviour("IntVector2", asBEHAVE_CONSTRUCT, "void f(const IntVector2&in)", asFUNCTION(ConstructIntVector2Copy), asCALL_CDECL_OBJLAST);
  127. engine->RegisterObjectBehaviour("IntVector2", asBEHAVE_CONSTRUCT, "void f(int, int)", asFUNCTION(ConstructIntVector2Init), asCALL_CDECL_OBJLAST);
  128. engine->RegisterObjectMethod("IntVector2", "IntVector2 &opAssign(const IntVector2&in)", asMETHOD(IntVector2, operator =), asCALL_THISCALL);
  129. engine->RegisterObjectMethod("IntVector2", "IntVector2 &opAddAssign(const IntVector2&in)", asMETHOD(IntVector2, operator +=), asCALL_THISCALL);
  130. engine->RegisterObjectMethod("IntVector2", "IntVector2 &opSubAssign(const IntVector2&in)", asMETHOD(IntVector2, operator -=), asCALL_THISCALL);
  131. engine->RegisterObjectMethod("IntVector2", "IntVector2 &opMulAssign(int)", asMETHODPR(IntVector2, operator *=, (int), IntVector2&), asCALL_THISCALL);
  132. engine->RegisterObjectMethod("IntVector2", "IntVector2 &opDivAssign(int)", asMETHODPR(IntVector2, operator /=, (int), IntVector2&), asCALL_THISCALL);
  133. engine->RegisterObjectMethod("IntVector2", "bool opEquals(const IntVector2&in) const", asMETHOD(IntVector2, operator ==), asCALL_THISCALL);
  134. engine->RegisterObjectMethod("IntVector2", "IntVector2 opNeg() const", asMETHODPR(IntVector2, operator -, () const, IntVector2), asCALL_THISCALL);
  135. engine->RegisterObjectMethod("IntVector2", "IntVector2 opAdd(const IntVector2&in) const", asMETHOD(IntVector2, operator +), asCALL_THISCALL);
  136. engine->RegisterObjectMethod("IntVector2", "IntVector2 opSub(const IntVector2&in) const", asMETHODPR(IntVector2, operator -, (const IntVector2&) const, IntVector2), asCALL_THISCALL);
  137. engine->RegisterObjectMethod("IntVector2", "IntVector2 opMul(int) const", asMETHODPR(IntVector2, operator *, (int) const, IntVector2), asCALL_THISCALL);
  138. engine->RegisterObjectMethod("IntVector2", "IntVector2 opDiv(int) const", asMETHODPR(IntVector2, operator /, (int) const, IntVector2), asCALL_THISCALL);
  139. engine->RegisterObjectMethod("IntVector2", "String ToString() const", asFUNCTIONPR(ToString, (const IntVector2&), String), asCALL_CDECL_OBJLAST);
  140. engine->RegisterObjectProperty("IntVector2", "int x", offsetof(IntVector2, x_));
  141. engine->RegisterObjectProperty("IntVector2", "int y", offsetof(IntVector2, y_));
  142. }
  143. static void ConstructVector2(Vector2* ptr)
  144. {
  145. // Init to zero because performance is not critical
  146. new(ptr) Vector2(Vector2::ZERO);
  147. }
  148. static void ConstructVector2Copy(const Vector2& vector, Vector2* ptr)
  149. {
  150. new(ptr) Vector2(vector);
  151. }
  152. static void ConstructVector2Init(float x, float y, Vector2* ptr)
  153. {
  154. new(ptr) Vector2(x, y);
  155. }
  156. static void RegisterVector2(asIScriptEngine* engine)
  157. {
  158. engine->RegisterObjectType("Vector2", sizeof(Vector2), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  159. engine->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructVector2), asCALL_CDECL_OBJLAST);
  160. engine->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT, "void f(const Vector2&in)", asFUNCTION(ConstructVector2Copy), asCALL_CDECL_OBJLAST);
  161. engine->RegisterObjectBehaviour("Vector2", asBEHAVE_CONSTRUCT, "void f(float, float)", asFUNCTION(ConstructVector2Init), asCALL_CDECL_OBJLAST);
  162. engine->RegisterObjectMethod("Vector2", "Vector2 &opAssign(const Vector2&in)", asMETHOD(Vector2, operator =), asCALL_THISCALL);
  163. engine->RegisterObjectMethod("Vector2", "Vector2 &opAddAssign(const Vector2&in)", asMETHOD(Vector2, operator +=), asCALL_THISCALL);
  164. engine->RegisterObjectMethod("Vector2", "Vector2 &opSubAssign(const Vector2&in)", asMETHOD(Vector2, operator -=), asCALL_THISCALL);
  165. engine->RegisterObjectMethod("Vector2", "Vector2 &opMulAssign(const Vector2&in)", asMETHODPR(Vector2, operator *=, (const Vector2&), Vector2&), asCALL_THISCALL);
  166. engine->RegisterObjectMethod("Vector2", "Vector2 &opMulAssign(float)", asMETHODPR(Vector2, operator *=, (float), Vector2&), asCALL_THISCALL);
  167. engine->RegisterObjectMethod("Vector2", "Vector2 &opDivAssign(const Vector2&in)", asMETHODPR(Vector2, operator /=, (const Vector2&), Vector2&), asCALL_THISCALL);
  168. engine->RegisterObjectMethod("Vector2", "Vector2 &opDivAssign(float)", asMETHODPR(Vector2, operator /=, (float), Vector2&), asCALL_THISCALL);
  169. engine->RegisterObjectMethod("Vector2", "bool opEquals(const Vector2&in) const", asMETHOD(Vector2, operator ==), asCALL_THISCALL);
  170. engine->RegisterObjectMethod("Vector2", "Vector2 opNeg() const", asMETHODPR(Vector2, operator -, () const, Vector2), asCALL_THISCALL);
  171. engine->RegisterObjectMethod("Vector2", "Vector2 opAdd(const Vector2&in) const", asMETHOD(Vector2, operator +), asCALL_THISCALL);
  172. engine->RegisterObjectMethod("Vector2", "Vector2 opSub(const Vector2&in) const", asMETHODPR(Vector2, operator -, (const Vector2&) const, Vector2), asCALL_THISCALL);
  173. engine->RegisterObjectMethod("Vector2", "Vector2 opMul(const Vector2&in) const", asMETHODPR(Vector2, operator *, (const Vector2&) const, Vector2), asCALL_THISCALL);
  174. engine->RegisterObjectMethod("Vector2", "Vector2 opMul(float) const", asMETHODPR(Vector2, operator *, (float) const, Vector2), asCALL_THISCALL);
  175. engine->RegisterObjectMethod("Vector2", "Vector2 opDiv(const Vector2&in) const", asMETHODPR(Vector2, operator /, (const Vector2&) const, Vector2), asCALL_THISCALL);
  176. engine->RegisterObjectMethod("Vector2", "Vector2 opDiv(float) const", asMETHODPR(Vector2, operator /, (float) const, Vector2), asCALL_THISCALL);
  177. engine->RegisterObjectMethod("Vector2", "float Normalize()", asMETHOD(Vector2, Normalize), asCALL_THISCALL);
  178. engine->RegisterObjectMethod("Vector2", "float DotProduct(const Vector2&in) const", asMETHOD(Vector2, DotProduct), asCALL_THISCALL);
  179. engine->RegisterObjectMethod("Vector2", "float AbsDotProduct(const Vector2&in) const", asMETHOD(Vector2, AbsDotProduct), asCALL_THISCALL);
  180. engine->RegisterObjectMethod("Vector2", "Vector2 Lerp(const Vector2&in, float) const", asMETHOD(Vector2, Lerp), asCALL_THISCALL);
  181. engine->RegisterObjectMethod("Vector2", "Vector2 GetNormalized() const", asMETHOD(Vector2, GetNormalized), asCALL_THISCALL);
  182. engine->RegisterObjectMethod("Vector2", "String ToString() const", asFUNCTIONPR(ToString, (const Vector2&), String), asCALL_CDECL_OBJLAST);
  183. engine->RegisterObjectMethod("Vector2", "float get_length() const", asMETHOD(Vector2, GetLength), asCALL_THISCALL);
  184. engine->RegisterObjectMethod("Vector2", "float get_lengthSquared() const", asMETHOD(Vector2, GetLengthSquared), asCALL_THISCALL);
  185. engine->RegisterObjectProperty("Vector2", "float x", offsetof(Vector2, x_));
  186. engine->RegisterObjectProperty("Vector2", "float y", offsetof(Vector2, y_));
  187. }
  188. static void ConstructVector3(Vector3* ptr)
  189. {
  190. // Init to zero because performance is not critical
  191. new(ptr) Vector3(Vector3::ZERO);
  192. }
  193. static void ConstructVector3Copy(const Vector3& vector, Vector3* ptr)
  194. {
  195. new(ptr) Vector3(vector);
  196. }
  197. static void ConstructVector3Init(float x, float y, float z, Vector3* ptr)
  198. {
  199. new(ptr) Vector3(x, y, z);
  200. }
  201. static void RegisterVector3(asIScriptEngine* engine)
  202. {
  203. engine->RegisterObjectType("Vector3", sizeof(Vector3), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  204. engine->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructVector3), asCALL_CDECL_OBJLAST);
  205. engine->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT, "void f(const Vector3&in)", asFUNCTION(ConstructVector3Copy), asCALL_CDECL_OBJLAST);
  206. engine->RegisterObjectBehaviour("Vector3", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructVector3Init), asCALL_CDECL_OBJLAST);
  207. engine->RegisterObjectMethod("Vector3", "Vector3 &opAssign(const Vector3&in)", asMETHOD(Vector3, operator =), asCALL_THISCALL);
  208. engine->RegisterObjectMethod("Vector3", "Vector3 &opAddAssign(const Vector3&in)", asMETHOD(Vector3, operator +=), asCALL_THISCALL);
  209. engine->RegisterObjectMethod("Vector3", "Vector3 &opSubAssign(const Vector3&in)", asMETHOD(Vector3, operator -=), asCALL_THISCALL);
  210. engine->RegisterObjectMethod("Vector3", "Vector3 &opMulAssign(const Vector3&in)", asMETHODPR(Vector3, operator *=, (const Vector3&), Vector3&), asCALL_THISCALL);
  211. engine->RegisterObjectMethod("Vector3", "Vector3 &opMulAssign(float)", asMETHODPR(Vector3, operator *=, (float), Vector3&), asCALL_THISCALL);
  212. engine->RegisterObjectMethod("Vector3", "Vector3 &opDivAssign(const Vector3&in)", asMETHODPR(Vector3, operator /=, (const Vector3&), Vector3&), asCALL_THISCALL);
  213. engine->RegisterObjectMethod("Vector3", "Vector3 &opDivAssign(float)", asMETHODPR(Vector3, operator /=, (float), Vector3&), asCALL_THISCALL);
  214. engine->RegisterObjectMethod("Vector3", "bool opEquals(const Vector3&in) const", asMETHOD(Vector3, operator ==), asCALL_THISCALL);
  215. engine->RegisterObjectMethod("Vector3", "Vector3 opNeg() const", asMETHODPR(Vector3, operator -, () const, Vector3), asCALL_THISCALL);
  216. engine->RegisterObjectMethod("Vector3", "Vector3 opAdd(const Vector3&in) const", asMETHOD(Vector3, operator +), asCALL_THISCALL);
  217. engine->RegisterObjectMethod("Vector3", "Vector3 opSub(const Vector3&in) const", asMETHODPR(Vector3, operator -, (const Vector3&) const, Vector3), asCALL_THISCALL);
  218. engine->RegisterObjectMethod("Vector3", "Vector3 opMul(const Vector3&in) const", asMETHODPR(Vector3, operator *, (const Vector3&) const, Vector3), asCALL_THISCALL);
  219. engine->RegisterObjectMethod("Vector3", "Vector3 opMul(float) const", asMETHODPR(Vector3, operator *, (float) const, Vector3), asCALL_THISCALL);
  220. engine->RegisterObjectMethod("Vector3", "Vector3 opDiv(const Vector3&in) const", asMETHODPR(Vector3, operator /, (const Vector3&) const, Vector3), asCALL_THISCALL);
  221. engine->RegisterObjectMethod("Vector3", "Vector3 opDiv(float) const", asMETHODPR(Vector3, operator /, (float) const, Vector3), asCALL_THISCALL);
  222. engine->RegisterObjectMethod("Vector3", "float Normalize()", asMETHOD(Vector3, Normalize), asCALL_THISCALL);
  223. engine->RegisterObjectMethod("Vector3", "float DotProduct(const Vector3&in) const", asMETHOD(Vector3, DotProduct), asCALL_THISCALL);
  224. engine->RegisterObjectMethod("Vector3", "float AbsDotProduct(const Vector3&in) const", asMETHOD(Vector3, AbsDotProduct), asCALL_THISCALL);
  225. engine->RegisterObjectMethod("Vector3", "Vector3 CrossProduct(const Vector3&in) const", asMETHOD(Vector3, CrossProduct), asCALL_THISCALL);
  226. engine->RegisterObjectMethod("Vector3", "Vector3 Lerp(const Vector3&in, float) const", asMETHOD(Vector3, Lerp), asCALL_THISCALL);
  227. engine->RegisterObjectMethod("Vector3", "Vector3 GetNormalized() const", asMETHOD(Vector3, GetNormalized), asCALL_THISCALL);
  228. engine->RegisterObjectMethod("Vector3", "String ToString() const", asFUNCTIONPR(ToString, (const Vector3&), String), asCALL_CDECL_OBJLAST);
  229. engine->RegisterObjectMethod("Vector3", "float get_length() const", asMETHOD(Vector3, GetLength), asCALL_THISCALL);
  230. engine->RegisterObjectMethod("Vector3", "float get_lengthSquared() const", asMETHOD(Vector3, GetLengthSquared), asCALL_THISCALL);
  231. engine->RegisterObjectProperty("Vector3", "float x", offsetof(Vector3, x_));
  232. engine->RegisterObjectProperty("Vector3", "float y", offsetof(Vector3, y_));
  233. engine->RegisterObjectProperty("Vector3", "float z", offsetof(Vector3, z_));
  234. }
  235. static void ConstructVector4(Vector4* ptr)
  236. {
  237. // Init to zero because performance is not critical
  238. new(ptr) Vector4(Vector4::ZERO);
  239. }
  240. static void ConstructVector4Copy(const Vector4& vector, Vector4* ptr)
  241. {
  242. new(ptr) Vector4(vector);
  243. }
  244. static void ConstructVector4Init(float x, float y, float z, float w, Vector4* ptr)
  245. {
  246. new(ptr) Vector4(x, y, z, w);
  247. }
  248. static void RegisterVector4(asIScriptEngine* engine)
  249. {
  250. engine->RegisterObjectType("Vector4", sizeof(Vector4), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  251. engine->RegisterObjectBehaviour("Vector4", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructVector4), asCALL_CDECL_OBJLAST);
  252. engine->RegisterObjectBehaviour("Vector4", asBEHAVE_CONSTRUCT, "void f(const Vector4&in)", asFUNCTION(ConstructVector4Copy), asCALL_CDECL_OBJLAST);
  253. engine->RegisterObjectBehaviour("Vector4", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructVector4Init), asCALL_CDECL_OBJLAST);
  254. engine->RegisterObjectMethod("Vector4", "Vector4 &opAssign(const Vector4&in)", asMETHOD(Vector4, operator =), asCALL_THISCALL);
  255. engine->RegisterObjectMethod("Vector4", "Vector4 &opAddAssign(const Vector4&in)", asMETHOD(Vector4, operator +=), asCALL_THISCALL);
  256. engine->RegisterObjectMethod("Vector4", "Vector4 &opSubAssign(const Vector4&in)", asMETHOD(Vector4, operator -=), asCALL_THISCALL);
  257. engine->RegisterObjectMethod("Vector4", "Vector4 &opMulAssign(const Vector4&in)", asMETHODPR(Vector4, operator *=, (const Vector4&), Vector4&), asCALL_THISCALL);
  258. engine->RegisterObjectMethod("Vector4", "Vector4 &opMulAssign(float)", asMETHODPR(Vector4, operator *=, (float), Vector4&), asCALL_THISCALL);
  259. engine->RegisterObjectMethod("Vector4", "Vector4 &opDivAssign(const Vector4&in)", asMETHODPR(Vector4, operator /=, (const Vector4&), Vector4&), asCALL_THISCALL);
  260. engine->RegisterObjectMethod("Vector4", "Vector4 &opDivAssign(float)", asMETHODPR(Vector4, operator /=, (float), Vector4&), asCALL_THISCALL);
  261. engine->RegisterObjectMethod("Vector4", "bool &opEquals(const Vector4&in) const", asMETHOD(Vector4, operator ==), asCALL_THISCALL);
  262. engine->RegisterObjectMethod("Vector4", "Vector4 opNeg() const", asMETHODPR(Vector4, operator -, () const, Vector4), asCALL_THISCALL);
  263. engine->RegisterObjectMethod("Vector4", "Vector4 opAdd(const Vector4&in) const", asMETHOD(Vector4, operator +), asCALL_THISCALL);
  264. engine->RegisterObjectMethod("Vector4", "Vector4 opSub(const Vector4&in) const", asMETHODPR(Vector4, operator -, (const Vector4&) const, Vector4), asCALL_THISCALL);
  265. engine->RegisterObjectMethod("Vector4", "Vector4 opMul(const Vector4&in) const", asMETHODPR(Vector4, operator *, (const Vector4&) const, Vector4), asCALL_THISCALL);
  266. engine->RegisterObjectMethod("Vector4", "Vector4 opMul(float) const", asMETHODPR(Vector4, operator *, (float) const, Vector4), asCALL_THISCALL);
  267. engine->RegisterObjectMethod("Vector4", "Vector4 opDiv(const Vector4&in) const", asMETHODPR(Vector4, operator /, (const Vector4&) const, Vector4), asCALL_THISCALL);
  268. engine->RegisterObjectMethod("Vector4", "Vector4 opDiv(float) const", asMETHODPR(Vector4, operator /, (float) const, Vector4), asCALL_THISCALL);
  269. engine->RegisterObjectMethod("Vector4", "float DotProduct(const Vector4&in) const", asMETHOD(Vector4, DotProduct), asCALL_THISCALL);
  270. engine->RegisterObjectMethod("Vector4", "float AbsDotProduct(const Vector4&in) const", asMETHOD(Vector4, AbsDotProduct), asCALL_THISCALL);
  271. engine->RegisterObjectMethod("Vector4", "Vector4 Lerp(const Vector4&in, float) const", asMETHOD(Vector4, Lerp), asCALL_THISCALL);
  272. engine->RegisterObjectMethod("Vector4", "String ToString() const", asFUNCTIONPR(ToString, (const Vector4&), String), asCALL_CDECL_OBJLAST);
  273. engine->RegisterObjectProperty("Vector4", "float x", offsetof(Vector4, x_));
  274. engine->RegisterObjectProperty("Vector4", "float y", offsetof(Vector4, y_));
  275. engine->RegisterObjectProperty("Vector4", "float z", offsetof(Vector4, z_));
  276. engine->RegisterObjectProperty("Vector4", "float w", offsetof(Vector4, w_));
  277. }
  278. static void ConstructQuaternion(Quaternion* ptr)
  279. {
  280. new(ptr) Quaternion();
  281. }
  282. static void ConstructQuaternionCopy(const Quaternion& quat, Quaternion* ptr)
  283. {
  284. new(ptr) Quaternion(quat);
  285. }
  286. static void ConstructQuaternionInit(float w, float x, float y, float z, Quaternion* ptr)
  287. {
  288. new(ptr) Quaternion(w, x, y, z);
  289. }
  290. static void ConstructQuaternionAngleAxis(float angle, const Vector3& axis, Quaternion* ptr)
  291. {
  292. new(ptr) Quaternion(angle, axis);
  293. }
  294. static void ConstructQuaternionEuler(float angleX, float angleY, float angleZ, Quaternion* ptr)
  295. {
  296. new(ptr) Quaternion(angleX, angleY, angleZ);
  297. }
  298. static void ConstructQuaternionRotation(const Vector3& start, const Vector3& end, Quaternion* ptr)
  299. {
  300. new(ptr) Quaternion(start, end);
  301. }
  302. static void RegisterQuaternion(asIScriptEngine* engine)
  303. {
  304. engine->RegisterObjectType("Quaternion", sizeof(Quaternion), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  305. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructQuaternion), asCALL_CDECL_OBJLAST);
  306. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f(const Quaternion&in)", asFUNCTION(ConstructQuaternionCopy), asCALL_CDECL_OBJLAST);
  307. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f(float, float, float, float)", asFUNCTION(ConstructQuaternionInit), asCALL_CDECL_OBJLAST);
  308. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f(float, const Vector3&in)", asFUNCTION(ConstructQuaternionAngleAxis), asCALL_CDECL_OBJLAST);
  309. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructQuaternionEuler), asCALL_CDECL_OBJLAST);
  310. engine->RegisterObjectBehaviour("Quaternion", asBEHAVE_CONSTRUCT, "void f(const Vector3&in, const Vector3&in)", asFUNCTION(ConstructQuaternionRotation), asCALL_CDECL_OBJLAST);
  311. engine->RegisterObjectMethod("Quaternion", "Quaternion &opAssign(const Quaternion&in)", asMETHOD(Quaternion, operator =), asCALL_THISCALL);
  312. engine->RegisterObjectMethod("Quaternion", "Quaternion &opAddAssign(const Quaternion&in)", asMETHOD(Quaternion, operator +=), asCALL_THISCALL);
  313. engine->RegisterObjectMethod("Quaternion", "bool opEquals(const Quaternion&in) const", asMETHOD(Quaternion, operator ==), asCALL_THISCALL);
  314. engine->RegisterObjectMethod("Quaternion", "Quaternion opMul(float) const", asMETHODPR(Quaternion, operator *, (float) const, Quaternion), asCALL_THISCALL);
  315. engine->RegisterObjectMethod("Quaternion", "Vector3 opMul(const Vector3&in) const", asMETHODPR(Quaternion, operator *, (const Vector3&) const, Vector3), asCALL_THISCALL);
  316. engine->RegisterObjectMethod("Quaternion", "Quaternion opNeg() const", asMETHODPR(Quaternion, operator -, () const, Quaternion), asCALL_THISCALL);
  317. engine->RegisterObjectMethod("Quaternion", "Quaternion opAdd(const Quaternion&in) const", asMETHOD(Quaternion, operator +), asCALL_THISCALL);
  318. engine->RegisterObjectMethod("Quaternion", "Quaternion opSub(const Quaternion&in) const", asMETHODPR(Quaternion, operator +, (const Quaternion&) const, Quaternion), asCALL_THISCALL);
  319. engine->RegisterObjectMethod("Quaternion", "Quaternion opMul(const Quaternion&in) const", asMETHODPR(Quaternion, operator *, (const Quaternion&) const, Quaternion), asCALL_THISCALL);
  320. engine->RegisterObjectMethod("Quaternion", "void Normalize()", asMETHOD(Quaternion, Normalize), asCALL_THISCALL);
  321. engine->RegisterObjectMethod("Quaternion", "Quaternion GetNormalized() const", asMETHOD(Quaternion, GetNormalized), asCALL_THISCALL);
  322. engine->RegisterObjectMethod("Quaternion", "Quaternion GetInverse() const", asMETHOD(Quaternion, GetInverse), asCALL_THISCALL);
  323. engine->RegisterObjectMethod("Quaternion", "float DotProduct(const Quaternion&in) const", asMETHOD(Quaternion, DotProduct), asCALL_THISCALL);
  324. engine->RegisterObjectMethod("Quaternion", "Quaternion Nlerp(const Quaternion&in, float) const", asMETHOD(Quaternion, Nlerp), asCALL_THISCALL);
  325. engine->RegisterObjectMethod("Quaternion", "Quaternion Slerp(const Quaternion&in, float) const", asMETHOD(Quaternion, Slerp), asCALL_THISCALL);
  326. engine->RegisterObjectMethod("Quaternion", "String ToString() const", asFUNCTIONPR(ToString, (const Quaternion&), String), asCALL_CDECL_OBJLAST);
  327. engine->RegisterObjectMethod("Quaternion", "Vector3 get_eulerAngles() const", asMETHOD(Quaternion, GetEulerAngles), asCALL_THISCALL);
  328. engine->RegisterObjectMethod("Quaternion", "float get_yaw() const", asMETHOD(Quaternion, GetYaw), asCALL_THISCALL);
  329. engine->RegisterObjectMethod("Quaternion", "float get_pitch() const", asMETHOD(Quaternion, GetPitch), asCALL_THISCALL);
  330. engine->RegisterObjectMethod("Quaternion", "float get_roll() const", asMETHOD(Quaternion, GetRoll), asCALL_THISCALL);
  331. engine->RegisterObjectProperty("Quaternion", "float w", offsetof(Quaternion, w_));
  332. engine->RegisterObjectProperty("Quaternion", "float x", offsetof(Quaternion, x_));
  333. engine->RegisterObjectProperty("Quaternion", "float y", offsetof(Quaternion, y_));
  334. engine->RegisterObjectProperty("Quaternion", "float z", offsetof(Quaternion, z_));
  335. }
  336. static void ConstructRay(Ray* ptr)
  337. {
  338. // Initialize to zero because performance is not critical
  339. new(ptr) Ray(Vector3::ZERO, Vector3::ZERO);
  340. }
  341. static void ConstructRayCopy(const Ray& ray, Ray* ptr)
  342. {
  343. new(ptr) Ray(ray);
  344. }
  345. static void ConstructRayInit(const Vector3& origin, const Vector3& direction, Ray* ptr)
  346. {
  347. // Normalize direction because performance is not critical
  348. new(ptr) Ray(origin, direction.GetNormalized());
  349. }
  350. static void RegisterRay(asIScriptEngine* engine)
  351. {
  352. engine->RegisterObjectType("Ray", sizeof(Ray), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  353. engine->RegisterObjectBehaviour("Ray", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructRay), asCALL_CDECL_OBJLAST);
  354. engine->RegisterObjectBehaviour("Ray", asBEHAVE_CONSTRUCT, "void f(const Ray&in)", asFUNCTION(ConstructRayCopy), asCALL_CDECL_OBJLAST);
  355. engine->RegisterObjectBehaviour("Ray", asBEHAVE_CONSTRUCT, "void f(const Vector3&in, const Vector3&in)", asFUNCTION(ConstructRayInit), asCALL_CDECL_OBJLAST);
  356. engine->RegisterObjectMethod("Ray", "Ray &opAssign(const Ray&in)", asMETHOD(Ray, operator =), asCALL_THISCALL);
  357. engine->RegisterObjectMethod("Ray", "bool opEquals(const Ray&in) const", asMETHOD(Ray, operator ==), asCALL_THISCALL);
  358. engine->RegisterObjectMethod("Ray", "void Define(const Vector3&in, const Vector3&in)", asMETHOD(Ray, Define), asCALL_THISCALL);
  359. engine->RegisterObjectMethod("Ray", "float GetDistance(const Vector3&in, const Vector3&in, const Vector3&in) const", asMETHODPR(Ray, GetDistance, (const Vector3&, const Vector3&, const Vector3&) const, float), asCALL_THISCALL);
  360. engine->RegisterObjectProperty("Ray", "Vector3 origin", offsetof(Ray, origin_));
  361. engine->RegisterObjectProperty("Ray", "Vector3 direction", offsetof(Ray, direction_));
  362. }
  363. static void ConstructRect(Rect* ptr)
  364. {
  365. // Init to zero because performance is not critical
  366. new(ptr) Rect(Rect::ZERO);
  367. }
  368. static void ConstructRectCopy(const Rect& rect, Rect* ptr)
  369. {
  370. new(ptr) Rect(rect);
  371. }
  372. static void ConstructRectInit(float left, float top, float right, float bottom, Rect* ptr)
  373. {
  374. new(ptr) Rect(left, top, right, bottom);
  375. }
  376. static void ConstructRectInitVec(const Vector2& min, const Vector2& max, Rect* ptr)
  377. {
  378. new(ptr) Rect(min, max);
  379. }
  380. static void RegisterRect(asIScriptEngine* engine)
  381. {
  382. engine->RegisterObjectType("Rect", sizeof(Rect), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  383. engine->RegisterObjectBehaviour("Rect", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructRect), asCALL_CDECL_OBJLAST);
  384. engine->RegisterObjectBehaviour("Rect", asBEHAVE_CONSTRUCT, "void f(const Rect&in)", asFUNCTION(ConstructRectCopy), asCALL_CDECL_OBJLAST);
  385. engine->RegisterObjectBehaviour("Rect", asBEHAVE_CONSTRUCT, "void f(float, float, float, float)", asFUNCTION(ConstructRectInit), asCALL_CDECL_OBJLAST);
  386. engine->RegisterObjectBehaviour("Rect", asBEHAVE_CONSTRUCT, "void f(const Vector2&in, const Vector2&in)", asFUNCTION(ConstructRectInitVec), asCALL_CDECL_OBJLAST);
  387. engine->RegisterObjectMethod("Rect", "Rect &opAssign(const Rect&in)", asMETHOD(Rect, operator =), asCALL_THISCALL);
  388. engine->RegisterObjectMethod("Rect", "bool opEquals(const Rect&in) const", asMETHOD(Rect, operator ==), asCALL_THISCALL);
  389. engine->RegisterObjectMethod("Rect", "void Define(const Vector2&in, const Vector2&in)", asMETHODPR(Rect, Define, (const Vector2&, const Vector2&), void), asCALL_THISCALL);
  390. engine->RegisterObjectMethod("Rect", "void Define(const Vector2&in)", asMETHODPR(Rect, Define, (const Vector2&), void), asCALL_THISCALL);
  391. engine->RegisterObjectMethod("Rect", "void Merge(const Vector2&in)", asMETHODPR(Rect, Merge, (const Vector2&), void), asCALL_THISCALL);
  392. engine->RegisterObjectMethod("Rect", "void Merge(const Rect&in)", asMETHODPR(Rect, Merge, (const Rect&), void), asCALL_THISCALL);
  393. engine->RegisterObjectProperty("Rect", "Vector2 min", offsetof(Rect, min_));
  394. engine->RegisterObjectProperty("Rect", "Vector2 max", offsetof(Rect, max_));
  395. engine->RegisterObjectProperty("Rect", "float left", offsetof(Rect, min_.x_));
  396. engine->RegisterObjectProperty("Rect", "float top", offsetof(Rect, min_.y_));
  397. engine->RegisterObjectProperty("Rect", "float right", offsetof(Rect, max_.x_));
  398. engine->RegisterObjectProperty("Rect", "float bottom", offsetof(Rect, max_.y_));
  399. engine->RegisterObjectProperty("Rect", "bool defined", offsetof(Rect, defined_));
  400. }
  401. static void ConstructBoundingBox(BoundingBox* ptr)
  402. {
  403. new(ptr) BoundingBox();
  404. }
  405. static void ConstructBoundingBoxCopy(const BoundingBox& box, BoundingBox* ptr)
  406. {
  407. new(ptr) BoundingBox(box);
  408. }
  409. static void ConstructBoundingBoxInit(const Vector3& min, const Vector3& max, BoundingBox* ptr)
  410. {
  411. new(ptr) BoundingBox(min, max);
  412. }
  413. static void ConstructBoundingBoxFloat(float min, float max, BoundingBox* ptr)
  414. {
  415. new(ptr) BoundingBox(min, max);
  416. }
  417. static void ConstructSphere(Sphere* ptr)
  418. {
  419. new(ptr) Sphere();
  420. }
  421. static void ConstructSphereCopy(const Sphere& sphere, Sphere* ptr)
  422. {
  423. new(ptr) Sphere(sphere);
  424. }
  425. static void ConstructSphereInit(const Vector3& center, float radius, Sphere* ptr)
  426. {
  427. new(ptr) Sphere(center, radius);
  428. }
  429. static void ConstructFrustum(Frustum* ptr)
  430. {
  431. new(ptr) Frustum();
  432. }
  433. static void ConstructFrustumCopy(const Frustum& frustum, Frustum* ptr)
  434. {
  435. new(ptr) Frustum(frustum);
  436. }
  437. static void DestructFrustum(Frustum* ptr)
  438. {
  439. ptr->~Frustum();
  440. }
  441. static Vector3 FrustumGetVertex(unsigned index, Frustum* ptr)
  442. {
  443. if (index >= NUM_FRUSTUM_VERTICES)
  444. return Vector3::ZERO;
  445. return ptr->vertices_[index];
  446. }
  447. static void RegisterVolumes(asIScriptEngine* engine)
  448. {
  449. engine->RegisterEnum("Intersection");
  450. engine->RegisterEnumValue("Intersection", "OUTSIDE", OUTSIDE);
  451. engine->RegisterEnumValue("Intersection", "INTERSECTS", INTERSECTS);
  452. engine->RegisterEnumValue("Intersection", "INSIDE", INSIDE);
  453. engine->RegisterObjectType("BoundingBox", sizeof(BoundingBox), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  454. engine->RegisterObjectType("Sphere", sizeof(Sphere), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  455. engine->RegisterObjectType("Frustum", sizeof(Frustum), asOBJ_VALUE | asOBJ_APP_CLASS_CDA);
  456. engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructBoundingBox), asCALL_CDECL_OBJLAST);
  457. engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f(const BoundingBox&in)", asFUNCTION(ConstructBoundingBoxCopy), asCALL_CDECL_OBJLAST);
  458. engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f(const Vector3&in, const Vector3&in)", asFUNCTION(ConstructBoundingBoxInit), asCALL_CDECL_OBJLAST);
  459. engine->RegisterObjectBehaviour("BoundingBox", asBEHAVE_CONSTRUCT, "void f(float, float)", asFUNCTION(ConstructBoundingBoxFloat), asCALL_CDECL_OBJLAST);
  460. engine->RegisterObjectMethod("BoundingBox", "BoundingBox &opAssign(const BoundingBox&in)", asMETHODPR(BoundingBox, operator =, (const BoundingBox&), BoundingBox&), asCALL_THISCALL);
  461. engine->RegisterObjectMethod("BoundingBox", "bool opEquals(const BoundingBox&in) const", asMETHOD(BoundingBox, operator ==), asCALL_THISCALL);
  462. engine->RegisterObjectMethod("BoundingBox", "void Define(const Vector3&in, const Vector3&in)", asMETHODPR(BoundingBox, Define, (const Vector3&, const Vector3&), void), asCALL_THISCALL);
  463. engine->RegisterObjectMethod("BoundingBox", "void Define(float, float)", asMETHODPR(BoundingBox, Define, (float, float), void), asCALL_THISCALL);
  464. engine->RegisterObjectMethod("BoundingBox", "void Define(const Frustum&in)", asMETHODPR(BoundingBox, Define, (const Frustum&), void), asCALL_THISCALL);
  465. engine->RegisterObjectMethod("BoundingBox", "void Define(const Sphere&in)", asMETHODPR(BoundingBox, Define, (const Sphere&), void), asCALL_THISCALL);
  466. engine->RegisterObjectMethod("BoundingBox", "void Merge(const Vector3&in)", asMETHODPR(BoundingBox, Merge, (const Vector3&), void), asCALL_THISCALL);
  467. engine->RegisterObjectMethod("BoundingBox", "void Merge(const BoundingBox&in)", asMETHODPR(BoundingBox, Merge, (const BoundingBox&), void), asCALL_THISCALL);
  468. engine->RegisterObjectMethod("BoundingBox", "void Merge(const Frustum&in)", asMETHODPR(BoundingBox, Merge, (const Frustum&), void), asCALL_THISCALL);
  469. engine->RegisterObjectMethod("BoundingBox", "void Merge(const Sphere&in)", asMETHODPR(BoundingBox, Merge, (const Sphere&), void), asCALL_THISCALL);
  470. engine->RegisterObjectMethod("BoundingBox", "void Intersect(const BoundingBox&in)", asMETHODPR(BoundingBox, Intersect, (const BoundingBox&), void), asCALL_THISCALL);
  471. engine->RegisterObjectMethod("BoundingBox", "Intersection IsInside(const Vector3&in) const", asMETHODPR(BoundingBox, IsInside, (const Vector3&) const, Intersection), asCALL_THISCALL);
  472. engine->RegisterObjectMethod("BoundingBox", "Intersection IsInside(const Sphere&in) const", asMETHODPR(BoundingBox, IsInside, (const Sphere&) const, Intersection), asCALL_THISCALL);
  473. engine->RegisterObjectMethod("BoundingBox", "Intersection IsInside(const BoundingBox&in) const", asMETHODPR(BoundingBox, IsInside, (const BoundingBox&) const, Intersection), asCALL_THISCALL);
  474. engine->RegisterObjectMethod("BoundingBox", "float GetDistance(const Ray&in) const", asMETHOD(BoundingBox, GetDistance), asCALL_THISCALL);
  475. engine->RegisterObjectMethod("BoundingBox", "Vector3 get_center() const", asMETHOD(BoundingBox, GetCenter), asCALL_THISCALL);
  476. engine->RegisterObjectMethod("BoundingBox", "Vector3 get_size() const", asMETHOD(BoundingBox, GetSize), asCALL_THISCALL);
  477. engine->RegisterObjectMethod("BoundingBox", "Vector3 get_halfSize() const", asMETHOD(BoundingBox, GetHalfSize), asCALL_THISCALL);
  478. engine->RegisterObjectProperty("BoundingBox", "Vector3 min", offsetof(BoundingBox, min_));
  479. engine->RegisterObjectProperty("BoundingBox", "Vector3 max", offsetof(BoundingBox, max_));
  480. engine->RegisterObjectProperty("BoundingBox", "bool defined", offsetof(BoundingBox, defined_));
  481. engine->RegisterObjectBehaviour("Sphere", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructSphere), asCALL_CDECL_OBJLAST);
  482. engine->RegisterObjectBehaviour("Sphere", asBEHAVE_CONSTRUCT, "void f(const Sphere&in)", asFUNCTION(ConstructSphereCopy), asCALL_CDECL_OBJLAST);
  483. engine->RegisterObjectBehaviour("Sphere", asBEHAVE_CONSTRUCT, "void f(const Vector3&in, float)", asFUNCTION(ConstructSphereInit), asCALL_CDECL_OBJLAST);
  484. engine->RegisterObjectMethod("Sphere", "Sphere &opAssign(const Sphere&in)", asMETHODPR(Sphere, operator =, (const Sphere&), Sphere&), asCALL_THISCALL);
  485. engine->RegisterObjectMethod("Sphere", "bool &opEquals(const Sphere&in) const", asMETHOD(Sphere, operator ==), asCALL_THISCALL);
  486. engine->RegisterObjectMethod("Sphere", "void Define(const Vector3&in, float)", asMETHODPR(Sphere, Define, (const Vector3&, float), void), asCALL_THISCALL);
  487. engine->RegisterObjectMethod("Sphere", "void Define(const BoundingBox&in)", asMETHODPR(Sphere, Define, (const BoundingBox&), void), asCALL_THISCALL);
  488. engine->RegisterObjectMethod("Sphere", "void Define(const Frustum&in)", asMETHODPR(Sphere, Define, (const Frustum&), void), asCALL_THISCALL);
  489. engine->RegisterObjectMethod("Sphere", "void Merge(const Vector3&in)", asMETHODPR(Sphere, Merge, (const Vector3&), void), asCALL_THISCALL);
  490. engine->RegisterObjectMethod("Sphere", "void Merge(const BoundingBox&in)", asMETHODPR(Sphere, Merge, (const BoundingBox&), void), asCALL_THISCALL);
  491. engine->RegisterObjectMethod("Sphere", "void Merge(const Frustum&in)", asMETHODPR(Sphere, Merge, (const Frustum&), void), asCALL_THISCALL);
  492. engine->RegisterObjectMethod("Sphere", "void Merge(const Sphere&in)", asMETHODPR(Sphere, Merge, (const Sphere&), void), asCALL_THISCALL);
  493. engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Vector3&in) const", asMETHODPR(Sphere, IsInside, (const Vector3&) const, Intersection), asCALL_THISCALL);
  494. engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const Sphere&in) const", asMETHODPR(Sphere, IsInside, (const Sphere&) const, Intersection), asCALL_THISCALL);
  495. engine->RegisterObjectMethod("Sphere", "Intersection IsInside(const BoundingBox&in) const", asMETHODPR(Sphere, IsInside, (const BoundingBox&) const, Intersection), asCALL_THISCALL);
  496. engine->RegisterObjectMethod("Sphere", "float GetDistance(const Ray&in) const", asMETHOD(Sphere, GetDistance), asCALL_THISCALL);
  497. engine->RegisterObjectProperty("Sphere", "Vector3 center", offsetof(Sphere, center_));
  498. engine->RegisterObjectProperty("Sphere", "float radius", offsetof(Sphere, radius_));
  499. engine->RegisterObjectProperty("Sphere", "bool defined", offsetof(Sphere, defined_));
  500. engine->RegisterObjectBehaviour("Frustum", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructFrustum), asCALL_CDECL_OBJLAST);
  501. engine->RegisterObjectBehaviour("Frustum", asBEHAVE_CONSTRUCT, "void f(const Frustum&in)", asFUNCTION(ConstructFrustumCopy), asCALL_CDECL_OBJLAST);
  502. engine->RegisterObjectBehaviour("Frustum", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(DestructFrustum), asCALL_CDECL_OBJLAST);
  503. engine->RegisterObjectMethod("Frustum", "Frustum &opAssign(const Frustum&in)", asMETHODPR(Frustum, operator =, (const Frustum&), Frustum&), asCALL_THISCALL);
  504. engine->RegisterObjectMethod("Frustum", "Intersection IsInside(const Vector3&in)", asMETHODPR(Frustum, IsInside, (const Vector3&) const, Intersection), asCALL_THISCALL);
  505. engine->RegisterObjectMethod("Frustum", "Intersection IsInside(const BoundingBox&in)", asMETHODPR(Frustum, IsInside, (const BoundingBox&) const, Intersection), asCALL_THISCALL);
  506. engine->RegisterObjectMethod("Frustum", "Intersection IsInside(const Sphere&in)", asMETHODPR(Frustum, IsInside, (const Sphere&) const, Intersection), asCALL_THISCALL);
  507. engine->RegisterObjectProperty("Frustum", "bool defined", offsetof(Frustum, defined_));
  508. engine->RegisterObjectMethod("Frustum", "Vector3 get_vertices(uint) const", asFUNCTION(FrustumGetVertex), asCALL_CDECL_OBJLAST);
  509. }
  510. static void ConstructColor(Color* ptr)
  511. {
  512. new(ptr) Color();
  513. }
  514. static void ConstructColorCopy(const Color& color, Color* ptr)
  515. {
  516. new(ptr) Color(color);
  517. }
  518. static void ConstructColorRGBA(float r, float g, float b, float a, Color* ptr)
  519. {
  520. new(ptr) Color(r, g, b, a);
  521. }
  522. static void ConstructColorRGB(float r, float g, float b, Color* ptr)
  523. {
  524. new(ptr) Color(r, g, b);
  525. }
  526. static void RegisterColor(asIScriptEngine* engine)
  527. {
  528. engine->RegisterObjectType("Color", sizeof(Color), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_CAK);
  529. engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(ConstructColor), asCALL_CDECL_OBJLAST);
  530. engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f(const Color&in)", asFUNCTION(ConstructColorCopy), asCALL_CDECL_OBJLAST);
  531. engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f(float, float, float, float)", asFUNCTION(ConstructColorRGBA), asCALL_CDECL_OBJLAST);
  532. engine->RegisterObjectBehaviour("Color", asBEHAVE_CONSTRUCT, "void f(float, float, float)", asFUNCTION(ConstructColorRGB), asCALL_CDECL_OBJLAST);
  533. engine->RegisterObjectMethod("Color", "Color &opAssign(const Color&in)", asMETHOD(Color, operator =), asCALL_THISCALL);
  534. engine->RegisterObjectMethod("Color", "Color &opAddAssign(const Color&in)", asMETHOD(Color, operator +=), asCALL_THISCALL);
  535. engine->RegisterObjectMethod("Color", "bool opEquals(const Color&in) const", asMETHOD(Color, operator ==), asCALL_THISCALL);
  536. engine->RegisterObjectMethod("Color", "Color opMul(float) const", asMETHOD(Color, operator *), asCALL_THISCALL);
  537. engine->RegisterObjectMethod("Color", "Color opAdd(const Color&in) const", asMETHOD(Color, operator +), asCALL_THISCALL);
  538. engine->RegisterObjectMethod("Color", "Color Lerp(const Color&in, float) const", asMETHOD(Color, Lerp), asCALL_THISCALL);
  539. engine->RegisterObjectMethod("Color", "String ToString() const", asFUNCTIONPR(ToString, (const Color&), String), asCALL_CDECL_OBJLAST);
  540. engine->RegisterObjectMethod("Color", "Vector3 get_rgb() const", asMETHOD(Color, GetRGB), asCALL_THISCALL);
  541. engine->RegisterObjectMethod("Color", "float get_intensity() const", asMETHOD(Color, GetIntensity), asCALL_THISCALL);
  542. engine->RegisterObjectProperty("Color", "float r", offsetof(Color, r_));
  543. engine->RegisterObjectProperty("Color", "float g", offsetof(Color, g_));
  544. engine->RegisterObjectProperty("Color", "float b", offsetof(Color, b_));
  545. engine->RegisterObjectProperty("Color", "float a", offsetof(Color, a_));
  546. }
  547. void RegisterMathAPI(asIScriptEngine* engine)
  548. {
  549. RegisterMathFunctions(engine);
  550. RegisterIntRect(engine);
  551. RegisterIntVector2(engine);
  552. RegisterVector2(engine);
  553. RegisterVector3(engine);
  554. RegisterVector4(engine);
  555. RegisterQuaternion(engine);
  556. RegisterRay(engine);
  557. RegisterRect(engine);
  558. RegisterVolumes(engine);
  559. RegisterColor(engine);
  560. /// \todo Register Matrix types
  561. }