Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

162 wiersze
4.5 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://sam.zoy.org/projects/COPYING.WTFPL 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. void AddPiece(int x, int y, int h, int dx, int dy, int dh)
  20. {
  21. m_mesh.OpenBrace();
  22. for (int j = 0; j < y; ++j)
  23. for (int i = 0; i < x; ++i)
  24. {
  25. m_mesh.OpenBrace();
  26. m_mesh.Compile("ad12,2.2,0 ty.1 ac12,.2,2.4,2.2,0,1 ty.8 ac12,1.7,2.4,2.4,0,1 ty2.5");
  27. m_mesh.Translate(vec3(i * 8.f, (h - 1) * 3.2f, j * 8.f));
  28. m_mesh.CloseBrace();
  29. }
  30. m_mesh.OpenBrace();
  31. m_mesh.AppendFlatChamfBox(vec3(x * 8.f, h * 3.2f, y * 8.f), -.1f);
  32. m_mesh.Translate(vec3((x - 1) * 4.f, (h - 1) * 1.6f, (y - 1) * 4.f));
  33. m_mesh.CloseBrace();
  34. m_mesh.Translate(vec3(dx * 8.f, dh * 3.2f, dy * 8.f));
  35. m_mesh.CloseBrace();
  36. }
  37. EasyMeshTutorial()
  38. {
  39. m_angle = 0;
  40. //m_mesh.Compile("sc#e94 scb#964 [asph11 7 7 7 tx10]");
  41. //m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx-6 tz-9]");
  42. //m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx-6 tz9]");
  43. m_mesh.Compile("sc#1c1 scb#1c1");
  44. AddPiece(16, 16, 1, -8, -8, -4);
  45. /* Flat white LOL */
  46. m_mesh.Compile("sc#ccc scb#ccc");
  47. AddPiece(1, 4, 1, -7, -7, -3);
  48. AddPiece(2, 1, 1, -6, -4, -3);
  49. AddPiece(1, 4, 1, -3, -7, -3);
  50. AddPiece(2, 1, 1, -2, -7, -3);
  51. AddPiece(2, 1, 1, -2, -4, -3);
  52. AddPiece(1, 2, 1, -1, -6, -3);
  53. AddPiece(1, 4, 1, 1, -7, -3);
  54. AddPiece(2, 1, 1, 2, -4, -3);
  55. /* High red LOL */
  56. m_mesh.Compile("sc#e33 scb#e33");
  57. AddPiece(3, 1, 3, 3, 4, -3);
  58. AddPiece(1, 1, 3, 5, 4, 0);
  59. AddPiece(1, 1, 3, 5, 4, 3);
  60. AddPiece(1, 1, 3, 5, 4, 6);
  61. AddPiece(3, 1, 3, -1, 4, -3);
  62. AddPiece(1, 1, 3, 1, 4, 0);
  63. AddPiece(1, 1, 3, 1, 4, 3);
  64. AddPiece(1, 1, 3, -1, 4, 0);
  65. AddPiece(1, 1, 3, -1, 4, 3);
  66. AddPiece(3, 1, 3, -1, 4, 6);
  67. AddPiece(3, 1, 3, -5, 4, -3);
  68. AddPiece(1, 1, 3, -3, 4, 0);
  69. AddPiece(1, 1, 3, -3, 4, 3);
  70. AddPiece(1, 1, 3, -3, 4, 6);
  71. /* Some random crap */
  72. m_mesh.Compile("sc#e0e scb#e0e");
  73. AddPiece(1, 1, 1, -1, 0, 2);
  74. m_mesh.Compile("sc#0ee scb#0ee");
  75. AddPiece(2, 1, 1, -1, 0, 1);
  76. m_mesh.Compile("sc#e94 scb#e94");
  77. AddPiece(1, 1, 1, 0, 0, 0);
  78. m_mesh.Compile("sc#94e scb#94e");
  79. AddPiece(2, 1, 1, 0, 0, -1);
  80. m_mesh.Compile("sc#9e4 scb#9e4");
  81. AddPiece(1, 2, 3, -1, -1, -2);
  82. m_mesh.Compile("sc#49e scb#49e");
  83. AddPiece(2, 3, 1, 0, -1, -2);
  84. m_mesh.Compile("sc#4e9 scb#4e9");
  85. AddPiece(6, 2, 1, -2, 0, -3);
  86. m_mesh.Compile("sc#e49 scb#e49");
  87. AddPiece(6, 2, 1, -2, -2, -3);
  88. /* Center everything -- is it needed? */
  89. m_mesh.Compile("tx4 tz4");
  90. m_camera = new Camera(vec3(0.f, 600.f, 0.f),
  91. vec3(0.f, 0.f, 0.f),
  92. vec3(0, 1, 0));
  93. m_camera->SetPerspective(70.f, 960.f, 600.f, .1f, 1000.f);
  94. m_camera->SetTarget(vec3(0.f, -10.f, 0.f));
  95. m_camera->SetPosition(vec3(-100.f, 60.f, 0.f));
  96. Ticker::Ref(m_camera);
  97. m_ready = false;
  98. }
  99. virtual void TickGame(float seconds)
  100. {
  101. WorldEntity::TickGame(seconds);
  102. m_angle += seconds * 45.0f;
  103. mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
  104. mat4 model = mat4::translate(vec3(0, 0, 0));
  105. m_matrix = model * anim;
  106. }
  107. virtual void TickDraw(float seconds)
  108. {
  109. WorldEntity::TickDraw(seconds);
  110. if (!m_ready)
  111. {
  112. m_mesh.MeshConvert();
  113. m_ready = true;
  114. }
  115. Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  116. m_mesh.Render(m_matrix);
  117. }
  118. private:
  119. float m_angle;
  120. mat4 m_matrix;
  121. EasyMesh m_mesh;
  122. Camera *m_camera;
  123. bool m_ready;
  124. };
  125. int main(int argc, char **argv)
  126. {
  127. Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f);
  128. new EasyMeshTutorial();
  129. app.Run();
  130. return EXIT_SUCCESS;
  131. }