Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/physics/src/subprojects/particles/framework.cc @ 4307

Last change on this file since 4307 was 4307, checked in by bensch, 19 years ago

orxonox/branches/physics: new definitions of particle-return-values

File size: 5.5 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   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#include "framework.h"
17
18#include "physics_engine.h"
19#include "particle_engine.h"
20
21#include "p_node.h"
22#include "null_parent.h"
23#include "state.h"
24#include "debug.h"
25#include "graphics_engine.h"
26#include "light.h"
27#include "resource_manager.h"
28#include "camera.h"
29
30int verbose;
31
32void Framework::initModule()
33{
34  // Creating a Test Particle System
35  ParticleSystem* system = new ParticleSystem(100000, PARTICLE_SPRITE);
36  system->setLifeSpan(5);
37  system->setConserve(.99);
38  system->setRadius(4, 3, 1, 2);
39  system->setColor(.5,0,0,.5, 1,1,0,1, 0,0,0,0);
40
41  // Creating a Test Particle Emitter
42  ParticleEmitter* emitter = new ParticleEmitter(Vector(0 , 1, 0), M_PI_4, 20, .1);
43  emitter->setType(EMITTER_DOT  );
44  emitter->setSize(0);
45  emitter->setRelCoor(Vector(0,0,0));
46 
47  // Add the Flow from the Emitter into the System
48  ParticleEngine::getInstance()->addConnection(emitter, system);
49}
50
51bool Framework::mainLoop()
52{
53  while(true)
54    {
55      // keyhandler returns false if sdl gets quit by some event
56      if (!this->keyHandler())
57        return false;
58
59      // tick the scene
60      float dt = this->tick();
61
62      // Draw the scene
63      this->draw(dt);
64    }
65}
66
67
68bool Framework::draw(float dt)
69{
70  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
71  glLoadIdentity(); // Reset the view
72 
73  ParticleEngine::getInstance()->draw(dt);
74
75  camera->apply();
76 
77  SDL_GL_SwapBuffers(); // Swap the buffers
78}
79
80
81float Framework::tick()
82{
83  currFrame = SDL_GetTicks();
84  float dt = (float)(currFrame - lastFrame) / 1000.0;
85  lastFrame = currFrame;
86
87  ParticleEngine::getInstance()->tick(dt);
88
89  NullParent::getInstance()->update(dt);
90  return dt;
91}
92
93
94bool Framework::keyHandler()
95{
96  // This is the main loop for the entire program and it will run until done==TRUE
97  {
98    // And poll for events
99    SDL_Event event;
100    while(SDL_PollEvent(&event))
101    {
102      switch (event.type) {
103      case SDL_MOUSEMOTION:
104        {
105          Vector view = camera->getTarget()->getAbsCoor() - camera->getAbsCoor();
106          Vector up = Vector(0, 1, 0);
107          up = camera->getAbsDir().apply(up);
108          Vector h = up.cross(view);
109          Vector v = h.cross(view);
110          h.normalize();
111          v.normalize();
112
113          if (mouseDown[1])
114            camera->setRelCoor(camera->getRelCoor()+ h * event.motion.xrel *.05 - v * event.motion.yrel * .05);
115          if (mouseDown[3])
116            camera->getTarget()->setRelCoor(camera->getTarget()->getRelCoor()+ h * event.motion.xrel *.05 - v * event.motion.yrel * .05);
117           
118        }
119        break;
120      case SDL_MOUSEBUTTONDOWN:
121        switch (event.button.button)
122          {
123          case 4:
124            PRINTF(4)("MouseWheel up\n");
125            //zoomTo *= .5;
126            break;
127          case 5:
128            PRINTF(4)("MouseWheel down\n");
129            //zoomTo *= 2.0;
130            break;
131          case 1:
132          case 2:
133          case 3:
134            mouseDown[event.button.button] = true;
135            break;
136          }
137           
138        break;
139      case SDL_MOUSEBUTTONUP:
140        switch (event.button.button)
141          {
142          case 1:
143          case 2:
144          case 3:
145            mouseDown[event.button.button] = false;
146            break;
147          }
148        break;
149      case SDL_VIDEORESIZE:
150        GraphicsEngine::getInstance()->resolutionChanged(&event.resize);
151        break;
152      case SDL_KEYDOWN:
153        switch (event.key.keysym.sym)
154          {
155          case SDLK_x:
156           
157            break;
158          case SDLK_c:
159
160            break;
161          case SDLK_i:
162            ParticleEngine::getInstance()->debug();
163            break;
164          case SDLK_a:
165            //zoomTo /=2;
166            break;
167          case SDLK_z:
168            //zoomTo *=2;
169            break;
170          case SDLK_h:
171            this->printHelp();
172            break;
173          }
174        break;
175           
176        // If a quit event was recieved
177      case SDL_QUIT:
178        // then we're done and we'll end this program
179        return false;
180        break;
181      default:
182        break;
183      }
184
185    }
186
187    // Get the state of the keyboard keys
188    keys = SDL_GetKeyState(NULL);
189
190    // and check if ESCAPE has been pressed. If so then quit
191    if(keys[SDLK_ESCAPE]) return false;
192  }
193  return true;
194}
195
196
197Framework::Framework()
198{
199  this->lastFrame = 0;
200  // Create a new OpenGL window with the title "Cone3D Basecode" at
201  // 640x480x32, fullscreen and check for errors along the way
202  GraphicsEngine::getInstance();
203
204  LightManager::getInstance();
205  glEnable(GL_TEXTURE_2D);
206
207  // Build the font from a TGA image font.tga in the data directory
208  // Hide the mouse cursor
209  SDL_ShowCursor(2);
210
211  for (int i = 0; i <MOUSE_BUTTON_COUNT; i++)
212    mouseDown[i] = false;
213
214  ResourceManager::getInstance()->setDataDir(DATA_DIRECTORY);
215 
216
217  initModule();
218
219  camera = new Camera();
220
221  State::getInstance()->setCamera(camera, camera->getTarget());
222
223  camera->setAbsCoor(Vector(10, 10, 0));
224
225}
226
227Framework::~Framework()
228{
229  delete GraphicsEngine::getInstance();
230
231}
232
233
234
235void Framework::printHelp(void) const
236{
237  PRINT(0)("Help for the frameWork \n");
238  PRINT(0)("----------------------");
239  PRINT(0)("h - print Help\n");
240  PRINT(0)("i - state Information\n");
241  PRINT(0)("1,2 - increase/decrease emissionRate\n");
242  PRINT(0)("3,4 - increase/decrease emission velocity\n");
243  PRINT(0)("5,6 - increase/decrease spread angle\n");
244  PRINT(0)("\n");
245  PRINT(0)("7,8 - increase-decrease emitter-size\n");
246  PRINT(0)("9 - swap emitterType\n");
247  PRINT(0)("\n");
248
249
250}
251
252
253
254int main(int argc, char *argv[])
255{
256  verbose = 3;
257  Framework* framework = new Framework();
258  framework->mainLoop();
259
260  delete framework;
261  // Kill the GL & SDL screens
262  // And quit
263  return 0;
264}
Note: See TracBrowser for help on using the repository browser.