test_particles.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*************************************************************************/
  2. /* test_particles.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "test_particles.h"
  30. #include "servers/visual_server.h"
  31. #include "os/main_loop.h"
  32. #include "math_funcs.h"
  33. #include "print_string.h"
  34. namespace TestParticles {
  35. class TestMainLoop : public MainLoop {
  36. RID particles;
  37. RID instance;
  38. RID camera;
  39. RID viewport;
  40. RID light;
  41. RID scenario;
  42. struct InstanceInfo {
  43. RID instance;
  44. Transform base;
  45. Vector3 rot_axis;
  46. };
  47. List<InstanceInfo> instances;
  48. float ofs;
  49. bool quit;
  50. public:
  51. virtual void input_event(const InputEvent& p_event) {
  52. }
  53. virtual void request_quit() {
  54. quit=true;
  55. }
  56. virtual void init() {
  57. VisualServer *vs=VisualServer::get_singleton();
  58. particles = vs->particles_create();
  59. vs->particles_set_amount(particles,1000);
  60. instance = vs->instance_create2(particles,scenario);
  61. camera = vs->camera_create();
  62. // vs->camera_set_perspective( camera, 60.0,0.1, 100.0 );
  63. viewport = vs->viewport_create();
  64. vs->viewport_attach_camera( viewport, camera );
  65. vs->camera_set_transform(camera, Transform( Matrix3(), Vector3(0,0,20 ) ) );
  66. /*
  67. RID lightaux = vs->light_create( VisualServer::LIGHT_OMNI );
  68. vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_RADIUS, 80 );
  69. vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ATTENUATION, 1 );
  70. vs->light_set_var( lightaux, VisualServer::LIGHT_VAR_ENERGY, 1.5 );
  71. light = vs->instance_create2( lightaux );
  72. */
  73. RID lightaux = vs->light_create( VisualServer::LIGHT_DIRECTIONAL );
  74. // vs->light_set_color( lightaux, VisualServer::LIGHT_COLOR_AMBIENT, Color(0.0,0.0,0.0) );
  75. light = vs->instance_create2( lightaux, scenario );
  76. ofs=0;
  77. quit=false;
  78. }
  79. virtual bool idle(float p_time) {
  80. return false;
  81. }
  82. virtual bool iteration(float p_time) {
  83. // VisualServer *vs=VisualServer::get_singleton();
  84. ofs+=p_time;
  85. return quit;
  86. }
  87. virtual void finish() {
  88. }
  89. };
  90. MainLoop* test() {
  91. return memnew( TestMainLoop );
  92. }
  93. }