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.

ScriptSystem_Camera.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #include "ScriptSystem_Camera.h"
  2. #include "ScriptSystem_Math.h"
  3. #include "Camera.h"
  4. namespace BlueCore
  5. {
  6. static SQInteger _camera_releasehook(SQUserPointer p, SQInteger size)
  7. {
  8. Camera *camera = (Camera *)p;
  9. if (camera)
  10. camera->removeReference();
  11. return 1;
  12. }
  13. static SQInteger _camera_constructor(HSQUIRRELVM vm)
  14. {
  15. SQInteger argc = sq_gettop(vm);
  16. if (argc < 1)
  17. return 0;
  18. Camera *camera = new Camera();
  19. camera->addReference();
  20. sq_setinstanceup(vm, 1, (void *)camera );
  21. sq_setreleasehook(vm, 1, _camera_releasehook);
  22. return 0;
  23. }
  24. static SQInteger _camera_setposition(HSQUIRRELVM v)
  25. {
  26. Camera *camera = 0;
  27. sq_getinstanceup(v, 1, ( void ** ) &camera, 0);
  28. if (camera)
  29. {
  30. Vector3 position;
  31. int argc = sq_gettop(v);
  32. if (argc == 2)
  33. {
  34. _getvectorvalues(v, 2, position.x, position.y, position.z);
  35. }
  36. else if (argc == 4)
  37. {
  38. sq_getfloat(v, 2, &position.x);
  39. sq_getfloat(v, 3, &position.y);
  40. sq_getfloat(v, 4, &position.z);
  41. }
  42. camera->setPosition(position);
  43. }
  44. return 0;
  45. }
  46. static SQInteger _camera_lookat(HSQUIRRELVM v)
  47. {
  48. Camera *camera = 0;
  49. sq_getinstanceup(v, 1, ( void ** ) &camera, 0);
  50. if (camera)
  51. {
  52. Vector3 position;
  53. int argc = sq_gettop(v);
  54. if (argc == 2)
  55. {
  56. _getvectorvalues(v, 2, position.x, position.y, position.z);
  57. }
  58. else if (argc == 4)
  59. {
  60. sq_getfloat(v, 2, &position.x);
  61. sq_getfloat(v, 3, &position.y);
  62. sq_getfloat(v, 4, &position.z);
  63. }
  64. camera->lookAt(position);
  65. }
  66. return 0;
  67. }
  68. void setupScriptSystem_Camera(ScriptSystem* scriptsystem)
  69. {
  70. if (scriptsystem == 0)
  71. return;
  72. HSQUIRRELVM vm = scriptsystem->getVM();
  73. sq_pushroottable(vm);
  74. // push class
  75. sq_pushstring(vm, "Camera", -1);
  76. if (SQ_SUCCEEDED(sq_newclass(vm, SQFalse) ) )
  77. {
  78. // register constructor
  79. sq_pushstring(vm, "constructor", -1);
  80. sq_newclosure(vm, _camera_constructor, 0);
  81. sq_newslot(vm, -3, false);
  82. sq_pushstring(vm, "setPosition", -1);
  83. sq_newclosure(vm, _camera_setposition, 0);
  84. sq_newslot(vm, -3, false);
  85. sq_pushstring(vm, "lookAt", -1);
  86. sq_newclosure(vm, _camera_lookat, 0);
  87. sq_newslot(vm, -3, false);
  88. // create class
  89. sq_newslot(vm, -3, false);
  90. }
  91. sq_poptop(vm);
  92. }
  93. }