source: trunk/orbital/orbital.cpp @ 1338

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

orbital: rewrite the shader once again.

File size: 5.3 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
27Orbital::Orbital()
28{
29    for (int j = 0; j < 20; j++)
30    {
31        for (int i = 0; i < 20; i++)
32        {
33            m.SendCommand(((i + j) % 2) ? "sc.2,.6,.7,1,scb.2,.6,.7,1"
34                                        : "sc.2,.2,.6,1,scb.2,.2,.6,1");
35            m.SendCommand("ac4,2,44,40,0,0,ty-1,ad4,40,0,ry45");
36            m.Scale(vec3(std::sqrt(0.5f)));
37            m.Translate(vec3(i * 44 - 440, 0, j * 44 - 440));
38            m.Flush();
39        }
40    }
41
42    /* Yellow sphere */
43    m.SendCommand("sc1,1,0,1,asph10,30,20,24");
44    m.SendCommand("t0,0,60,fl");
45
46    /* Pink box */
47    m.SendCommand("sc1,0,1,1,afcb10,10,10,1,rx45,rz45");
48    m.SendCommand("t-20,20,0,fl");
49
50    /* Large meteor */
51    m.SendCommand("sc0,0,0.3,1,afcb30,30,30,5,ry45,rx45,afcb30,30,30,5");
52    m.SendCommand("t40,40,0,fl");
53
54    /* Grey/red bonus */
55    m.SendCommand("sc0.6,0.7,0.8,1,afcb7,4,7,0.6,sc1,0,0.3,1,afcb4,7,4,0.6");
56    m.SendCommand("t-40,20,-30,fl");
57
58    /* Orange/white alien */
59    m.SendCommand("sc1,0.7,0,1,afcb12,3,10,0.4,tz3,sc1,1,1,1,afcb2,10,10,0.4");
60    m.SendCommand("rx20,ry30,t0,40,-20,fl");
61
62    /* Orange player ship */
63    m.SendCommand("sc1,.5,0,1");
64    m.SendCommand("afcb5,1,3,0.6,fl,sc1,1,1,1,afcb1,5,3,0.6,tz-1,irb");
65    m.SendCommand("sc1,.5,0,1");
66    m.SendCommand("afcb3,6,7,.4,t0,0,7,sc1,1,1,1,afcb3,4,4,.4,t4,0,-4,mx,fl");
67    m.SendCommand("sc1,.5,0,1");
68    m.SendCommand("afcb3,6,5,.4,sc1,1,1,1,afcb2,3,9,.4,fl");
69    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");
70
71    /* Orange fire */
72    m.SendCommand("sc1,1,0,1,scb1,0,0,0,at4,1,s1.5,1,4,tz-13,ad6,5.8,1");
73    m.SendCommand("t-40,40,0,fl");
74
75    /* Lasers */
76    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");
77
78    /* Thrusters */
79    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");
80    m.SendCommand("fl");
81
82    m_particlesystem = new ParticleSystem();
83    Ticker::Ref(m_particlesystem);
84
85    m_camera = new Camera(vec3(0, 200, 200),
86                          vec3(0, 0, 0),
87                          vec3(0, 1, 0));
88    Ticker::Ref(m_camera);
89
90    for (int j = 0; j < 4; j++)
91    for (int i = 0; i < 4; i++)
92    {
93        m_tanks << new Tank();
94        m_tanks.Last()->m_position = vec3(i * 40.f - 60.f, 0, j * 40.f + 20.f);
95        m_tanks.Last()->SetTarget(vec3(i * 80.f - 60.f, 0, j * 80.f - 30.f));
96        Ticker::Ref(m_tanks.Last());
97    }
98
99    m_auto_cam_timer = 0.0f;
100
101    m_angle = vec3(0.f);
102    m_angular_velocity = vec3(0.f);
103
104    m_ready = false;
105}
106
107void Orbital::TickGame(float seconds)
108{
109    WorldEntity::TickGame(seconds);
110
111    if (Input::GetButtonState(27 /*SDLK_ESCAPE*/))
112        Ticker::Shutdown();
113
114#if 0
115    if (m_auto_cam_timer > 0.0f)
116        m_auto_cam_timer -= seconds;
117
118    //Doing the query with actual values, cause I want to stay SDL-free for now.
119
120    int VMovement = Input::GetButtonState(274 /*SDLK_DOWN*/) - Input::GetButtonState(273 /*SDLK_UP*/);
121    int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
122    int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);
123
124    vec3 new_angular_velocity = vec3(0.0f);
125
126    if (VMovement != 0 || HMovement != 0 || RMovement != 0)
127    {
128        new_angular_velocity = vec3(HMovement, VMovement, RMovement) * 50.0f;
129        m_auto_cam_timer = 2.0f;
130    }
131    else if (m_auto_cam_timer <= 0.0f)
132    {
133        /* Order is yaw, pitch, roll */
134        new_angular_velocity = clamp(-m_angle, vec3(40.f, -20.f, -40.f),
135                                               vec3(40.f,  20.f,  40.f));
136    }
137
138    m_angular_velocity += (new_angular_velocity - m_angular_velocity)
139                          * (seconds / (seconds + 0.3f));
140    m_angle += m_angular_velocity * seconds;
141
142    /* TODO: implement "vec3 % float" or "fmod(vec3, float)" */
143    for (int n = 0; n < 3; n++)
144    {
145        if (m_angle[n] > 180.f)
146            m_angle[n] -= 360.f;
147        else if (m_angle[n] < -180.f)
148            m_angle[n] += 360.f;
149    }
150
151    quat q = quat::rotate(-90.f, 0.f, 0.f, 1.f);
152    mat4 anim = mat4(~q * quat::fromeuler(m_angle) * q);
153#endif
154
155    m_model = mat4(1.f);
156}
157
158void Orbital::TickDraw(float seconds)
159{
160    WorldEntity::TickDraw(seconds);
161
162    if (!m_ready)
163    {
164        m.SendCommand("irb");
165
166        /* FIXME: this object never cleans up */
167        m_ready = true;
168    }
169
170    Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));
171
172    m.Render(m_model);
173}
174
175Orbital::~Orbital()
176{
177    for (int i = 0; i < m_tanks.Count(); i++)
178        Ticker::Unref(m_tanks[i]);
179    Ticker::Unref(m_particlesystem);
180    Ticker::Unref(m_camera);
181}
182
183int main(int argc, char **argv)
184{
185    Application app("Orbital", ivec2(800, 600), 60.0f);
186
187#if defined _MSC_VER && !defined _XBOX
188    _chdir("..");
189#elif defined _WIN32 && !defined _XBOX
190    _chdir("../..");
191#endif
192
193    new DebugFps(5, 5);
194    new Orbital();
195    app.ShowPointer(false);
196
197    app.Run();
198
199    return EXIT_SUCCESS;
200}
201
Note: See TracBrowser for help on using the repository browser.