source: trunk/orbital/orbital.cpp @ 1256

Last change on this file since 1256 was 1256, checked in by sam, 10 years ago

orbital: split model matrix into modelview and projection so that we
can start working on lighting.

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