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

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

easymesh: add the capsule mesh.

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