source: trunk/orbital/orbital.cpp @ 1262

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

orbital: the mesh builder now supports spheres.

File size: 1.9 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.AppendBox(vec3(0.5, 0.5, 0.5));
37    m.RotateX(45.0);
38    m.RotateZ(45.0);
39    m.Translate(vec3(0.0, 0.4, 0.0));
40    m.Flush();
41
42    m_angle = 0;
43
44    m_ready = false;
45}
46
47void Orbital::TickGame(float deltams)
48{
49    WorldEntity::TickGame(deltams);
50
51    m_angle += deltams / 1000.0f * 90.0f;
52
53    mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0))
54              * mat4::rotate(m_angle * 0.25, vec3(0, 0, 1));
55    mat4 model = mat4::translate(vec3(0, 0, -4.5));
56    mat4 view = mat4::lookat(vec3(0, 2, 0), vec3(0, 0, -4), vec3(0, 1, 0));
57    mat4 proj = mat4::perspective(45.0f, 640.0f, 480.0f, 0.1f, 10.0f);
58
59    m_modelview = view * model * anim;
60    m_proj = proj;
61    m_normalmat = transpose(inverse(mat3(m_modelview)));
62}
63
64void Orbital::TickDraw(float deltams)
65{
66    WorldEntity::TickDraw(deltams);
67
68    if (!m_ready)
69    {
70        m.MeshConvert();
71
72        /* FIXME: this object never cleans up */
73        m_ready = true;
74    }
75
76    m.Render(m_modelview, m_proj, m_normalmat);
77}
78
79Orbital::~Orbital()
80{
81    ;
82}
83
84int main(int argc, char **argv)
85{
86    Application app("Orbital", ivec2(800, 600), 60.0f);
87
88#if defined _MSC_VER && !defined _XBOX
89    _chdir("..");
90#elif defined _WIN32 && !defined _XBOX
91    _chdir("../..");
92#endif
93
94    new DebugFps(5, 5);
95    new Orbital();
96    app.ShowPointer(false);
97
98    app.Run();
99
100    return EXIT_SUCCESS;
101}
102
Note: See TracBrowser for help on using the repository browser.