Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/core/shoot_rocket.cc @ 1924

Last change on this file since 1924 was 1924, checked in by bensch, 21 years ago

orxonox/truk/core: added support for different types of rockets, and implemented Side-Accelerators :) I think they really rock.

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