Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/gui/src/shoot_rocket.cc @ 2015

Last change on this file since 2015 was 1977, checked in by bensch, 20 years ago

orxonox/branches/gui: updated from trunk with 'svn merge -r 1860 [trunkdir] .'

File size: 4.9 KB
RevLine 
[1920]1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer:  Benjamin Grauer
16*/
17
18
19#include "shoot_rocket.h"
20
21#include <iostream>
22
23
24using namespace std;
25
26
27
[1921]28ShootRocket::ShootRocket ()
[1920]29{
30  lastShoot = null;
31  step = 1.0;
[1921]32  inhibitor =0;
[1926]33  rotateAngle = 0.0;
[1920]34}
35
36
37ShootRocket::~ShootRocket () {}
38
39
40void ShootRocket::drawShoot() 
41{
42
43  //cout << "ShootRocket::drawShoot" << endl;
44  /* now draw all the shoots (many) */
45  shoot* tmpShoot = lastShoot;
46  shoot* lastRef = null;
47  while( tmpShoot != null )
48    {
49      glPushMatrix(); 
50      glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor);
[1957]51      tmpShoot->age+=step;
[1924]52      switch (tmpShoot->type)
53        {
54        case BACKPARABLE:
55          tmpShoot->xCor+=tmpShoot->xVel;
56          tmpShoot->yCor+=tmpShoot->yVel;
57          tmpShoot->xVel+=tmpShoot->xAcc;
58          tmpShoot->yVel+=tmpShoot->yAcc;
59          break;
60       
61        case SIDEACC:
62          if (tmpShoot->xVel >= .01 || tmpShoot->xVel <= -.01)
63            {
64              tmpShoot->xCor+=tmpShoot->xVel;
[1925]65              tmpShoot->yCor+=tmpShoot->yVel;
[1924]66              tmpShoot->xVel*=tmpShoot->xAcc;
67            }
68          else
69            {
[1925]70              tmpShoot->xCor+=tmpShoot->xVel;
[1924]71              tmpShoot->yCor+=tmpShoot->yVel;
72              tmpShoot->yVel+=tmpShoot->yVel*tmpShoot->yAcc;
73            }
74          break;
[1926]75       
76        case ROTATER:
[1927]77          tmpShoot->xCor+=tmpShoot->xVel;
[1926]78          tmpShoot->yCor+=tmpShoot->yVel;
[1927]79          tmpShoot->zCor+=tmpShoot->zVel;
[1926]80          break;
81       
[1924]82        }
[1926]83     
[1920]84      glScalef(0.1, 0.1, 0.1);
85      glutWireCube(1.0);
86      glPopMatrix();
87
88      /* garbage collection: look if shoot is outside world */
89      /* fix1: weak boundaries check all four sides */
90      /* fix2: conditions, that a struct tree can be cut off */
91      /* fix3: more efficent and nicer please */
[1957]92      if (tmpShoot->age > tmpShoot->lifetime) 
[1920]93        {
94          /* normal case: delete one element, link the others */
95          if (lastRef != null) 
96            {
97              //cout << "garbage collection" << endl;
98              lastRef->next = tmpShoot->next;
99              delete tmpShoot;
100              tmpShoot = lastRef->next;
101              //cout << "garbage collection left" << endl;
102            }
103          else
104            {
105              /* special case: first element to be processed */
106              //cout << "garbage collecton: first el in queue" << endl;
107              lastRef = tmpShoot->next;
108              delete tmpShoot;
109              tmpShoot = lastRef;
110              lastShoot = tmpShoot;
111              if (tmpShoot != null) 
112                {
113                  tmpShoot = tmpShoot->next;
114                  //cout << "noch nich null" << endl;
115                }
116              else 
117                {
118                  lastRef = null;
119                  tmpShoot = null;
120                  lastShoot = null;
121                  //cout << "endl null" << endl;
122                }
123             
124              //cout << "garbage collection: firtst el in queue left" << endl;
125            }
126        }
127      else 
128        {
129          lastRef = tmpShoot;
130          tmpShoot = tmpShoot->next;
131        }
132    }
133  //cout << "ShootRocket::drawShoot - finished" << endl;
134}
135
136
137void ShootRocket::addShoot(shoot* sh) 
138{
139  sh->next = null;
140  lastShoot = sh;
141}
142
[1924]143void ShootRocket::addBackParable(float x, float y, float z)
[1920]144{
[1926]145 
146  //cout << "ShootRocket::addShoot" << endl;
147  shoot* sh = new shoot;
148  sh->type = BACKPARABLE;
149  sh->xCor = x; sh->yCor = y; sh->zCor = z;
[1955]150  sh->xVel = (-1+(float)rand() / 1000000000/step)/5; 
[1926]151  sh->yVel = -.3;
[1955]152  sh->zVel = (1-(float)rand() / 1000000000/step)/5;
[1926]153  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
[1957]154  sh->age=0;
155  sh->lifetime=5; 
[1926]156  sh->next = lastShoot;
157  lastShoot = sh;
[1929]158  }
[1924]159void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction)
[1920]160{
[1926]161  //cout << "ShootRocket::addShoot" << endl;
162  shoot* sh = new shoot;
163  sh->type = SIDEACC;
164  sh->xCor = x; sh->yCor = y; sh->zCor = z;
165  switch (direction)
[1924]166    {
[1926]167    case LEFT:
168      sh->xVel = -.5; sh->yVel = .05; sh->zVel = 0;
169      break;
170    case RIGHT:
171      sh->xVel = .5; sh->yVel = .05; sh->zVel = 0;
172      break;
[1924]173    }
[1926]174  sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0;
[1957]175  sh->age=0;
176  sh->lifetime=10; 
[1926]177  sh->next = lastShoot;
178  lastShoot = sh;
[1929]179}
[1926]180
181void ShootRocket::addRotater(float x, float y, float z)
182{
183 
184  static float radius = 2;
[1927]185  rotateAngle+=.1;
[1926]186  //cout << "ShootRocket::addShoot" << endl;
187  shoot* sh = new shoot;
188  sh->type = ROTATER;
189  sh->xCor = x+radius*sin(rotateAngle); sh->yCor = y; sh->zCor = z+radius*cos(rotateAngle);
[1957]190  sh->xVel = 1*cos(rotateAngle)*step;
191  sh->yVel = 4*step;
192  sh->zVel = 1*sin(rotateAngle)*step;
193  sh->xAcc = 1.01; sh->yAcc = 1- step; sh->zAcc = 1.01;
194  sh->age=0;
195  sh->lifetime=10; 
[1926]196  sh->next = lastShoot;
197  lastShoot = sh;
198}
[1920]199
200void ShootRocket::setShootStep(float step) 
201{
202  cout << "ShootRocket::setShootStep to " << step << endl;
203  this->step = step;
204}
205
206
207/* Exterminate shoot from game, implement this method  */
208/* if you like to add animatiion */
209void ShootRocket::removeShoot(shoot* sh)
210{
211  glPushMatrix(); 
212  glTranslatef(sh->xCor, sh->yCor, sh->zCor);
213  glutWireCube(1.0);
214  glPopMatrix();
215}
Note: See TracBrowser for help on using the repository browser.