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