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

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

core: fix the X360 build by re-adding macro barriers I removed.

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