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.
 
 
 

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