Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/physics: particleEngine can now return the stored systems and emitter by name and number

File size: 5.6 KB
RevLine 
[3140]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
[2931]16#include "framework.h"
[3427]17
[4293]18#include "physics_engine.h"
19#include "particle_engine.h"
[3427]20
[4294]21#include "p_node.h"
22#include "null_parent.h"
23#include "state.h"
[4272]24#include "debug.h"
25#include "graphics_engine.h"
[4300]26#include "light.h"
[4295]27#include "resource_manager.h"
[4297]28#include "camera.h"
[3657]29
[3398]30int verbose;
[4293]31
[4305]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
[4297]51bool Framework::mainLoop()
[2748]52{
[4293]53  while(true)
54    {
[4297]55      // keyhandler returns false if sdl gets quit by some event
[4303]56      if (!this->keyHandler())
[4293]57        return false;
[2939]58
[4297]59      // tick the scene
[4303]60      float dt = this->tick();
[4297]61
[4293]62      // Draw the scene
[4303]63      this->draw(dt);
[4293]64    }
65}
66
67
[4297]68bool Framework::draw(float dt)
[4293]69{
[2748]70  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
71  glLoadIdentity(); // Reset the view
72 
[4294]73  ParticleEngine::getInstance()->draw(dt);
[4297]74
75  camera->apply();
[4294]76 
[2748]77  SDL_GL_SwapBuffers(); // Swap the buffers
78}
[4300]79
80
[4297]81float Framework::tick()
[2748]82{
[4293]83  currFrame = SDL_GetTicks();
[4300]84  float dt = (float)(currFrame - lastFrame) / 1000.0;
85  lastFrame = currFrame;
[3398]86
[4293]87  ParticleEngine::getInstance()->tick(dt);
[2963]88
[4294]89  NullParent::getInstance()->update(dt);
90  return dt;
[4293]91}
[2952]92
[2931]93
[4297]94bool Framework::keyHandler()
[4293]95{
[2748]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;
[4305]100    while(SDL_PollEvent(&event))
[4303]101    {
[2748]102      switch (event.type) {
[2931]103      case SDL_MOUSEMOTION:
[4306]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);
[4300]117           
[4306]118        }
[2931]119        break;
120      case SDL_MOUSEBUTTONDOWN:
[4306]121        switch (event.button.button)
[2933]122          {
[4306]123          case 4:
[3656]124            PRINTF(4)("MouseWheel up\n");
[4306]125            //zoomTo *= .5;
126            break;
127          case 5:
[3656]128            PRINTF(4)("MouseWheel down\n");
[4306]129            //zoomTo *= 2.0;
130            break;
131          case 1:
132          case 2:
133          case 3:
134            mouseDown[event.button.button] = true;
135            break;
[2933]136          }
[2932]137           
[2931]138        break;
[2952]139      case SDL_MOUSEBUTTONUP:
[4306]140        switch (event.button.button)
141          {
142          case 1:
143          case 2:
144          case 3:
145            mouseDown[event.button.button] = false;
146            break;
147          }
[2931]148        break;
[4302]149      case SDL_VIDEORESIZE:
150        GraphicsEngine::getInstance()->resolutionChanged(&event.resize);
151        break;
[3211]152      case SDL_KEYDOWN:
153        switch (event.key.keysym.sym)
154          {
155          case SDLK_x:
[4298]156           
[3211]157            break;
158          case SDLK_c:
[4293]159
[3211]160            break;
[4296]161          case SDLK_i:
162            ParticleEngine::getInstance()->debug();
163            break;
[3418]164          case SDLK_a:
[4300]165            //zoomTo /=2;
[3418]166            break;
167          case SDLK_z:
[4300]168            //zoomTo *=2;
169            break;
[4307]170          case SDLK_h:
171            this->printHelp();
172            break;
[4308]173
174          case SDLK_1:
175            break;
[3211]176          }
177        break;
[2952]178           
[2748]179        // If a quit event was recieved
[2863]180      case SDL_QUIT:
181        // then we're done and we'll end this program
[4293]182        return false;
183        break;
[2863]184      default:
[4293]185        break;
[2748]186      }
[2952]187
[2748]188    }
189
190    // Get the state of the keyboard keys
191    keys = SDL_GetKeyState(NULL);
192
193    // and check if ESCAPE has been pressed. If so then quit
[4293]194    if(keys[SDLK_ESCAPE]) return false;
[2748]195  }
[4293]196  return true;
197}
[2748]198
[4293]199
[4300]200Framework::Framework()
[4293]201{
[4304]202  this->lastFrame = 0;
[4293]203  // Create a new OpenGL window with the title "Cone3D Basecode" at
204  // 640x480x32, fullscreen and check for errors along the way
205  GraphicsEngine::getInstance();
206
[4300]207  LightManager::getInstance();
208  glEnable(GL_TEXTURE_2D);
[4293]209
210  // Build the font from a TGA image font.tga in the data directory
211  // Hide the mouse cursor
212  SDL_ShowCursor(2);
213
[4306]214  for (int i = 0; i <MOUSE_BUTTON_COUNT; i++)
215    mouseDown[i] = false;
216
[4295]217  ResourceManager::getInstance()->setDataDir(DATA_DIRECTORY);
[4294]218 
219
[4305]220  initModule();
[4294]221
[4297]222  camera = new Camera();
[4294]223
[4305]224  State::getInstance()->setCamera(camera, camera->getTarget());
[4294]225
226  camera->setAbsCoor(Vector(10, 10, 0));
227
[4297]228}
229
230Framework::~Framework()
231{
232  delete GraphicsEngine::getInstance();
233
234}
235
[4307]236
237
238void Framework::printHelp(void) const
239{
240  PRINT(0)("Help for the frameWork \n");
241  PRINT(0)("----------------------");
242  PRINT(0)("h - print Help\n");
243  PRINT(0)("i - state Information\n");
244  PRINT(0)("1,2 - increase/decrease emissionRate\n");
245  PRINT(0)("3,4 - increase/decrease emission velocity\n");
246  PRINT(0)("5,6 - increase/decrease spread angle\n");
247  PRINT(0)("\n");
248  PRINT(0)("7,8 - increase-decrease emitter-size\n");
249  PRINT(0)("9 - swap emitterType\n");
250  PRINT(0)("\n");
251
252
253}
254
255
256
[4297]257int main(int argc, char *argv[])
258{
259  verbose = 3;
[4304]260  Framework* framework = new Framework();
[4297]261  framework->mainLoop();
262
263  delete framework;
[2748]264  // Kill the GL & SDL screens
265  // And quit
266  return 0;
267}
Note: See TracBrowser for help on using the repository browser.