terrain_main.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #include "Crown.h"
  2. #include "Terrain.h"
  3. #include "FPSSystem.h"
  4. #include "Game.h"
  5. using namespace crown;
  6. class WndCtrl: public KeyboardListener
  7. {
  8. public:
  9. //WndCtrl()
  10. //{
  11. // device()->input_manager()->register_keyboard_listener(this);
  12. //}
  13. //void key_released(const KeyboardEvent& event)
  14. //{
  15. // if (event.key == KC_ESCAPE)
  16. // {
  17. // device()->stop();
  18. // }
  19. //}
  20. };
  21. class MainScene
  22. {
  23. public:
  24. //MainScene() :
  25. // optShowSkybox(true),
  26. // optShowCrate(true),
  27. // optShowTerrain(true),
  28. // camera_active(true)
  29. //{
  30. // mouseRightPressed = false;
  31. // mouseLeftPressed = false;
  32. //}
  33. //~MainScene()
  34. //{
  35. //}
  36. //void poll_input()
  37. //{
  38. // Keyboard* keyb = device()->keyboard();
  39. // Mouse* mouse = device()->mouse();
  40. // if (keyb->key_pressed(KC_1))
  41. // {
  42. // terrain.PlotCircle(2, 2, 2, 2);
  43. // }
  44. // if (keyb->key_pressed(KC_2))
  45. // {
  46. // terrain.PlotCircle(4, 4, 4, 2);
  47. // }
  48. // if (keyb->key_pressed(KC_3))
  49. // {
  50. // terrain.PlotCircle(8, 8, 8, 2);
  51. // }
  52. // if (keyb->key_pressed(KC_F5))
  53. // {
  54. // device()->reload(grass);
  55. // }
  56. // if (keyb->key_pressed(KC_SPACE))
  57. // {
  58. // camera_active = !camera_active;
  59. // }
  60. // mouseLeftPressed = mouse->button_pressed(MB_LEFT);
  61. // mouseRightPressed = mouse->button_pressed(MB_RIGHT);
  62. //}
  63. //
  64. //void on_load()
  65. //{
  66. // crown::Renderer* renderer = crown::device()->renderer();
  67. //
  68. // Vec3 start = Vec3(0.0f, 10.0f, 0.0f);
  69. // // Add a movable camera
  70. // cam = CE_NEW(m_allocator, Camera)(start, 90.0f, 1.6f);
  71. // system = CE_NEW(m_allocator, FPSSystem)(cam, 10.0f, 2.5f);
  72. // terrain.CreateTerrain(64, 64, 1, 0.0f);
  73. // terrain.PlotCircle(4, 4, 4, 2);
  74. // terrain.UpdateVertexBuffer(true);
  75. // // red_north = device()->load("textures/red_north.tga");
  76. // // red_south = device()->load("textures/red_south.tga");
  77. // // red_east = device()->load("textures/red_east.tga");
  78. // // red_west = device()->load("textures/red_west.tga");
  79. // // red_up = device()->load("textures/red_up.tga");
  80. // // red_down = device()->load("textures/red_down.tga");
  81. // grass = device()->load("textures/grass.tga");
  82. // device()->resource_manager()->flush();
  83. // TextureResource* grass_texture = (TextureResource*)device()->data(grass);
  84. // grass_id = device()->renderer()->create_texture(grass_texture->width(), grass_texture->height(), grass_texture->format(), grass_texture->data());
  85. //}
  86. //void on_unload()
  87. //{
  88. // device()->unload(grass);
  89. // device()->unload(red_north);
  90. // device()->unload(red_south);
  91. // device()->unload(red_east);
  92. // device()->unload(red_west);
  93. // device()->unload(red_up);
  94. // device()->unload(red_down);
  95. // CE_DELETE(m_allocator, system);
  96. // CE_DELETE(m_allocator, cam);
  97. //}
  98. //void update(float dt)
  99. //{
  100. // poll_input();
  101. // Renderer* renderer = device()->renderer();
  102. // renderer->set_clear_color(Color4::LIGHTBLUE);
  103. //
  104. // if (camera_active)
  105. // {
  106. // system->set_view_by_cursor();
  107. // }
  108. // system->update(dt);
  109. // renderer->set_texturing(0, false);
  110. // ray.set_origin(cam->position());
  111. // ray.set_direction(cam->look_at());
  112. // /* Render the terrain */
  113. // renderer->set_ambient_light(Color4(0.5f, 0.5f, 0.5f, 1.0f));
  114. // renderer->set_matrix(MT_MODEL, Mat4::IDENTITY);
  115. // if (device()->is_loaded(grass))
  116. // {
  117. // renderer->set_texturing(0, true);
  118. // renderer->bind_texture(0, grass_id);
  119. // }
  120. // terrain.Render();
  121. // /* Test for intersection */
  122. // Triangle tri, tri2;
  123. // float dist;
  124. // if (terrain.TraceRay(ray, tri, tri2, dist))
  125. // {
  126. // renderer->set_depth_test(false);
  127. // Vec3 intersectionPoint = ray.origin() + (ray.direction() * dist);
  128. // if (mouseLeftPressed)
  129. // {
  130. // terrain.ApplyBrush(intersectionPoint, 0.09f);
  131. // terrain.UpdateVertexBuffer(true);
  132. // }
  133. // if (mouseRightPressed)
  134. // {
  135. // terrain.ApplyBrush(intersectionPoint, -0.09f);
  136. // terrain.UpdateVertexBuffer(true);
  137. // }
  138. // renderer->set_depth_test(true);
  139. // }
  140. //}
  141. //private:
  142. //HeapAllocator m_allocator;
  143. //FPSSystem* system;
  144. //Camera* cam;
  145. //Mat4 ortho;
  146. //Terrain terrain;
  147. //// Resources
  148. //ResourceId grass;
  149. //ResourceId red_north;
  150. //ResourceId red_south;
  151. //ResourceId red_east;
  152. //ResourceId red_west;
  153. //ResourceId red_up;
  154. //ResourceId red_down;
  155. //TextureId grass_id;
  156. //RenderBufferId rb_id;
  157. //VertexShaderId vs_id;
  158. //PixelShaderId ps_id;
  159. //GPUProgramId gpu_program_id;
  160. //ResourceId script;
  161. //bool optShowSkybox;
  162. //bool optShowCrate;
  163. //bool optShowTerrain;
  164. //bool mouseLeftPressed;
  165. //bool mouseRightPressed;
  166. //float wheel;
  167. //bool camera_active;
  168. //Ray ray;
  169. public:
  170. inline void dumb_func()
  171. {
  172. if (device()->is_init())
  173. {
  174. os::printf("SEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n");
  175. }
  176. }
  177. };
  178. MainScene m_scene;
  179. //WndCtrl m_ctrl;
  180. void init()
  181. {
  182. //m_scene.on_load();
  183. m_scene.dumb_func();
  184. }
  185. void shutdown_1()
  186. {
  187. //m_scene.on_unload();
  188. }
  189. void frame(float dt)
  190. {
  191. //m_scene.update(dt);
  192. }