Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/john/src/shoot_rocket.cc @ 2775

Last change on this file since 2775 was 1957, checked in by bensch, 20 years ago

orxonox/truk: now the rockets are frame-rate-driven

File size: 4.9 KB
Line 
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
28ShootRocket::ShootRocket ()
29{
30  lastShoot = null;
31  step = 1.0;
32  inhibitor =0;
33  rotateAngle = 0.0;
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);
51      tmpShoot->age+=step;
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;
65              tmpShoot->yCor+=tmpShoot->yVel;
66              tmpShoot->xVel*=tmpShoot->xAcc;
67            }
68          else
69            {
70              tmpShoot->xCor+=tmpShoot->xVel;
71              tmpShoot->yCor+=tmpShoot->yVel;
72              tmpShoot->yVel+=tmpShoot->yVel*tmpShoot->yAcc;
73            }
74          break;
75       
76        case ROTATER:
77          tmpShoot->xCor+=tmpShoot->xVel;
78          tmpShoot->yCor+=tmpShoot->yVel;
79          tmpShoot->zCor+=tmpShoot->zVel;
80          break;
81       
82        }
83     
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 */
92      if (tmpShoot->age > tmpShoot->lifetime) 
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
143void ShootRocket::addBackParable(float x, float y, float z)
144{
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;
150  sh->xVel = (-1+(float)rand() / 1000000000/step)/5; 
151  sh->yVel = -.3;
152  sh->zVel = (1-(float)rand() / 1000000000/step)/5;
153  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
154  sh->age=0;
155  sh->lifetime=5; 
156  sh->next = lastShoot;
157  lastShoot = sh;
158  }
159void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction)
160{
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)
166    {
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;
173    }
174  sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0;
175  sh->age=0;
176  sh->lifetime=10; 
177  sh->next = lastShoot;
178  lastShoot = sh;
179}
180
181void ShootRocket::addRotater(float x, float y, float z)
182{
183 
184  static float radius = 2;
185  rotateAngle+=.1;
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);
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; 
196  sh->next = lastShoot;
197  lastShoot = sh;
198}
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.