Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/orxonox.cc @ 1883

Last change on this file since 1883 was 1883, checked in by patrick, 20 years ago

orxonox/trunk: added envoronment eg. little mountain - its time to talk about further development…

File size: 5.6 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19
20
21   ### File Specific:
22   main-programmer: Patrick Boenzli
23   co-programmer:
24*/
25
26/* class definition header */
27#include "orxonox.h"
28#include "environment.h"
29
30
31using namespace std;
32
33
34
35Orxonox::Orxonox () 
36{
37  pause = false;
38}
39
40
41
42Orxonox::~Orxonox () 
43{
44  glutSetKeyRepeat(GLUT_KEY_REPEAT_ON);
45}
46
47
48/* this is a singleton class to prevent dublicates */
49Orxonox* Orxonox::singleton_ref = 0;
50World* Orxonox::world = 0;
51InputOutput* Orxonox::io = 0;
52bool Orxonox::pause = false;
53bool Orxonox::upWeGo = false;
54bool Orxonox::downWeGo = false;
55bool Orxonox::rightWeGo = false;
56bool Orxonox::leftWeGo = false;
57int Orxonox::alpha = 0;
58int Orxonox::beta = 0;
59//int Orxonox::offsetX = 0;
60//int Orxonox::offsetY = 0;
61
62Orxonox* Orxonox::getInstance (void)
63{
64  if (singleton_ref == NULL)
65    singleton_ref = new Orxonox();
66  return singleton_ref;
67}
68
69
70int Orxonox::globalInit (int argc, char** argv) 
71{
72  glutInit(&argc, argv);
73  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
74  glEnable(GL_DEPTH_TEST);
75  glutInitWindowSize(500, 500);
76  //glutFullScreen();
77  glutInitWindowPosition(100, 100);
78  glutCreateWindow("orxOnox");
79  glShadeModel(GL_FLAT);
80  /* window event dispatchers */
81  glutDisplayFunc(display);
82  glutReshapeFunc(reshape);
83  glutKeyboardFunc(keyboard);
84}
85
86
87int Orxonox::menuInit (void)
88{
89  glClearColor(0.0, 0.0, 0.0, 0.0);
90}
91
92
93int Orxonox::gameInit (void) 
94{
95  glClearColor(0.0, 0.0, 0.0, 0.0);
96  world = new World;
97  (*world).initEnvironement();
98  Player* localPlayer = new Player;
99  io = new InputOutput(world, localPlayer);
100  (*world).addPlayer(localPlayer);
101  Environment *env = new Environment;
102  (*world).addEnv(env);
103 
104
105  glutSpecialFunc(specFunc); 
106  glutSpecialUpFunc(releaseKey);
107
108  //for testing purps only
109  //testTheShit();
110  glutIdleFunc(continousRedraw);
111}
112
113
114void Orxonox::keyboard(unsigned char key, int x, int y)
115{
116  switch(key) {
117
118    /* perspectiv control */
119  case 'w':
120    beta -= 1;
121    break;
122  case 's':
123    beta += 1;
124    break;
125  case 'a':
126    alpha -= 1;
127    break;
128  case 'd':
129    alpha += 1;
130    break;
131
132    /* game controls */
133
134  case 'p':
135    if (pause) 
136      {
137        cout << "unset pause" << endl;
138        glutIdleFunc(continousRedraw);
139        pause = false;
140      }
141    else 
142      {
143        cout << "set pause" << endl;
144        glutIdleFunc(NULL);
145        pause = true;
146      }
147    break;
148  case 27:
149  case 'q':
150    quitGame();
151    break;
152  }
153}
154
155
156void Orxonox::quitGame() 
157{
158  //glutIgnoreKeyRepeat(0);                 /* for win32 */
159  //glutSetKeyRepeat(GLUT_KEY_REPEAT_DEFAULT); /*do not remove or you will have
160  //                                      no repeating keys anymore...*/
161  cout << "finished garbage colletion, quitting..." << endl;
162  exit(0);
163}
164
165
166void Orxonox::releaseKey(int key, int x, int y) 
167{ 
168  switch(key) {
169  case GLUT_KEY_UP:
170    upWeGo = false;
171    break;
172  case GLUT_KEY_DOWN:
173    downWeGo = false;
174    break;
175  case GLUT_KEY_RIGHT:
176    rightWeGo = false;
177    break;
178  case GLUT_KEY_LEFT:
179    leftWeGo = false;
180    break;
181  }
182}
183
184
185/**
186   \brief special keys function. called by glut
187   
188   Here are all special key function defined.
189*/
190void Orxonox::specFunc(int key, int x, int y)
191{
192  switch(key) {
193
194    /* spacecraft controls */
195   
196  case GLUT_KEY_UP:
197    upWeGo = true;
198    break;
199  case GLUT_KEY_DOWN:
200    downWeGo = true;
201    break;
202  case GLUT_KEY_RIGHT:
203    rightWeGo = true;
204    break;
205  case GLUT_KEY_LEFT:
206    leftWeGo = true;
207    break;
208  }
209}
210
211
212void Orxonox::display() 
213{
214  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
215
216  glColor3f(0.0, 0.5, 0.6);
217  glLoadIdentity();
218  gluLookAt(0.0, -14.0, 15.0, 0.0 + alpha, 0.0 + beta, 0.0, 0.0, 1.0, 0.0);
219  (*world).drawWorld();
220
221  glutSwapBuffers();
222} 
223
224
225void Orxonox::continousRedraw()
226{
227  /* check for input to pass it over */
228  if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo)) {
229    if (upWeGo)
230      (*io).goUp();
231    if (downWeGo)
232      (*io).goDown();
233    if (rightWeGo)
234      (*io).goRight();
235    if (leftWeGo)
236      (*io).goLeft();
237  }
238  /* request repaint */
239
240  //cout << "contiousRedraw" << endl;
241  glutPostRedisplay();
242}
243
244
245void Orxonox::reshape (int w, int h)
246{
247  glViewport(0, 0, (GLsizei) w, (GLsizei) h);
248  glMatrixMode(GL_PROJECTION);
249  glLoadIdentity();
250  //glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); pb: //simple and working
251  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0);
252  //glFrustum(-10.0, 10.0, -5.0, 10.0, 0.0, 100.0);
253  glMatrixMode(GL_MODELVIEW);
254  glLoadIdentity(); //pb why a second time?
255}
256
257
258void Orxonox::testTheShit() 
259{
260  //Player* pl = new Player;
261  //(*pl).setPosition(1, 1, 1);
262  //(*world).addPlayer(pl);
263 
264  //NPC* nl = new NPC;
265  //(*world).addNPC(nl);
266  //(*world).addNPC(nl);
267  //(*world).addNPC(nl);
268  //(*world).addNPC(nl);
269  //(*world).addNPC(nl);
270  //(*world).addNPC(nl);
271  //(*world).testThaTest();
272}
273
274
275int main (int argc, char** argv) 
276{ 
277  Orxonox *orx = Orxonox::getInstance();
278  (*orx).globalInit(argc, argv);
279  //(*orx).menuInit(); pb: directly jump to the game, no menu
280  (*orx).gameInit();
281
282  glutMainLoop(); 
283  return 0;
284}
Note: See TracBrowser for help on using the repository browser.