source: trunk/orbital/orbital.cpp @ 1301

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

orbital: create a Camera class where we will hide the complexity.

File size: 3.4 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#include "particlesystem.h"
28#include "camera.h"
29
30Orbital::Orbital()
31{
32    m.SendCommand("sc1,1,0,1,asph10,16,20,24");
33    m.SendCommand("t0,0,-60,fl");
34
35    m.SendCommand("sc1,0,1,1,afcb10,10,10,2,rx45,rz45");
36    m.SendCommand("t-20,-20,0,fl");
37
38    m.SendCommand("sc0,0,0.3,1,afcb30,30,30,5,ry45,rx45,afcb30,30,30,5");
39    m.SendCommand("t40,40,0,fl");
40
41    m.SendCommand("sc1,1,0,1,scb1,0,0,0,at4,1,s1.5,1,4,tz-13,ad6,5.8,1");
42    m.SendCommand("t-40,-40,0,fl");
43
44    m.SendCommand("sc0.6,0.7,0.8,1,afcb7,4,7,0.6,sc1,0,0.3,1,afcb4,7,4,0.6");
45    m.SendCommand("t-40,20,-30,fl");
46
47    m.SendCommand("sc1,0.7,0,1,afcb12,3,10,0.4,tz3,sc1,1,1,1,afcb2,10,10,0.4");
48    m.SendCommand("rx20,ry30,t0,40,-20,fl");
49
50    m.SendCommand("sc0.1,0.1,0,1,ab6,6,15,ty-2,sc1,1,1,1,afcb4,5,16,0.4,tx4,tx60,mx,tx120,fl,sc0.2,0.7,0,1,afcb8,7,10,0.4,tz-4,tx60,fl");
51    m.SendCommand("sc0.2,0.7,0,1,afcb3,6,10,0.4,tx-8,afcb3,6,10,0.4,tx4,ty10,tx60,fl,sc1,1,1,1,afcb3,6,10,0.4,rx-30,ty10,tx60,fl");
52
53    m.SendCommand("sc1,1,1,1,scb0,0,0,1,aq8,1,sx0.25,tx-3,sc1,0,0,1,scb0,0,0,1,aq8,1,tx4,sz50,sx0.3,tz-200,mx,as10,12,8,1,1,ty60,fl");
54
55    m.SendCommand("sc1,.5,0,1");
56    m.SendCommand("afcb5,1,3,0.6,fl,sc1,1,1,1,afcb1,5,3,0.6,tz-1,irb");
57    m.SendCommand("sc1,.5,0,1");
58    m.SendCommand("afcb3,6,7,.4,t0,0,7,sc1,1,1,1,afcb3,4,4,.4,t4,0,-4,mx,fl");
59    m.SendCommand("sc1,.5,0,1");
60    m.SendCommand("afcb3,6,5,.4,sc1,1,1,1,afcb2,3,9,.4,fl");
61    m.SendCommand("scb1,1,1,1,ac4,15,.2,.6,1,1,tz-2,ac4,15,.2,.6,1,1,rx90,t0,-2,-7,fl");
62
63    m.SendCommand("sc0,1,1,scb0,0,0,1,ac5,15,0,1.5,0,1,ac7,35,1.1,4,0,1,rx90,t-3,0,27,mx");
64
65    m_particlesystem = new ParticleSystem();
66    m_camera = new Camera(vec3(0, 0, -4),
67                          vec3(0, 1, 0),
68                          vec3(0, 2, 0));
69
70    m_angle = 0;
71
72    m_ready = false;
73
74    Ticker::Ref(m_particlesystem);
75    Ticker::Ref(m_camera);
76}
77
78void Orbital::TickGame(float deltams)
79{
80    WorldEntity::TickGame(deltams);
81
82    m_angle += deltams / 1000.0f * 90.0f;
83
84    mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0))
85              * mat4::rotate(m_angle * 0.25f, vec3(0, 0, 1));
86    mat4 model = mat4::translate(vec3(0, 0, -4.5))
87               * mat4::scale(vec3(0.025));
88
89    m_modelview = m_camera->GetViewMatrix() * model * anim;
90    m_proj = m_camera->GetProjMatrix();
91    m_normalmat = transpose(inverse(mat3(m_modelview)));
92}
93
94void Orbital::TickDraw(float deltams)
95{
96    WorldEntity::TickDraw(deltams);
97
98    if (!m_ready)
99    {
100        m.SendCommand("irb");
101
102        /* FIXME: this object never cleans up */
103        m_ready = true;
104    }
105
106    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
107
108    m.Render(m_modelview, m_proj, m_normalmat);
109}
110
111Orbital::~Orbital()
112{
113    Ticker::Unref(m_particlesystem);
114    Ticker::Unref(m_camera);
115}
116
117int main(int argc, char **argv)
118{
119    Application app("Orbital", ivec2(800, 600), 60.0f);
120
121#if defined _MSC_VER && !defined _XBOX
122    _chdir("..");
123#elif defined _WIN32 && !defined _XBOX
124    _chdir("../..");
125#endif
126
127    new DebugFps(5, 5);
128    new Orbital();
129    app.ShowPointer(false);
130
131    app.Run();
132
133    return EXIT_SUCCESS;
134}
135
Note: See TracBrowser for help on using the repository browser.