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

Last change on this file since 1647 was 1647, checked in by sam, 8 years ago

build: hide the SDL_main.h inclusion in core.h, and only activate it
on Windows if using Visual Studio; if using MinGW, try to stick to the
original main() entry point.

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