Simple game engine with complete export to scripting language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

139 lines
3.3 KiB

  1. #ifndef BLUECORE_SCRIPTING_MATH_H
  2. #define BLUECORE_SCRIPTING_MATH_H
  3. #include "ScriptSystem.h"
  4. namespace BlueCore
  5. {
  6. //------------------------------------------------------------------------------
  7. inline void _setvectorvalues(HSQUIRRELVM &v, const SQInteger &idx,
  8. const SQFloat &x, const SQFloat &y, const SQFloat &z)
  9. {
  10. sq_pushstring (v, "x", 1);
  11. sq_pushfloat (v, x );
  12. sq_rawset (v, idx );
  13. sq_pushstring (v, "y", 1);
  14. sq_pushfloat (v, y );
  15. sq_rawset (v, idx );
  16. sq_pushstring (v, "z", 1);
  17. sq_pushfloat (v, z );
  18. sq_rawset (v, idx );
  19. }
  20. //------------------------------------------------------------------------------
  21. inline void _getvectorvalues(HSQUIRRELVM &v, const SQInteger &idx, SQFloat &x,
  22. SQFloat &y, SQFloat &z)
  23. {
  24. sq_pushstring (v, "x", 1);
  25. sq_rawget (v, idx );
  26. sq_getfloat (v, -1, &x );
  27. sq_pushstring (v, "y", 1);
  28. sq_rawget (v, idx );
  29. sq_getfloat (v, -1, &y );
  30. sq_pushstring (v, "z", 1);
  31. sq_rawget (v, idx );
  32. sq_getfloat (v, -1, &z );
  33. sq_pop (v, 3);
  34. }
  35. //------------------------------------------------------------------------------
  36. inline void _pushvector(HSQUIRRELVM &v, const SQFloat &x, const SQFloat &y,
  37. const SQFloat &z)
  38. {
  39. // get closure/class
  40. // TODO: use SQObject rfom creation
  41. sq_pushroottable (v );
  42. sq_pushstring (v, "Vector", -1);
  43. sq_get (v, -2);
  44. sq_remove (v, -2);
  45. // call constructor
  46. sq_pushroottable (v );
  47. sq_pushfloat (v, x );
  48. sq_pushfloat (v, y );
  49. sq_pushfloat (v, z );
  50. sq_call (v, 4, SQTrue, SQTrue );
  51. // remove class, leave instance
  52. sq_remove (v, -2);
  53. }
  54. //------------------------------------------------------------------------------
  55. inline void _pushquaternion(HSQUIRRELVM &v, const SQFloat &w, const SQFloat &x,
  56. const SQFloat &y, const SQFloat &z)
  57. {
  58. // get closure/class
  59. // TODO: use SQObject rfom creation!!!!!!
  60. sq_pushroottable (v );
  61. sq_pushstring (v, "Quaternion", -1);
  62. sq_get (v, -2);
  63. sq_remove (v, -2);
  64. // call constructor
  65. sq_pushroottable (v );
  66. sq_pushfloat (v, w );
  67. sq_pushfloat (v, x );
  68. sq_pushfloat (v, y );
  69. sq_pushfloat (v, z );
  70. sq_call (v, 5, SQTrue, SQTrue );
  71. // remove class, leave instance
  72. sq_remove (v, -2);
  73. }
  74. //------------------------------------------------------------------------------
  75. inline void _setquaternionvalues(HSQUIRRELVM &v, const SQInteger &idx,
  76. const SQFloat &w, const SQFloat &x, const SQFloat &y, const SQFloat &z)
  77. {
  78. sq_pushstring (v, "w", -1);
  79. sq_pushfloat (v, w );
  80. sq_rawset (v, idx );
  81. sq_pushstring (v, "x", -1);
  82. sq_pushfloat (v, x );
  83. sq_rawset (v, idx );
  84. sq_pushstring (v, "y", -1);
  85. sq_pushfloat (v, y );
  86. sq_rawset (v, idx );
  87. sq_pushstring (v, "z", -1);
  88. sq_pushfloat (v, z );
  89. sq_rawset (v, idx );
  90. }
  91. //------------------------------------------------------------------------------
  92. inline void _getquaternionvalues(HSQUIRRELVM &v, const SQInteger &idx,
  93. SQFloat &w, SQFloat &x, SQFloat &y, SQFloat &z)
  94. {
  95. sq_pushstring (v, "w", -1);
  96. sq_get (v, idx );
  97. sq_getfloat (v, -1, &w );
  98. sq_pushstring (v, "x", -1);
  99. sq_get (v, idx );
  100. sq_getfloat (v, -1, &x );
  101. sq_pushstring (v, "y", -1);
  102. sq_get (v, idx );
  103. sq_getfloat (v, -1, &y );
  104. sq_pushstring (v, "z", -1);
  105. sq_get (v, idx );
  106. sq_getfloat (v, -1, &z );
  107. sq_pop (v, 3);
  108. }
  109. void setupScriptSystem_Math(ScriptSystem* scriptsystem);
  110. } // namespace BlueCore
  111. #endif