Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/shadows/src/shoot_rocket.cc @ 4225

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

orxonxo/trunk/src: extended framework: class inheritance, right including (had som bugs), framework not finished yet

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