Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/core: added modulated phase variance-shot

File size: 4.8 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      switch (tmpShoot->type)
52        {
53        case BACKPARABLE:
54          tmpShoot->xCor+=tmpShoot->xVel;
55          tmpShoot->yCor+=tmpShoot->yVel;
56          tmpShoot->xVel+=tmpShoot->xAcc;
57          tmpShoot->yVel+=tmpShoot->yAcc;
58          break;
59       
60        case SIDEACC:
61          if (tmpShoot->xVel >= .01 || tmpShoot->xVel <= -.01)
62            {
63              tmpShoot->xCor+=tmpShoot->xVel;
64              tmpShoot->yCor+=tmpShoot->yVel;
65              tmpShoot->xVel*=tmpShoot->xAcc;
66            }
67          else
68            {
69              tmpShoot->xCor+=tmpShoot->xVel;
70              tmpShoot->yCor+=tmpShoot->yVel;
71              tmpShoot->yVel+=tmpShoot->yVel*tmpShoot->yAcc;
72            }
73          break;
74       
75        case ROTATER:
76          // tmpShoot->xCor+=tmpShoot->xVel;
77          tmpShoot->yCor+=tmpShoot->yVel;
78          //tmpShoot->zCor+=tmpShoot->zVel;
79          //tmpShoot->xVel+=tmpShoot->xVel;
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->yCor - DataTank::yOffset > 20) 
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)random() / 1000000000/step)/5; 
151  sh->yVel = -.3;
152  sh->zVel = (1-(float)random() / 1000000000/step)/5;
153  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
154  sh->next = lastShoot;
155  lastShoot = sh;
156  inhibitor =0;
157}
158void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction)
159{
160  //cout << "ShootRocket::addShoot" << endl;
161  shoot* sh = new shoot;
162  sh->type = SIDEACC;
163  sh->xCor = x; sh->yCor = y; sh->zCor = z;
164  switch (direction)
165    {
166    case LEFT:
167      sh->xVel = -.5; sh->yVel = .05; sh->zVel = 0;
168      break;
169    case RIGHT:
170      sh->xVel = .5; sh->yVel = .05; sh->zVel = 0;
171      break;
172    }
173  sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0;
174  sh->next = lastShoot;
175  lastShoot = sh;
176  inhibitor =0;
177
178}
179void ShootRocket::addRotater(float x, float y, float z)
180{
181 
182  static float radius = 2;
183  rotateAngle+=.5;
184  //cout << "ShootRocket::addShoot" << endl;
185  shoot* sh = new shoot;
186  sh->type = ROTATER;
187  sh->xCor = x+radius*sin(rotateAngle); sh->yCor = y; sh->zCor = z+radius*cos(rotateAngle);
188  sh->xVel = .05*sin(rotateAngle);
189  sh->yVel = .4;
190  sh->xVel = .05*cos(rotateAngle);
191  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
192  sh->next = lastShoot;
193  lastShoot = sh;
194  inhibitor =0;
195}
196
197void ShootRocket::setShootStep(float step) 
198{
199  cout << "ShootRocket::setShootStep to " << step << endl;
200  this->step = step;
201}
202
203
204/* Exterminate shoot from game, implement this method  */
205/* if you like to add animatiion */
206void ShootRocket::removeShoot(shoot* sh)
207{
208  glPushMatrix(); 
209  glTranslatef(sh->xCor, sh->yCor, sh->zCor);
210  glutWireCube(1.0);
211  glPopMatrix();
212}
Note: See TracBrowser for help on using the repository browser.