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.

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