forked from PrototypeX29A/norbit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (95 loc) · 3.35 KB
/
main.cpp
File metadata and controls
117 lines (95 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* Norbit - Fridge in space simulation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <iostream>
#include <string>
#include "rendering/gl_renderer.h"
#include "rendering/obj_shape.h"
#include "rendering/sphere_shape.h"
#include "control.h"
#include "main.h"
extern "C" {
#include <stdlib.h>
#include <math.h>
//#include "extra.h"
#include "physics.h"
}
using namespace std;
void init_sdl(SDL_Surface **screen, int bpp, int flags, int width, int height);
void init_scene(gl_renderer *renderer);
list<game_object*> game_objects;
list<Controller*> game_controllers;
game_object *ship1, *ship2;
simulation_world *world;
SpaceShipController *control1, *control2;
int main(int argc, char **argv)
{
gl_renderer *renderer = new gl_renderer();
renderer->init();
init_scene(renderer);
renderer->add_ship(ship1, 1);
renderer->add_ship(ship2, 2);
int running = 1;
do {
running = renderer->render();
for(list<Controller*>::const_iterator it = game_controllers.begin(); it !=game_controllers.end(); ++it)
{
(*it)->apply();
}
static real LastTime = 0;
// real Time = LastTime + 0.0001f;
real Time = LastTime + 0.001f;
// printf("time %0.4f %0.4f\n", Time, LastTime);
world->Simulate(Time - LastTime);
// world->Render(); // some debug output
LastTime = Time;
} while (running);
renderer->stop();
}
void init_scene(gl_renderer *renderer)
{
/* ----- Init scene --------------- */
world = new simulation_world();
game_object::set_simulation_world(world);
for(int i=0; i<10;i++){
game_object* sun = new game_object();
rigid_body * r = world->add_body(100.0f);
sun->set_rigid_body(r);
float rx = -50.0 + (rand() % 100);
float ry = -50.0 + (rand() % 100);
//float rz = -50.0 + (rand() % 100);
sun->set_position( rx, ry, 0.0f);
game_objects.push_front(sun);
renderer->add_star(sun);
//GravityController * sungrav = new GravityController(sun, &game_objects);
//game_controllers.push_front(sungrav);
}
ship1 = new game_object();
rigid_body * r = world->add_body( 1.0f );
ship1->set_rigid_body(r);
ship1->set_position(1.0f, 1.0f, 0.0f);
game_objects.push_front(ship1);
GravityController * gravcontrol1 = new GravityController(ship1, &game_objects);
control1 = new SpaceShipController(ship1);
game_controllers.push_front(gravcontrol1);
game_controllers.push_front(control1);
ship2 = new game_object();
r = world->add_body( 1.0f );
ship2->set_rigid_body(r);
ship2->set_position(-1.0f, 1.5f, -0.0f);
game_objects.push_front(ship2);
GravityController * gravcontrol2 = new GravityController(ship2, &game_objects);
control2 = new SpaceShipController(ship2);
game_controllers.push_front(gravcontrol2);
game_controllers.push_front(control2);
}