您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

86 行
2.0 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. EasyMeshTutorial()
  20. {
  21. m_angle = 0;
  22. m_mesh.Compile("sc#e94 scb#964 [asph11 7 7 7 tx10]");
  23. m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx-6 tz-9]");
  24. m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx-6 tz9]");
  25. m_camera = new Camera(vec3(0.f, 600.f, 0.f),
  26. vec3(0.f, 0.f, 0.f),
  27. vec3(0, 1, 0));
  28. m_camera->SetPerspective(70.f, 640.f, 480.f, .1f, 1000.f);
  29. m_camera->SetTarget(vec3(0.f, -5.f, 0.f));
  30. m_camera->SetPosition(vec3(-20.f, 20.f, 0.f));
  31. Ticker::Ref(m_camera);
  32. m_ready = false;
  33. }
  34. virtual void TickGame(float seconds)
  35. {
  36. WorldEntity::TickGame(seconds);
  37. m_angle += seconds * 45.0f;
  38. mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
  39. mat4 model = mat4::translate(vec3(0, 0, 0));
  40. m_matrix = model * anim;
  41. }
  42. virtual void TickDraw(float seconds)
  43. {
  44. WorldEntity::TickDraw(seconds);
  45. if (!m_ready)
  46. {
  47. m_mesh.MeshConvert();
  48. m_ready = true;
  49. }
  50. Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  51. m_mesh.Render(m_matrix);
  52. }
  53. private:
  54. float m_angle;
  55. mat4 m_matrix;
  56. EasyMesh m_mesh;
  57. Camera *m_camera;
  58. bool m_ready;
  59. };
  60. int main(int argc, char **argv)
  61. {
  62. Application app("Tutorial 5: EasyMesh", ivec2(640, 480), 60.0f);
  63. new EasyMeshTutorial();
  64. app.Run();
  65. return EXIT_SUCCESS;
  66. }