You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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