source: trunk/orbital/orbital.cpp @ 1268

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

orbital: implement chamfer boxes and stars in the mesh builder.

File size: 2.0 KB
Line 
1//
2// Orbital
3//
4// Copyright: (c) 2012 Various People
5//
6
7#if defined HAVE_CONFIG_H
8#   include "config.h"
9#endif
10
11#if defined _WIN32
12#   include <direct.h>
13#endif
14
15#if USE_SDL && defined __APPLE__
16#   include <SDL_main.h>
17#endif
18
19#include "core.h"
20#include "loldebug.h"
21
22using namespace std;
23using namespace lol;
24
25#include "orbital.h"
26#include "mesh.h"
27
28Orbital::Orbital()
29{
30    m.SetCurColor(vec4(1.0, 1.0, 0.0, 1.0));
31    m.AppendSphere(vec3(1.0, 0.5, 1.0), 32);
32    m.Translate(vec3(0.0, -0.4, 0.0));
33    m.Flush();
34
35    m.SetCurColor(vec4(1.0, 0.0, 1.0, 1.0));
36    m.AppendSmoothChamfBox(vec3(0.5, 0.5, 0.5), 0.1);
37    m.RotateX(45.0);
38    m.RotateZ(45.0);
39    m.Translate(vec3(0.0, 0.6, 0.0));
40    m.Flush();
41
42    m.SetCurColor(vec4(0.0, 1.0, 0.5, 1.0));
43    m.SetCurColor2(vec4(0.0, 0.5, 1.0, 1.0));
44    m.AppendStar(5, 0.4, 0.7, 1, 1);
45    m.Flush();
46
47    m_angle = 0;
48
49    m_ready = false;
50}
51
52void Orbital::TickGame(float deltams)
53{
54    WorldEntity::TickGame(deltams);
55
56    m_angle += deltams / 1000.0f * 90.0f;
57
58    mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0))
59              * mat4::rotate(m_angle * 0.25, vec3(0, 0, 1));
60    mat4 model = mat4::translate(vec3(0, 0, -4.5));
61    mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0));
62    mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f);
63
64    m_modelview = view * model * anim;
65    m_proj = proj;
66    m_normalmat = transpose(inverse(mat3(m_modelview)));
67}
68
69void Orbital::TickDraw(float deltams)
70{
71    WorldEntity::TickDraw(deltams);
72
73    if (!m_ready)
74    {
75        m.MeshConvert();
76
77        /* FIXME: this object never cleans up */
78        m_ready = true;
79    }
80
81    m.Render(m_modelview, m_proj, m_normalmat);
82}
83
84Orbital::~Orbital()
85{
86    ;
87}
88
89int main(int argc, char **argv)
90{
91    Application app("Orbital", ivec2(800, 600), 60.0f);
92
93#if defined _MSC_VER && !defined _XBOX
94    _chdir("..");
95#elif defined _WIN32 && !defined _XBOX
96    _chdir("../..");
97#endif
98
99    new DebugFps(5, 5);
100    new Orbital();
101    app.ShowPointer(false);
102
103    app.Run();
104
105    return EXIT_SUCCESS;
106}
107
Note: See TracBrowser for help on using the repository browser.