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.
 
 
 

116 lines
3.6 KiB

  1. //
  2. // Lol Engine - EasyMesh tutorial
  3. //
  4. // Copyright: (c) 2011-2012 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include "core.h"
  14. using namespace std;
  15. using namespace lol;
  16. class EasyMeshTutorial : public WorldEntity
  17. {
  18. public:
  19. EasyMeshTutorial()
  20. {
  21. m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f);
  22. m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f);
  23. m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
  24. m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
  25. m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
  26. m_gears[0].m1.Compile("sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0 s .1 .1 .1");
  27. m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0 s .1 .1 .1");
  28. m_gears[2].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0 s .1 .1 .1");
  29. m_gears[3].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0 s .1 .1 .1");
  30. m_gears[4].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0 s .1 .1 .1");
  31. m_angle = 0;
  32. m_camera = new Camera(vec3(0.f, 600.f, 0.f),
  33. vec3(0.f, 0.f, 0.f),
  34. vec3(0, 1, 0));
  35. m_camera->SetPerspective(70.f, 960.f, 600.f, .1f, 1000.f);
  36. m_camera->SetTarget(vec3(0.f, -1.f, 0.f));
  37. m_camera->SetPosition(vec3(-15.f, 10.f, 0.f));
  38. Ticker::Ref(m_camera);
  39. m_ready = false;
  40. }
  41. ~EasyMeshTutorial()
  42. {
  43. Ticker::Unref(m_camera);
  44. }
  45. virtual void TickGame(float seconds)
  46. {
  47. WorldEntity::TickGame(seconds);
  48. m_angle += seconds * 70.0f;
  49. m_mat = mat4::rotate(10.0f, vec3(0, 0, 1))
  50. * mat4::rotate(m_angle, vec3(0, 1, 0));
  51. m_gears[0].m3 += seconds * 150.0f;
  52. m_gears[1].m3 += seconds * 150.0f * -2 / 9;
  53. m_gears[2].m3 += seconds * 150.0f * -2 / 3;
  54. m_gears[3].m3 += seconds * 150.0f * -2 / 3;
  55. m_gears[4].m3 += seconds * 150.0f * -2 / 3;
  56. m_gears[0].m2 = mat4::translate(vec3(0, 0, 0))
  57. * mat4::rotate(m_gears[0].m3, vec3(0, 1, 0));
  58. m_gears[1].m2 = mat4::translate(vec3(0, 0, 0))
  59. * mat4::rotate(m_gears[1].m3, vec3(0, 1, 0));
  60. m_gears[2].m2 = mat4::translate(vec3(0, 0, 5.5f))
  61. * mat4::rotate(m_gears[2].m3, vec3(0, 1, 0));
  62. m_gears[3].m2 = mat4::translate(vec3(5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f))
  63. * mat4::rotate(m_gears[3].m3, vec3(0, 1, 0));
  64. m_gears[4].m2 = mat4::translate(vec3(-5.5f * lol::sqrt(3.f) * 0.5f, 0, -5.5f * 0.5f))
  65. * mat4::rotate(m_gears[4].m3, vec3(0, 1, 0));
  66. }
  67. virtual void TickDraw(float seconds)
  68. {
  69. WorldEntity::TickDraw(seconds);
  70. if (!m_ready)
  71. {
  72. for (int i = 0; i < m_gears.Count(); i++)
  73. m_gears[i].m1.MeshConvert();
  74. m_ready = true;
  75. }
  76. Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  77. for (int i = 0; i < m_gears.Count(); i++)
  78. m_gears[i].m1.Render(m_mat * m_gears[i].m2);
  79. }
  80. private:
  81. Array<EasyMesh, mat4, float> m_gears;
  82. float m_angle;
  83. mat4 m_mat;
  84. Camera *m_camera;
  85. bool m_ready;
  86. };
  87. int main(int argc, char **argv)
  88. {
  89. Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f);
  90. new EasyMeshTutorial();
  91. app.Run();
  92. return EXIT_SUCCESS;
  93. }