Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

569 rader
21 KiB

  1. //
  2. // Lol Engine - EasyMesh tutorial
  3. //
  4. // Copyright: (c) 2011-2013 Sam Hocevar <sam@hocevar.net>
  5. // (c) 2012-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #if defined HAVE_CONFIG_H
  12. # include "config.h"
  13. #endif
  14. #include <cfloat> /* for FLT_MAX */
  15. #include "core.h"
  16. using namespace std;
  17. using namespace lol;
  18. static int const TEXTURE_WIDTH = 256;
  19. LOLFX_RESOURCE_DECLARE(shinyfur);
  20. LOLFX_RESOURCE_DECLARE(shinymvtexture);
  21. enum
  22. {
  23. KEY_CAM_RESET,
  24. KEY_CAM_FORWARD,
  25. KEY_CAM_BACKWARD,
  26. KEY_CAM_ZOOM_OUT,
  27. KEY_CAM_ZOOM_IN,
  28. KEY_MESH_UPDATE,
  29. KEY_MESH_RESET,
  30. KEY_MESH_PREV,
  31. KEY_MESH_NEXT,
  32. KEY_MESH_LEFT,
  33. KEY_MESH_RIGHT,
  34. KEY_MESH_UP,
  35. KEY_MESH_DOWN,
  36. KEY_MESH_SCALE_UP,
  37. KEY_MESH_SCALE_DOWN,
  38. KEY_MESH_OFFSET_UP,
  39. KEY_MESH_OFFSET_DOWN,
  40. KEY_MESH_ROT_LEFT,
  41. KEY_MESH_ROT_RIGHT,
  42. KEY_MESH_ROT_UP,
  43. KEY_MESH_ROT_DOWN,
  44. KEY_F1,
  45. KEY_F2,
  46. KEY_F3,
  47. KEY_F4,
  48. KEY_F5,
  49. KEY_ESC,
  50. KEY_MAX,
  51. };
  52. #define MIN_FOV 0.1f
  53. #define WITH_FUR 0
  54. #define WITH_TEXTURE 0
  55. class MeshViewer : public WorldEntity
  56. {
  57. public:
  58. void SetFov(float new_fov=60.0f, vec2 video_size = vec2(Video::GetSize()))
  59. {
  60. if (new_fov > MIN_FOV)
  61. g_scene->GetCamera()->SetProjection(mat4::perspective(new_fov, video_size.x, video_size.y, .1f, 1000.f));
  62. else
  63. g_scene->GetCamera()->SetProjection(mat4::ortho(video_size.x, video_size.y, .1f, 1000.f));
  64. }
  65. MeshViewer(char const *file_name = "data/mesh-buffer.txt")
  66. : m_file_name(file_name)
  67. {
  68. /* Register an input controller for the keyboard */
  69. m_controller = new Controller(KEY_MAX, 0);
  70. m_controller->GetKey(KEY_CAM_RESET).Bind("Keyboard", "Return");
  71. m_controller->GetKey(KEY_CAM_ZOOM_IN).Bind("Keyboard", "PageUp");
  72. m_controller->GetKey(KEY_CAM_ZOOM_OUT).Bind("Keyboard", "PageDown");
  73. m_controller->GetKey(KEY_MESH_LEFT).Bind("Keyboard", "Left");
  74. m_controller->GetKey(KEY_MESH_RIGHT).Bind("Keyboard", "Right");
  75. m_controller->GetKey(KEY_MESH_UP).Bind("Keyboard", "Up");
  76. m_controller->GetKey(KEY_MESH_DOWN).Bind("Keyboard", "Down");
  77. m_controller->GetKey(KEY_MESH_UPDATE).Bind("Keyboard", "Space");
  78. m_controller->GetKey(KEY_MESH_RESET).Bind("Keyboard", "KP0");
  79. m_controller->GetKey(KEY_MESH_PREV).Bind("Keyboard", "KPPlus");
  80. m_controller->GetKey(KEY_MESH_NEXT).Bind("Keyboard", "KPMinus");
  81. m_controller->GetKey(KEY_MESH_OFFSET_DOWN).Bind("Keyboard", "KP1");
  82. m_controller->GetKey(KEY_MESH_OFFSET_UP).Bind("Keyboard", "KP3");
  83. m_controller->GetKey(KEY_MESH_SCALE_DOWN).Bind("Keyboard", "KP7");
  84. m_controller->GetKey(KEY_MESH_SCALE_UP).Bind("Keyboard", "KP9");
  85. m_controller->GetKey(KEY_MESH_ROT_LEFT).Bind("Keyboard", "KP4");
  86. m_controller->GetKey(KEY_MESH_ROT_RIGHT).Bind("Keyboard", "KP6");
  87. m_controller->GetKey(KEY_MESH_ROT_UP).Bind("Keyboard", "KP8");
  88. m_controller->GetKey(KEY_MESH_ROT_DOWN).Bind("Keyboard", "KP5");
  89. m_controller->GetKey(KEY_F1).Bind("Keyboard", "F1");
  90. m_controller->GetKey(KEY_F2).Bind("Keyboard", "F2");
  91. m_controller->GetKey(KEY_F3).Bind("Keyboard", "F3");
  92. m_controller->GetKey(KEY_F4).Bind("Keyboard", "F4");
  93. m_controller->GetKey(KEY_F5).Bind("Keyboard", "F5");
  94. m_controller->GetKey(KEY_ESC).Bind("Keyboard", "Escape");
  95. // State
  96. m_mesh_shown = 0;
  97. m_angle = 0;
  98. m_default_texture = NULL;
  99. //Camera Setup
  100. m_fov_zoom_damp = .0f;
  101. m_fov_damp = 60.0f;
  102. m_fov = 60.0f;
  103. m_camera = new Camera();
  104. SetFov(m_fov_damp);
  105. m_camera->SetView(vec3(0.f, 0.f, 10.f),
  106. vec3(0.f, 0.f, 0.f),
  107. vec3(0.f, 1.f, 0.f));
  108. g_scene->PushCamera(m_camera);
  109. //Lights setup
  110. m_lights << new Light();
  111. m_lights.Last()->SetPosition(vec4(4.f, -1.f, -4.f, 0.f));
  112. m_lights.Last()->SetColor(vec4(.0f, .2f, .5f, 1.f));
  113. Ticker::Ref(m_lights.Last());
  114. m_lights << new Light();
  115. m_lights.Last()->SetPosition(vec4(8.f, 2.f, 6.f, 1.f));
  116. m_lights.Last()->SetColor(vec4(.5f, .3f, .0f, 1.f));
  117. Ticker::Ref(m_lights.Last());
  118. //Speed damp
  119. m_mesh_rotate_damp = vec2(.0f);
  120. m_mesh_screen_move_damp = vec2(.0f);
  121. m_mesh_move_damp = vec2(.0f);
  122. //Actual values
  123. SetDefaultMeshTransform();
  124. //Actual values damp
  125. m_mesh_rotation_damp = vec2(.0f);
  126. m_mesh_screen_offset_damp = vec2(.0f);
  127. m_mesh_offset_damp = vec2(.0f);
  128. m_mat = mat4::rotate(m_mesh_rotation.x, vec3(1, 0, 0)) *
  129. mat4::rotate(m_angle, vec3(0, 1, 0)) *
  130. mat4::rotate(m_mesh_rotation.y, vec3(0, 1, 0));
  131. m_stream_update_time = 2.0f;
  132. m_stream_update_timer = 1.0f;
  133. }
  134. ~MeshViewer()
  135. {
  136. g_scene->PopCamera(m_camera);
  137. for (int i = 0; i < m_lights.Count(); ++i)
  138. Ticker::Unref(m_lights[i]);
  139. }
  140. void SetDefaultMeshTransform()
  141. {
  142. m_mesh_rotation = vec2(25.0f, .0f);
  143. m_mesh_screen_offset = vec2(.54f, .0f);
  144. m_mesh_offset = vec2(-.64f, .07f);
  145. }
  146. virtual void TickGame(float seconds)
  147. {
  148. WorldEntity::TickGame(seconds);
  149. //TODO : This should probably be "standard LoL behaviour"
  150. {
  151. //Shutdown logic
  152. if (m_controller->GetKey(KEY_ESC).IsReleased())
  153. Ticker::Shutdown();
  154. }
  155. //--
  156. //Update Mesh BBox - Get the Min/Max needed
  157. //--
  158. vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
  159. vec3 cam_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
  160. vec3 world_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
  161. int mesh_id = m_meshes.Count() - 1;
  162. for (; mesh_id >= 0; mesh_id--)
  163. if (m_meshes[mesh_id].m2)
  164. break;
  165. mat4 world_cam = g_scene->GetCamera()->GetView();
  166. mat4 cam_screen = g_scene->GetCamera()->GetProjection();
  167. if (m_meshes.Count() && mesh_id >= 0)
  168. {
  169. for (int i = 0; i < m_meshes[mesh_id].m1.GetVertexCount(); i++)
  170. {
  171. //--
  172. mat4 LocalPos = m_mat * mat4::translate(m_meshes[mesh_id].m1.GetVertexLocation(i));
  173. vec3 vpos = LocalPos.v3.xyz;
  174. world_min_max[0] = min(vpos.xyz, world_min_max[0]);
  175. world_min_max[1] = max(vpos.xyz, world_min_max[1]);
  176. //--
  177. LocalPos = world_cam * LocalPos;
  178. vpos = LocalPos.v3.xyz;
  179. cam_min_max[0] = min(vpos.xyz, cam_min_max[0]);
  180. cam_min_max[1] = max(vpos.xyz, cam_min_max[1]);
  181. //--
  182. LocalPos = cam_screen * LocalPos;
  183. vpos = (LocalPos.v3 / LocalPos.v3.w).xyz;
  184. screen_min_max[0] = min(vpos.xy, screen_min_max[0]);
  185. screen_min_max[1] = max(vpos.xy, screen_min_max[1]);
  186. }
  187. }
  188. else
  189. {
  190. world_min_max[1] = vec3(.0f);
  191. world_min_max[0] = vec3(.0f);
  192. cam_min_max[1] = vec3(.0f);
  193. cam_min_max[0] = vec3(.0f);
  194. screen_min_max[0] = vec2(.0f);
  195. screen_min_max[1] = vec2(.0f);
  196. }
  197. //[0] : center, [1] : size.
  198. vec3 BBox[2] = { vec3(.0f), vec3(.0f) };
  199. BBox[1] = world_min_max[1] - world_min_max[0];
  200. BBox[0] = world_min_max[0] + BBox[1] * .5f;
  201. vec3 BBox_mod = BBox[1];
  202. #if 0
  203. //--
  204. //Camera movement handling
  205. //--
  206. if (m_controller->GetKey(KEY_CAM_RESET).IsReleased())
  207. SetFov();
  208. //Auto Fov
  209. float local_max = max(max(lol::abs(world_min_max[0].x), lol::abs(world_min_max[0].y)),
  210. max( lol::abs(world_min_max[1].x), lol::abs(world_min_max[1].y)));
  211. float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
  212. max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
  213. //Fov modification
  214. float fov_zoom = (float)(Input::GetStatus(IPT_CAM_ZOOM_OUT) - Input::GetStatus(IPT_CAM_ZOOM_IN));
  215. m_fov_zoom_damp = damp(m_fov_zoom_damp, fov_zoom, (fov_zoom == .0f)?(.15f):(0.5f), seconds);
  216. m_fov = max(.0f, m_fov + seconds * 10.0f * m_fov_zoom_damp);
  217. m_fov_damp = damp(m_fov_damp, m_fov, .2f, seconds);
  218. if (m_fov_damp < MIN_FOV)
  219. {
  220. vec2 tmp = vec2(Video::GetSize());
  221. SetFov(0, vec2(local_max * 2.2f) * (tmp / vec2(tmp.y)));
  222. }
  223. else
  224. SetFov(m_fov_damp);
  225. //Move modification
  226. vec3 campos = g_scene->GetCamera()->GetPosition();
  227. if (m_fov_damp < MIN_FOV)
  228. g_scene->GetCamera()->SetView(vec3(campos.xy, 10.f), quat(1.f));
  229. else if (fov_ratio > .0f)
  230. g_scene->GetCamera()->SetView(vec3(campos.xy, campos.z * fov_ratio * 1.1f), quat(1.f));
  231. #else
  232. Camera* cur_cam = g_scene->GetCamera();
  233. vec3 min_max_diff = (cam_min_max[1] - cam_min_max[0]);
  234. float screen_size = max(max(lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)),
  235. max( lol::abs(min_max_diff.x), lol::abs(min_max_diff.y)));
  236. float fov_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
  237. max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
  238. float fov_zoom = 0.f;
  239. fov_zoom += m_controller->GetKey(KEY_CAM_ZOOM_OUT).IsDown() ? 1.f : 0.f;
  240. fov_zoom -= m_controller->GetKey(KEY_CAM_ZOOM_IN).IsDown() ? 1.f : 0.f;
  241. m_fov_zoom_damp = damp(m_fov_zoom_damp, fov_zoom, (fov_zoom == .0f)?(.15f):(0.5f), seconds);
  242. m_fov = max(.0f, m_fov + seconds * 10.0f * m_fov_zoom_damp);
  243. m_fov_damp = damp(m_fov_damp, m_fov, .2f, seconds);
  244. if (m_fov_damp < MIN_FOV)
  245. cur_cam->SetProjection(mat4::ortho(screen_size * fov_ratio * 1.1f, 1600.f / 600.f, 1000.f));
  246. else if (fov_ratio > .0f)
  247. cur_cam->SetProjection(mat4::shifted_perspective(m_fov_damp, screen_size * fov_ratio * 1.1f, 1600.f / 600.f, 1000.f));
  248. vec3 cam_center = cam_min_max[0] + min_max_diff * .5f;
  249. vec4 test = inverse(world_cam) * vec4(.0f,.0f,-1.0f,1.f);
  250. test = test;
  251. test = inverse(world_cam) * vec4(.0f,.0f,.0f,1.f);
  252. test = inverse(world_cam) * vec4(.0f,.0f,1.0f,1.f);
  253. vec3 eye = (inverse(world_cam) * vec4(vec3(cam_center.xy, cam_min_max[1].z), 1.f)).xyz;
  254. vec3 target = (inverse(world_cam) * vec4(vec3(cam_center.xy, cam_min_max[0].z), 1.f)).xyz;
  255. if (eye == target)
  256. cur_cam->SetView(vec3(.0f), vec3(.0f, .0f, -1.f), vec3(0.f, 1.f, 0.f));
  257. else
  258. cur_cam->SetView(eye, target, vec3(0,1,0));
  259. #endif
  260. //--
  261. //Mesh movement handling
  262. //--
  263. if (m_controller->GetKey(KEY_MESH_RESET).IsReleased())
  264. SetDefaultMeshTransform();
  265. m_mesh_shown += m_controller->GetKey(KEY_MESH_NEXT).IsReleased() ? 1 : 0;
  266. m_mesh_shown -= m_controller->GetKey(KEY_MESH_PREV).IsReleased() ? 1 : 0;
  267. m_mesh_shown = clamp(m_mesh_shown, 0, max(m_meshes.Count(), 1) - 1);
  268. vec2 new_move = vec2(.0f);
  269. new_move.x += m_controller->GetKey(KEY_MESH_RIGHT).IsDown() ? 1.f : 0.f;
  270. new_move.x -= m_controller->GetKey(KEY_MESH_LEFT).IsDown() ? 1.f : 0.f;
  271. new_move.y += m_controller->GetKey(KEY_MESH_UP).IsDown() ? 1.f : 0.f;
  272. new_move.y -= m_controller->GetKey(KEY_MESH_DOWN).IsDown() ? 1.f : 0.f;
  273. m_mesh_screen_move_damp = vec2(damp(m_mesh_screen_move_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
  274. damp(m_mesh_screen_move_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));
  275. new_move.x = m_controller->GetKey(KEY_MESH_OFFSET_UP).IsDown() ? 1.f : 0.f;
  276. new_move.x -= m_controller->GetKey(KEY_MESH_OFFSET_DOWN).IsDown() ? 1.f : 0.f;
  277. new_move.y = m_controller->GetKey(KEY_MESH_SCALE_UP).IsDown() ? 1.f : 0.f;
  278. new_move.y -= m_controller->GetKey(KEY_MESH_SCALE_DOWN).IsDown() ? 1.f : 0.f;
  279. m_mesh_move_damp = vec2(damp(m_mesh_move_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
  280. damp(m_mesh_move_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));
  281. new_move.x = m_controller->GetKey(KEY_MESH_ROT_UP).IsDown() ? 1.f : 0.f;
  282. new_move.x -= m_controller->GetKey(KEY_MESH_ROT_DOWN).IsDown() ? 1.f : 0.f;
  283. new_move.y = m_controller->GetKey(KEY_MESH_ROT_RIGHT).IsDown() ? 1.f : 0.f;
  284. new_move.y -= m_controller->GetKey(KEY_MESH_ROT_LEFT).IsDown() ? 1.f : 0.f;
  285. m_mesh_rotate_damp = vec2(damp(m_mesh_rotate_damp.x, new_move.x, (new_move.x == .0f)?(.15f):(0.5f), seconds),
  286. damp(m_mesh_rotate_damp.y, new_move.y, (new_move.y == .0f)?(.15f):(0.5f), seconds));
  287. vec2 mesh_screen_move = seconds * 0.6f * m_mesh_screen_move_damp;
  288. vec2 mesh_offset_move = seconds * vec2(.6f, .2f) * m_mesh_move_damp;
  289. vec2 mesh_rotate = seconds * vec2(40.0f, 60.0f) * m_mesh_rotate_damp;
  290. //Add movement
  291. m_mesh_screen_offset += mesh_screen_move;
  292. m_mesh_offset += mesh_offset_move;
  293. m_mesh_rotation += mesh_rotate;
  294. //Compute damp
  295. m_mesh_rotation_damp = damp(m_mesh_rotation_damp, m_mesh_rotation, .2f, seconds);
  296. m_mesh_screen_offset_damp = damp(m_mesh_screen_offset_damp, m_mesh_screen_offset, .2f, seconds);
  297. m_mesh_offset_damp = damp(m_mesh_offset_damp, m_mesh_offset, .2f, seconds);
  298. //Clamp necessary
  299. m_mesh_rotation.x = clamp(m_mesh_rotation.x, -90.0f, 90.0f);
  300. m_mesh_offset.y = max(.0f, m_mesh_offset.y);
  301. //m_angle += seconds * 70.0f;
  302. m_mat = mat4::rotate(m_mesh_rotation.x, vec3(1, 0, 0)) *
  303. mat4::rotate(m_angle, vec3(0, 1, 0)) *
  304. mat4::rotate(m_mesh_rotation.y, vec3(0, 1, 0));
  305. //--
  306. //File management
  307. //--
  308. if (m_controller->GetKey(KEY_MESH_UPDATE).IsReleased())
  309. m_stream_update_time = m_stream_update_timer + 1.0f;
  310. m_stream_update_time += seconds;
  311. if (m_stream_update_time > m_stream_update_timer)
  312. {
  313. m_stream_update_time = 0.f;
  314. File f;
  315. f.Open(m_file_name.C(), FileAccess::Read);
  316. String cmd = f.ReadString();
  317. f.Close();
  318. for (int i = 0; i < cmd.Count() - 1; i++)
  319. {
  320. if (cmd[i] == '/' && cmd[i + 1] == '/')
  321. {
  322. int j = i;
  323. for (; j < cmd.Count(); j++)
  324. {
  325. if (cmd[j] == '\r' || cmd[j] == '\n')
  326. break;
  327. }
  328. String new_cmd = cmd.Sub(0, i);
  329. if (j < cmd.Count())
  330. new_cmd += cmd.Sub(j, cmd.Count() - j);
  331. cmd = new_cmd;
  332. i--;
  333. }
  334. }
  335. if (cmd.Count()
  336. && (!m_cmdlist.Count() || cmd != m_cmdlist.Last()))
  337. {
  338. m_cmdlist << cmd;
  339. //Create a new mesh
  340. m_meshes.Push(EasyMesh(), false, .0f, vec3(.0f));
  341. if (!m_meshes.Last().m1.Compile(cmd.C()))
  342. m_meshes.Pop();
  343. //else
  344. // m_meshes.Last().m1.ComputeTexCoord(0.2f, 2);
  345. }
  346. }
  347. }
  348. virtual void TickDraw(float seconds)
  349. {
  350. WorldEntity::TickDraw(seconds);
  351. //TODO : This should probably be "standard LoL behaviour"
  352. {
  353. if (m_controller->GetKey(KEY_F1).IsReleased())
  354. Video::SetDebugRenderMode(DebugRenderMode::Default);
  355. if (m_controller->GetKey(KEY_F2).IsReleased())
  356. Video::SetDebugRenderMode(DebugRenderMode::Wireframe);
  357. if (m_controller->GetKey(KEY_F3).IsReleased())
  358. Video::SetDebugRenderMode(DebugRenderMode::Lighting);
  359. if (m_controller->GetKey(KEY_F4).IsReleased())
  360. Video::SetDebugRenderMode(DebugRenderMode::Normal);
  361. if (m_controller->GetKey(KEY_F5).IsReleased())
  362. Video::SetDebugRenderMode(DebugRenderMode::UV);
  363. }
  364. if (!m_default_texture)
  365. {
  366. m_texture_shader = Shader::Create(LOLFX_RESOURCE_NAME(shinymvtexture));
  367. m_texture_uni = m_texture_shader->GetUniformLocation("u_Texture");
  368. //m_image = new Image("data/test-texture.png");
  369. m_default_texture = Tiler::Register("data/test-texture.png", ivec2(0), ivec2(0,1));
  370. //ivec2 size = m_image->GetSize();
  371. //// m_image->GetFormat()
  372. //m_texture = new Texture(m_image->GetSize(), PixelFormat::ABGR_8);
  373. //m_texture->SetData(m_image->GetData());
  374. // PixelFormat::ABGR_8
  375. }
  376. else if (m_texture && m_default_texture)
  377. m_texture_shader->SetUniform(m_texture_uni, m_default_texture->GetTexture(), 0);
  378. for (int i = 0; i < m_meshes.Count(); i++)
  379. {
  380. if (!m_meshes[i].m2)
  381. {
  382. //Fur support
  383. #if WITH_FUR
  384. m_meshes[i].m1.MeshConvert(Shader::Create(LOLFX_RESOURCE_NAME(shinyfur)));
  385. #elif WITH_TEXTURE
  386. //m_meshes[i].m1.MeshConvert(m_texture_shader);
  387. //m_meshes[i].m1.MeshConvert();
  388. m_meshes[i].m1.MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) |
  389. (1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)),
  390. m_texture_shader, true));
  391. #else
  392. m_meshes[i].m1.MeshConvert();
  393. #endif
  394. m_meshes[i].m2 = true;
  395. }
  396. }
  397. g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  398. mat4 default_proj = g_scene->GetCamera()->GetProjection();
  399. int max_drawn = m_meshes.Count() - m_mesh_shown;
  400. for (int i = max_drawn; i < m_meshes.Count(); i++)
  401. m_meshes[i].m4 = vec3(.0f);
  402. for (int i = 0; i < max_drawn; i++)
  403. {
  404. float new_scale = max(.0f, 1.0f - (m_mesh_offset_damp.y * (float)(max_drawn - (i + 1))));
  405. m_meshes[i].m3 = damp(m_meshes[i].m3, new_scale, .35f, seconds);
  406. if (m_meshes[i].m3 > .0f)
  407. {
  408. vec3 new_mesh_offset = vec3(.0f);
  409. //damping calculations
  410. for (int j = max_drawn - 1; j > i; j--)
  411. {
  412. float ofs_scale = max(.0f, 1.0f - (m_mesh_offset_damp.y * (float)(max_drawn - (j + 0))));
  413. new_mesh_offset = new_mesh_offset + vec3(m_meshes[j].m3 * ofs_scale * ofs_scale * m_mesh_offset_damp.x, .0f, .0f);
  414. }
  415. m_meshes[i].m4 = damp(m_meshes[i].m4, new_mesh_offset, .35f, seconds);
  416. g_scene->GetCamera()->SetProjection(
  417. mat4::translate(m_meshes[i].m4) *
  418. mat4::translate(vec3(m_mesh_screen_offset_damp, .0f)) *
  419. mat4::scale(vec3(vec2(m_meshes[i].m3), 1.0f)) *
  420. default_proj);
  421. #if WITH_FUR
  422. for (int j=0; j < 40; j++)
  423. m_meshes[i].m1.Render(m_mat, 0.1 * j);
  424. #else
  425. m_meshes[i].m1.Render(m_mat);
  426. #endif
  427. g_renderer->Clear(ClearMask::Depth);
  428. }
  429. }
  430. g_scene->GetCamera()->SetProjection(default_proj);
  431. }
  432. private:
  433. Controller *m_controller;
  434. Camera *m_camera;
  435. float m_angle;
  436. mat4 m_mat;
  437. //Mesh infos
  438. //Move damping
  439. vec2 m_mesh_rotate_damp;
  440. vec2 m_mesh_screen_move_damp;
  441. vec2 m_mesh_move_damp;
  442. //Move transform damping
  443. vec2 m_mesh_rotation_damp;
  444. vec2 m_mesh_screen_offset_damp;
  445. vec2 m_mesh_offset_damp;
  446. vec2 m_mesh_rotation; //Meshes rotation
  447. vec2 m_mesh_screen_offset;//Meshes screen offset
  448. vec2 m_mesh_offset; //Mesh Offset after first mesh (x: offset, y: scale)
  449. int m_mesh_shown;
  450. //File data
  451. String m_file_name;
  452. Array<String> m_cmdlist;
  453. float m_stream_update_time;
  454. float m_stream_update_timer;
  455. //misc datas
  456. Array<EasyMesh, bool, float, vec3> m_meshes;
  457. Array<Light *> m_lights;
  458. Shader * m_texture_shader;
  459. TileSet * m_default_texture;
  460. Texture * m_texture;
  461. ShaderUniform m_texture_uni;
  462. Image * m_image;
  463. float m_fov;
  464. float m_fov_damp;
  465. float m_fov_zoom_damp;
  466. mat4 m_fov_compensation;
  467. };
  468. //The basic main :
  469. int main(int argc, char **argv)
  470. {
  471. System::Init(argc, argv);
  472. Application app("MeshViewer", ivec2(1600, 600), 60.0f);
  473. if (argc > 1)
  474. new MeshViewer(argv[1]);
  475. else
  476. new MeshViewer();
  477. app.Run();
  478. return EXIT_SUCCESS;
  479. }