25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

05_easymesh.cpp 4.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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#8d3 [ato40 10 40 rx20 ry130 tx30]");
  41. m_mesh.OpenBrace();
  42. m_mesh.Compile("sc#800 [asph10 25 25 25]");
  43. m_mesh.Compile("ty50");
  44. m_mesh.RadialJitter(0.2f);
  45. m_mesh.Compile("ty-50 tx-40");
  46. m_mesh.CloseBrace();
  47. #if 0
  48. //m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx-6 tz-9]");
  49. //m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx-6 tz9]");
  50. m_mesh.Compile("sc#1c1 scb#1c1");
  51. AddPiece(16, 16, 1, -8, -8, -4);
  52. /* Flat white LOL */
  53. m_mesh.Compile("sc#ccc scb#ccc");
  54. AddPiece(1, 4, 1, -7, -7, -3);
  55. AddPiece(2, 1, 1, -6, -4, -3);
  56. AddPiece(1, 4, 1, -3, -7, -3);
  57. AddPiece(2, 1, 1, -2, -7, -3);
  58. AddPiece(2, 1, 1, -2, -4, -3);
  59. AddPiece(1, 2, 1, -1, -6, -3);
  60. AddPiece(1, 4, 1, 1, -7, -3);
  61. AddPiece(2, 1, 1, 2, -4, -3);
  62. /* High red LOL */
  63. m_mesh.Compile("sc#e33 scb#e33");
  64. AddPiece(3, 1, 3, 3, 4, -3);
  65. AddPiece(1, 1, 3, 5, 4, 0);
  66. AddPiece(1, 1, 3, 5, 4, 3);
  67. AddPiece(1, 1, 3, 5, 4, 6);
  68. AddPiece(3, 1, 3, -1, 4, -3);
  69. AddPiece(1, 1, 3, 1, 4, 0);
  70. AddPiece(1, 1, 3, 1, 4, 3);
  71. AddPiece(1, 1, 3, -1, 4, 0);
  72. AddPiece(1, 1, 3, -1, 4, 3);
  73. AddPiece(3, 1, 3, -1, 4, 6);
  74. AddPiece(3, 1, 3, -5, 4, -3);
  75. AddPiece(1, 1, 3, -3, 4, 0);
  76. AddPiece(1, 1, 3, -3, 4, 3);
  77. AddPiece(1, 1, 3, -3, 4, 6);
  78. /* Some random crap */
  79. m_mesh.Compile("sc#e0e scb#e0e");
  80. AddPiece(1, 1, 1, -1, 0, 2);
  81. m_mesh.Compile("sc#0ee scb#0ee");
  82. AddPiece(2, 1, 1, -1, 0, 1);
  83. m_mesh.Compile("sc#e94 scb#e94");
  84. AddPiece(1, 1, 1, 0, 0, 0);
  85. m_mesh.Compile("sc#94e scb#94e");
  86. AddPiece(2, 1, 1, 0, 0, -1);
  87. m_mesh.Compile("sc#9e4 scb#9e4");
  88. AddPiece(1, 2, 3, -1, -1, -2);
  89. m_mesh.Compile("sc#49e scb#49e");
  90. AddPiece(2, 3, 1, 0, -1, -2);
  91. m_mesh.Compile("sc#4e9 scb#4e9");
  92. AddPiece(6, 2, 1, -2, 0, -3);
  93. m_mesh.Compile("sc#e49 scb#e49");
  94. AddPiece(6, 2, 1, -2, -2, -3);
  95. #endif
  96. /* Center everything -- is it needed? */
  97. // m_mesh.Compile("tx4 tz4");
  98. m_camera = new Camera(vec3(0.f, 600.f, 0.f),
  99. vec3(0.f, 0.f, 0.f),
  100. vec3(0, 1, 0));
  101. m_camera->SetPerspective(70.f, 960.f, 600.f, .1f, 1000.f);
  102. m_camera->SetTarget(vec3(0.f, -10.f, 0.f));
  103. m_camera->SetPosition(vec3(-100.f, 60.f, 0.f));
  104. Ticker::Ref(m_camera);
  105. m_ready = false;
  106. }
  107. virtual void TickGame(float seconds)
  108. {
  109. WorldEntity::TickGame(seconds);
  110. m_angle += seconds * 45.0f;
  111. mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
  112. mat4 model = mat4::translate(vec3(0, 0, 0));
  113. m_matrix = model * anim;
  114. }
  115. virtual void TickDraw(float seconds)
  116. {
  117. WorldEntity::TickDraw(seconds);
  118. if (!m_ready)
  119. {
  120. m_mesh.MeshConvert();
  121. m_ready = true;
  122. }
  123. Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  124. m_mesh.Render(m_matrix);
  125. }
  126. private:
  127. float m_angle;
  128. mat4 m_matrix;
  129. EasyMesh m_mesh;
  130. Camera *m_camera;
  131. bool m_ready;
  132. };
  133. int main(int argc, char **argv)
  134. {
  135. Application app("Tutorial 5: EasyMesh", ivec2(960, 600), 60.0f);
  136. new EasyMeshTutorial();
  137. app.Run();
  138. return EXIT_SUCCESS;
  139. }