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.

meshviewer.cpp 20 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. #define R_M 1.f
  20. #define DEFAULT_WIDTH (770.f * R_M)
  21. #define DEFAULT_HEIGHT (200.f * R_M)
  22. #define WIDTH ((float)Video::GetSize().x)
  23. #define HEIGHT ((float)Video::GetSize().y)
  24. #define SCREEN_W (10.f / WIDTH)
  25. #define SCREEN_LIMIT 1.1f
  26. #define RATIO_HW (HEIGHT / WIDTH)
  27. #define RATIO_WH (WIDTH / HEIGHT)
  28. #define ROT_SPEED vec2(50.f)
  29. #define ROT_CLAMP 89.f
  30. #define POS_SPEED vec2(1.2f)
  31. #define POS_CLAMP 1.f
  32. #define FOV_SPEED 20.f
  33. #define FOV_CLAMP 120.f
  34. #define ZOM_SPEED 3.f
  35. #define ZOM_CLAMP 20.f
  36. #define HST_SPEED .5f
  37. #define HST_CLAMP 1.f
  38. #define WITH_TEXTURE 0
  39. #define EM_TEST (1 && EMSCRIPTEN)
  40. #define NO_NACL_EM (!__native_client__ && !EMSCRIPTEN)
  41. #define NACL_EM (__native_client__ || EMSCRIPTEN)
  42. LOLFX_RESOURCE_DECLARE(shinyfur);
  43. LOLFX_RESOURCE_DECLARE(shinymvtexture);
  44. enum
  45. {
  46. KEY_CAM_RESET,
  47. KEY_CAM_POS,
  48. KEY_CAM_FOV,
  49. KEY_CAM_UP,
  50. KEY_CAM_DOWN,
  51. KEY_CAM_LEFT,
  52. KEY_CAM_RIGHT,
  53. KEY_MESH_NEXT,
  54. KEY_MESH_PREV,
  55. KEY_F1,
  56. KEY_F2,
  57. KEY_F3,
  58. KEY_F4,
  59. KEY_F5,
  60. KEY_ESC,
  61. KEY_MAX,
  62. };
  63. enum MessageType
  64. {
  65. MSG_IN,
  66. MSG_OUT,
  67. MSG_MAX
  68. };
  69. LOLFX_RESOURCE_DECLARE(mviewer_em_test);
  70. class MVTestShaderData : public GpuShaderData
  71. {
  72. public:
  73. //-----------------------------------------------------------------------------
  74. MVTestShaderData()
  75. {
  76. m_render_mode = DebugRenderMode::Default;
  77. m_vert_decl_flags = (1 << VertexUsage::Position) | (1 << VertexUsage::Color);
  78. m_shader = Shader::Create(LOLFX_RESOURCE_NAME(mviewer_em_test));
  79. SetupDefaultData(false);
  80. }
  81. //-----------------------------------------------------------------------------
  82. void SetupDefaultData(bool with_UV)
  83. {
  84. AddUniform("in_ModelView");
  85. AddUniform("in_Proj");
  86. }
  87. //-----------------------------------------------------------------------------
  88. void SetupShaderDatas(mat4 const &model)
  89. {
  90. mat4 proj = g_scene->GetCamera()->GetProjection();
  91. mat4 view = g_scene->GetCamera()->GetView();
  92. m_shader->SetUniform(*GetUniform("in_ModelView"), view * model);
  93. m_shader->SetUniform(*GetUniform("in_Proj"), proj);
  94. }
  95. };
  96. class MeshViewer : public WorldEntity
  97. {
  98. public:
  99. MeshViewer(char const *file_name = "data/mesh-buffer.txt")
  100. : m_file_name(file_name)
  101. {
  102. m_init = false;
  103. }
  104. void Init()
  105. {
  106. m_init = true;
  107. #if NO_NACL_EM
  108. /* Register an input controller for the keyboard */
  109. m_controller = new Controller("Default", KEY_MAX, 0);
  110. //Camera keyboard rotation
  111. m_controller->GetKey(KEY_CAM_UP ).Bind("Keyboard", "Up");
  112. m_controller->GetKey(KEY_CAM_DOWN ).Bind("Keyboard", "Down");
  113. m_controller->GetKey(KEY_CAM_LEFT ).Bind("Keyboard", "Left");
  114. m_controller->GetKey(KEY_CAM_RIGHT).Bind("Keyboard", "Right");
  115. //Camera keyboard position switch
  116. m_controller->GetKey(KEY_CAM_POS ).Bind("Keyboard", "LeftShift");
  117. m_controller->GetKey(KEY_CAM_FOV ).Bind("Keyboard", "LeftCtrl");
  118. //Camera unzoom switch
  119. m_controller->GetKey(KEY_CAM_RESET).Bind("Keyboard", "Space");
  120. //Mesh change
  121. m_controller->GetKey(KEY_MESH_NEXT).Bind("Keyboard", "PageUp");
  122. m_controller->GetKey(KEY_MESH_PREV).Bind("Keyboard", "PageDown");
  123. //Base setup
  124. m_controller->GetKey(KEY_F1).Bind("Keyboard", "F1");
  125. m_controller->GetKey(KEY_F2).Bind("Keyboard", "F2");
  126. m_controller->GetKey(KEY_F3).Bind("Keyboard", "F3");
  127. m_controller->GetKey(KEY_F4).Bind("Keyboard", "F4");
  128. m_controller->GetKey(KEY_F5).Bind("Keyboard", "F5");
  129. m_controller->GetKey(KEY_ESC).Bind("Keyboard", "Escape");
  130. #endif //NO_NACL_EM
  131. // Message Service
  132. MessageService::Setup(MSG_MAX);
  133. // Mesh Setup
  134. m_render_max = vec2(-.9f, 6.1f);
  135. m_mesh_id = 0;
  136. m_mesh_id1 = 0.f;
  137. m_default_texture = NULL;
  138. //Camera Setup
  139. m_fov = -100.f;
  140. m_fov_mesh = 0.f;
  141. m_fov_speed = 0.f;
  142. m_zoom = -100.f;
  143. m_zoom_mesh = 0.f;
  144. m_zoom_speed = 0.f;
  145. m_rot = vec2(45.f);
  146. m_rot_mesh = vec2::zero;
  147. m_rot_speed = vec2::zero;
  148. m_pos = vec2::zero;
  149. m_pos_mesh = vec2::zero;
  150. m_pos_speed = vec2::zero;
  151. m_screen_offset = vec2::zero;
  152. m_hist_scale = vec2(.13f, .03f);
  153. m_hist_scale_mesh = vec2(.0f);
  154. m_hist_scale_speed = vec2(.0f);
  155. m_camera = new Camera();
  156. m_camera->SetView(vec3(0.f, 0.f, 10.f), vec3(0.f, 0.f, 0.f), vec3(0.f, 1.f, 0.f));
  157. m_camera->SetProjection(0.f, .0001f, 2000.f, WIDTH * SCREEN_W, RATIO_HW);
  158. m_camera->UseShift(true);
  159. g_scene->PushCamera(m_camera);
  160. //Lights setup
  161. m_lights << new Light();
  162. m_lights.Last()->SetPosition(vec4(4.f, -1.f, -4.f, 0.f));
  163. m_lights.Last()->SetColor(vec4(.0f, .2f, .5f, 1.f));
  164. Ticker::Ref(m_lights.Last());
  165. m_lights << new Light();
  166. m_lights.Last()->SetPosition(vec4(8.f, 2.f, 6.f, 0.f));
  167. m_lights.Last()->SetColor(vec4(1.f, 1.f, 1.f, 1.f));
  168. Ticker::Ref(m_lights.Last());
  169. //stream update
  170. m_stream_update_time = 2.0f;
  171. m_stream_update_timer = 1.0f;
  172. }
  173. ~MeshViewer()
  174. {
  175. if (m_camera)
  176. g_scene->PopCamera(m_camera);
  177. for (int i = 0; i < m_lights.Count(); ++i)
  178. Ticker::Unref(m_lights[i]);
  179. MessageService::Destroy();
  180. }
  181. virtual void TickGame(float seconds)
  182. {
  183. WorldEntity::TickGame(seconds);
  184. if (!m_init && g_scene)
  185. {
  186. Init();
  187. return;
  188. }
  189. if (!m_init)
  190. return;
  191. //TODO : This should probably be "standard LoL behaviour"
  192. #if NO_NACL_EM
  193. {
  194. //Shutdown logic
  195. if (m_controller->GetKey(KEY_ESC).IsReleased())
  196. Ticker::Shutdown();
  197. }
  198. #endif //NO_NACL_EM
  199. //Mesh Change
  200. #if NO_NACL_EM
  201. m_mesh_id = clamp(m_mesh_id + ((int)m_controller->GetKey(KEY_MESH_PREV).IsPressed() - (int)m_controller->GetKey(KEY_MESH_NEXT).IsPressed()), 0, m_meshes.Count() - 1);
  202. #endif //NO_NACL_EM
  203. m_mesh_id1 = damp(m_mesh_id1, (float)m_mesh_id, .2f, seconds);
  204. //Camera update
  205. bool is_pos = false;
  206. bool is_fov = false;
  207. bool is_hsc = false;
  208. vec2 tmp = vec2::zero;
  209. #if NO_NACL_EM
  210. is_pos = m_controller->GetKey(KEY_CAM_POS).IsDown();
  211. is_fov = m_controller->GetKey(KEY_CAM_FOV).IsDown();
  212. tmp = vec2((float)m_controller->GetKey(KEY_CAM_UP ).IsDown() - (float)m_controller->GetKey(KEY_CAM_DOWN).IsDown(),
  213. (float)m_controller->GetKey(KEY_CAM_RIGHT ).IsDown() - (float)m_controller->GetKey(KEY_CAM_LEFT).IsDown());
  214. #endif //NO_NACL_EM
  215. //Base data
  216. vec2 rot = (!is_pos && !is_fov)?(tmp):(vec2(.0f)); rot = vec2(rot.x, rot.y);
  217. vec2 pos = (is_pos && !is_fov)?(tmp):(vec2(.0f)); pos = -vec2(pos.y, pos.x);
  218. vec2 fov = (!is_pos && is_fov)?(tmp):(vec2(.0f)); fov = vec2(-fov.x, fov.y);
  219. vec2 hsc = vec2(0.f);
  220. //speed
  221. m_rot_speed = damp(m_rot_speed, rot * ROT_SPEED, .2f, seconds);
  222. float pos_factor = 1.f / (1.f + m_zoom_mesh * .5f);
  223. m_pos_speed = damp(m_pos_speed, pos * POS_SPEED * pos_factor, .2f, seconds);
  224. float fov_factor = 1.f + lol::pow((m_fov_mesh / FOV_CLAMP) * 1.f, 2.f);
  225. m_fov_speed = damp(m_fov_speed, fov.x * FOV_SPEED * fov_factor, .2f, seconds);
  226. float zom_factor = 1.f + lol::pow((m_zoom_mesh / ZOM_CLAMP) * 1.f, 2.f);
  227. m_zoom_speed = damp(m_zoom_speed, fov.y * ZOM_SPEED * zom_factor, .2f, seconds);
  228. m_hist_scale_speed = damp(m_hist_scale_speed, hsc * HST_SPEED, .2f, seconds);
  229. m_rot += m_rot_speed * seconds;
  230. #if NO_NACL_EM
  231. //Transform update
  232. if (!m_controller->GetKey(KEY_CAM_RESET).IsDown())
  233. {
  234. m_pos += m_pos_speed * seconds;
  235. m_fov += m_fov_speed * seconds;
  236. m_zoom += m_zoom_speed * seconds;
  237. m_hist_scale += m_hist_scale_speed * seconds;
  238. }
  239. #endif //NO_NACL_EM
  240. //clamp
  241. vec2 rot_mesh = vec2(SmoothClamp(m_rot.x, -ROT_CLAMP, ROT_CLAMP, ROT_CLAMP * .1f), m_rot.y);
  242. vec2 pos_mesh = vec2(SmoothClamp(m_pos.x, -POS_CLAMP, POS_CLAMP, POS_CLAMP * .1f),
  243. SmoothClamp(m_pos.y, -POS_CLAMP, POS_CLAMP, POS_CLAMP * .1f));
  244. float fov_mesh = SmoothClamp(m_fov, 0.f, FOV_CLAMP, FOV_CLAMP * .1f);
  245. float zoom_mesh = SmoothClamp(m_zoom, 0.f, ZOM_CLAMP, ZOM_CLAMP * .1f);
  246. vec2 hist_scale_mesh = vec2(SmoothClamp(m_hist_scale.x, 0.f, HST_CLAMP, HST_CLAMP * .1f),
  247. SmoothClamp(m_hist_scale.y, 0.f, HST_CLAMP, HST_CLAMP * .1f));
  248. #if NO_NACL_EM
  249. if (m_controller->GetKey(KEY_CAM_RESET).IsDown())
  250. {
  251. pos_mesh = vec2::zero;
  252. zoom_mesh = 0.f;
  253. }
  254. #endif //NO_NACL_EM
  255. m_rot_mesh = vec2(damp(m_rot_mesh.x, rot_mesh.x, .2f, seconds), damp(m_rot_mesh.y, rot_mesh.y, .2f, seconds));
  256. m_pos_mesh = vec2(damp(m_pos_mesh.x, pos_mesh.x, .2f, seconds), damp(m_pos_mesh.y, pos_mesh.y, .2f, seconds));
  257. m_fov_mesh = damp(m_fov_mesh, fov_mesh, .2f, seconds);
  258. m_zoom_mesh = damp(m_zoom_mesh, zoom_mesh, .2f, seconds);
  259. m_hist_scale_mesh = damp(m_hist_scale_mesh, hist_scale_mesh, .2f, seconds);
  260. //Mesh mat calculation
  261. m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f)));
  262. //Target List Setup
  263. Array<vec3> target_list;
  264. if (m_meshes.Count() && m_mesh_id >= 0)
  265. for (int i = 0; i < m_meshes[m_mesh_id]->GetVertexCount(); i++)
  266. target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id]->GetVertexLocation(i))).v3.xyz;
  267. //--
  268. //Update mesh screen location - Get the Min/Max needed
  269. //--
  270. vec2 cam_center(0.f);
  271. float cam_factor = .0f;
  272. vec3 local_min_max[2] = { vec3(FLT_MAX), vec3(-FLT_MAX) };
  273. vec2 screen_min_max[2] = { vec2(FLT_MAX), vec2(-FLT_MAX) };
  274. mat4 world_cam = m_camera->GetView();
  275. mat4 cam_screen = m_camera->GetProjection();
  276. //target on-screen computation
  277. for (int i = 0; i < target_list.Count(); i++)
  278. {
  279. vec3 obj_loc = target_list[i];
  280. {
  281. //Debug::DrawBox(obj_loc - vec3(4.f), obj_loc + vec3(4.f), vec4(1.f, 0.f, 0.f, 1.f));
  282. mat4 target_mx = mat4::translate(obj_loc);
  283. vec3 vpos;
  284. //Get location in cam coordinates
  285. target_mx = world_cam * target_mx;
  286. vpos = target_mx.v3.xyz;
  287. local_min_max[0] = min(vpos.xyz, local_min_max[0]);
  288. local_min_max[1] = max(vpos.xyz, local_min_max[1]);
  289. //Get location in screen coordinates
  290. target_mx = cam_screen * target_mx;
  291. vpos = (target_mx.v3 / target_mx.v3.w).xyz;
  292. screen_min_max[0] = min(screen_min_max[0], vpos.xy * vec2(RATIO_WH, 1.f));
  293. screen_min_max[1] = max(screen_min_max[1], vpos.xy * vec2(RATIO_WH, 1.f));
  294. //Build Barycenter
  295. cam_center += vpos.xy;
  296. cam_factor += 1.f;
  297. }
  298. }
  299. float screen_ratio = max(max(lol::abs(local_min_max[0].x), lol::abs(local_min_max[0].y)),
  300. max(lol::abs(local_min_max[1].x), lol::abs(local_min_max[1].y)));
  301. float scale_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)),
  302. max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y)));
  303. vec2 screen_offset = vec2(0.f, -(screen_min_max[1].y + screen_min_max[0].y) * .5f);
  304. m_screen_offset = damp(m_screen_offset, screen_offset, .9f, seconds);
  305. float z_pos = (inverse(world_cam) * mat4::translate(vec3(0.f, 0.f, max(local_min_max[0].z, local_min_max[1].z)))).v3.z;
  306. if (cam_factor > 0.f)
  307. {
  308. vec2 new_screen_scale = m_camera->GetScreenScale();
  309. m_camera->SetScreenScale(max(vec2(0.001f), new_screen_scale * ((1.0f + m_zoom_mesh) / (scale_ratio * SCREEN_LIMIT))));
  310. m_camera->m_position.z = damp(m_camera->m_position.z, z_pos + screen_ratio * 2.f, .1f, seconds);
  311. m_camera->SetFov(m_fov_mesh);
  312. m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio), 1.2f, seconds));
  313. }
  314. //--
  315. //Message Service
  316. //--
  317. String mesh("");
  318. int u = 4;
  319. while (u-- > 0 && MessageService::FetchFirst(MSG_IN, mesh))
  320. {
  321. int o = 1;
  322. while (o-- > 0)
  323. {
  324. if (m_mesh_id == m_meshes.Count() - 1)
  325. m_mesh_id++;
  326. //Create a new mesh
  327. EasyMesh* em = new EasyMesh();
  328. if (em->Compile(mesh.C()))
  329. m_meshes.Push(em);
  330. else
  331. delete(em);
  332. }
  333. }
  334. #if NACL_EM
  335. if (m_stream_update_time > .0f)
  336. {
  337. m_stream_update_time = -1.f;
  338. MessageService::Send(MSG_IN, "[sc#f8f ab 1]");
  339. // MessageService::Send(MSG_IN, "[sc#f8f ab 1 splt 4 twy 90]");
  340. // MessageService::Send(MSG_IN, "[sc#8ff afcb 1 1 1 0]");
  341. // MessageService::Send(MSG_IN, "[sc#ff8 afcb 1 1 1 0]");
  342. }
  343. #elif WIN32
  344. //--
  345. //File management
  346. //--
  347. m_stream_update_time += seconds;
  348. if (m_stream_update_time > m_stream_update_timer)
  349. {
  350. m_stream_update_time = 0.f;
  351. File f;
  352. f.Open(m_file_name.C(), FileAccess::Read);
  353. String cmd = f.ReadString();
  354. f.Close();
  355. /*
  356. for (int i = 0; i < cmd.Count() - 1; i++)
  357. {
  358. if (cmd[i] == '/' && cmd[i + 1] == '/')
  359. {
  360. int j = i;
  361. for (; j < cmd.Count(); j++)
  362. {
  363. if (cmd[j] == '\r' || cmd[j] == '\n')
  364. break;
  365. }
  366. String new_cmd = cmd.Sub(0, i);
  367. if (j < cmd.Count())
  368. new_cmd += cmd.Sub(j, cmd.Count() - j);
  369. cmd = new_cmd;
  370. i--;
  371. }
  372. }
  373. */
  374. if (cmd.Count()
  375. && (!m_cmdlist.Count() || cmd != m_cmdlist.Last()))
  376. {
  377. m_cmdlist << cmd;
  378. MessageService::Send(MSG_IN, cmd);
  379. }
  380. }
  381. #endif //WINDOWS
  382. }
  383. virtual void TickDraw(float seconds)
  384. {
  385. WorldEntity::TickDraw(seconds);
  386. if (!m_init)
  387. return;
  388. //TODO : This should probably be "standard LoL behaviour"
  389. #if NO_NACL_EM
  390. {
  391. if (m_controller->GetKey(KEY_F1).IsReleased())
  392. Video::SetDebugRenderMode(DebugRenderMode::Default);
  393. if (m_controller->GetKey(KEY_F2).IsReleased())
  394. Video::SetDebugRenderMode(DebugRenderMode::Wireframe);
  395. if (m_controller->GetKey(KEY_F3).IsReleased())
  396. Video::SetDebugRenderMode(DebugRenderMode::Lighting);
  397. if (m_controller->GetKey(KEY_F4).IsReleased())
  398. Video::SetDebugRenderMode(DebugRenderMode::Normal);
  399. if (m_controller->GetKey(KEY_F5).IsReleased())
  400. Video::SetDebugRenderMode(DebugRenderMode::UV);
  401. }
  402. #endif //NO_NACL_EM
  403. #if NO_NACL_EM
  404. if (!m_default_texture)
  405. {
  406. m_texture_shader = Shader::Create(LOLFX_RESOURCE_NAME(shinymvtexture));
  407. m_texture_uni = m_texture_shader->GetUniformLocation("u_Texture");
  408. m_default_texture = Tiler::Register("data/test-texture.png", ivec2::zero, ivec2(0,1));
  409. }
  410. else if (m_texture && m_default_texture)
  411. m_texture_shader->SetUniform(m_texture_uni, m_default_texture->GetTexture(), 0);
  412. #endif //NO_NACL_EM
  413. g_renderer->SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  414. vec3 x = vec3(1.f,0.f,0.f);
  415. vec3 y = vec3(0.f,1.f,0.f);
  416. for (int i = 0; i < m_meshes.Count(); i++)
  417. {
  418. {
  419. if (m_meshes[i]->GetMeshState() == MeshRender::NeedConvert)
  420. {
  421. #if EM_TEST
  422. m_meshes[i]->MeshConvert(new MVTestShaderData());
  423. #elif WITH_TEXTURE
  424. m_meshes[i]->MeshConvert(new DefaultShaderData(((1 << VertexUsage::Position) | (1 << VertexUsage::Normal) |
  425. (1 << VertexUsage::Color) | (1 << VertexUsage::TexCoord)),
  426. m_texture_shader, true));
  427. #else
  428. m_meshes[i]->MeshConvert();
  429. #endif //WITH_TEXTURE
  430. }
  431. mat4 save_proj = m_camera->GetProjection();
  432. float j = -(float)(m_meshes.Count() - (i + 1)) + (-m_mesh_id1 + (float)(m_meshes.Count() - 1));
  433. if (m_mesh_id1 - m_render_max[0] > (float)i && m_mesh_id1 - m_render_max[1] < (float)i &&
  434. m_meshes[i]->GetMeshState() > MeshRender::NeedConvert)
  435. {
  436. float a_j = lol::abs(j);
  437. float i_trans = (a_j * a_j * m_hist_scale_mesh.x + a_j * m_hist_scale_mesh.x) * .5f;
  438. float i_scale = clamp(1.f - (m_hist_scale_mesh.y * (m_mesh_id1 - (float)i)), 0.f, 1.f);
  439. mat4 new_proj =
  440. //Y object Offset
  441. mat4::translate(x * m_screen_offset.x + y * m_screen_offset.y) *
  442. //Mesh Pos Offset
  443. mat4::translate((x * m_pos_mesh.x * RATIO_HW + y * m_pos_mesh.y) * 2.f * (1.f + .5f * m_zoom_mesh / SCREEN_LIMIT)) *
  444. //Mesh count offset
  445. mat4::translate(x * RATIO_HW * 2.f * (j + i_trans)) *
  446. //Align right meshes
  447. mat4::translate(x - x * RATIO_HW) *
  448. //Mesh count scale
  449. mat4::scale(vec3(vec2(i_scale), 1.f)) *
  450. //Camera projection
  451. save_proj;
  452. m_camera->SetProjection(new_proj);
  453. //#if NO_NACL_EM
  454. m_meshes[i]->Render(m_mat);
  455. //#endif //NO_NACL_EM
  456. g_renderer->Clear(ClearMask::Depth);
  457. }
  458. m_camera->SetProjection(save_proj);
  459. }
  460. }
  461. }
  462. private:
  463. Array<Light *> m_lights;
  464. Controller *m_controller;
  465. mat4 m_mat;
  466. bool m_init;
  467. //Camera Setup
  468. Camera *m_camera;
  469. float m_fov;
  470. float m_fov_mesh;
  471. float m_fov_speed;
  472. float m_zoom;
  473. float m_zoom_mesh;
  474. float m_zoom_speed;
  475. vec2 m_rot;
  476. vec2 m_rot_mesh;
  477. vec2 m_rot_speed;
  478. vec2 m_pos;
  479. vec2 m_pos_mesh;
  480. vec2 m_pos_speed;
  481. vec2 m_hist_scale;
  482. vec2 m_hist_scale_mesh;
  483. vec2 m_hist_scale_speed;
  484. vec2 m_screen_offset;
  485. //Mesh infos
  486. vec2 m_render_max;
  487. int m_mesh_id;
  488. float m_mesh_id1;
  489. Array<EasyMesh*> m_meshes;
  490. //File data
  491. String m_file_name;
  492. Array<String> m_cmdlist;
  493. float m_stream_update_time;
  494. float m_stream_update_timer;
  495. Shader * m_test_shader;
  496. //misc datas
  497. Shader * m_texture_shader;
  498. TileSet * m_default_texture;
  499. Texture * m_texture;
  500. ShaderUniform m_texture_uni;
  501. Image * m_image;
  502. };
  503. //The basic main :
  504. int main(int argc, char **argv)
  505. {
  506. System::Init(argc, argv);
  507. Application app("MeshViewer", ivec2((int)DEFAULT_WIDTH, (int)DEFAULT_HEIGHT), 60.0f);
  508. if (argc > 1)
  509. new MeshViewer(argv[1]);
  510. else
  511. new MeshViewer();
  512. app.Run();
  513. return EXIT_SUCCESS;
  514. }