source: trunk/tutorial/05_easymesh.cpp @ 1598

Last change on this file since 1598 was 1598, checked in by sam, 9 years ago

tutorial: add a simple EasyMesh viewer.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
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
17using namespace std;
18using namespace lol;
19
20#if USE_SDL && defined __APPLE__
21#   include <SDL_main.h>
22#endif
23
24class EasyMeshTutorial : public WorldEntity
25{
26public:
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
70private:
71    float m_angle;
72    mat4 m_matrix;
73    EasyMesh m_mesh;
74    Camera *m_camera;
75
76    bool m_ready;
77};
78
79int 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
Note: See TracBrowser for help on using the repository browser.