source: trunk/orbital/orbital.cpp @ 1260

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

orbital: basic lighting in the mesh builder.

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    m_normalmat = transpose(inverse(mat3(m_modelview)));
57}
58
59void Orbital::TickDraw(float deltams)
60{
61    WorldEntity::TickDraw(deltams);
62
63    if (!m_ready)
64    {
65        m.MeshConvert();
66
67        /* FIXME: this object never cleans up */
68        m_ready = true;
69    }
70
71    m.Render(m_modelview, m_proj, m_normalmat);
72}
73
74Orbital::~Orbital()
75{
76    ;
77}
78
79int main(int argc, char **argv)
80{
81    Application app("Orbital", ivec2(800, 600), 60.0f);
82
83#if defined _MSC_VER && !defined _XBOX
84    _chdir("..");
85#elif defined _WIN32 && !defined _XBOX
86    _chdir("../..");
87#endif
88
89    new DebugFps(5, 5);
90    new Orbital();
91    app.ShowPointer(false);
92
93    app.Run();
94
95    return EXIT_SUCCESS;
96}
97
Note: See TracBrowser for help on using the repository browser.