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.
 
 
 

88 wiersze
1.9 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. #if USE_SDL && defined __APPLE__
  17. # include <SDL_main.h>
  18. #endif
  19. class EasyMeshTutorial : public WorldEntity
  20. {
  21. public:
  22. EasyMeshTutorial()
  23. {
  24. m_angle = 0;
  25. m_mesh.Compile("sc#e94 scb#964 [acg10 5 8 8 2 2 0.1 0]");
  26. m_camera = new Camera(vec3(0.f, 600.f, 0.f),
  27. vec3(0.f, 0.f, 0.f),
  28. vec3(0, 1, 0));
  29. m_camera->SetPerspective(70.f, 640.f, 480.f, .1f, 1000.f);
  30. m_camera->SetTarget(vec3(0.f));
  31. m_camera->SetPosition(vec3(-20.f, 20.f, 0.f));
  32. Ticker::Ref(m_camera);
  33. m_ready = false;
  34. }
  35. virtual void TickGame(float seconds)
  36. {
  37. WorldEntity::TickGame(seconds);
  38. m_angle += seconds * 45.0f;
  39. mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
  40. mat4 model = mat4::translate(vec3(0, 0, 0));
  41. m_matrix = model * anim;
  42. }
  43. virtual void TickDraw(float seconds)
  44. {
  45. WorldEntity::TickDraw(seconds);
  46. if (!m_ready)
  47. {
  48. m_mesh.MeshConvert();
  49. m_ready = true;
  50. }
  51. Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
  52. m_mesh.Render(m_matrix);
  53. }
  54. private:
  55. float m_angle;
  56. mat4 m_matrix;
  57. EasyMesh m_mesh;
  58. Camera *m_camera;
  59. bool m_ready;
  60. };
  61. int main(int argc, char **argv)
  62. {
  63. Application app("Tutorial 5: EasyMesh", ivec2(640, 480), 60.0f);
  64. new EasyMeshTutorial();
  65. app.Run();
  66. return EXIT_SUCCESS;
  67. }