Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

05_easymesh.cpp 4.5 KiB

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