Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/automake/src/shoot_rocket.cc @ 2000

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

orxonox/branches/automake: now it should compile on windows. random→rand, glut→glut32

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          break;
80       
81        }
82     
83      glScalef(0.1, 0.1, 0.1);
84      glutWireCube(1.0);
85      glPopMatrix();
86
87      /* garbage collection: look if shoot is outside world */
88      /* fix1: weak boundaries check all four sides */
89      /* fix2: conditions, that a struct tree can be cut off */
90      /* fix3: more efficent and nicer please */
91      if (tmpShoot->yCor - DataTank::yOffset > 20) 
92        {
93          /* normal case: delete one element, link the others */
94          if (lastRef != null) 
95            {
96              //cout << "garbage collection" << endl;
97              lastRef->next = tmpShoot->next;
98              delete tmpShoot;
99              tmpShoot = lastRef->next;
100              //cout << "garbage collection left" << endl;
101            }
102          else
103            {
104              /* special case: first element to be processed */
105              //cout << "garbage collecton: first el in queue" << endl;
106              lastRef = tmpShoot->next;
107              delete tmpShoot;
108              tmpShoot = lastRef;
109              lastShoot = tmpShoot;
110              if (tmpShoot != null) 
111                {
112                  tmpShoot = tmpShoot->next;
113                  //cout << "noch nich null" << endl;
114                }
115              else 
116                {
117                  lastRef = null;
118                  tmpShoot = null;
119                  lastShoot = null;
120                  //cout << "endl null" << endl;
121                }
122             
123              //cout << "garbage collection: firtst el in queue left" << endl;
124            }
125        }
126      else 
127        {
128          lastRef = tmpShoot;
129          tmpShoot = tmpShoot->next;
130        }
131    }
132  //cout << "ShootRocket::drawShoot - finished" << endl;
133}
134
135
136void ShootRocket::addShoot(shoot* sh) 
137{
138  sh->next = null;
139  lastShoot = sh;
140}
141
142void ShootRocket::addBackParable(float x, float y, float z)
143{
144 
145  //cout << "ShootRocket::addShoot" << endl;
146  shoot* sh = new shoot;
147  sh->type = BACKPARABLE;
148  sh->xCor = x; sh->yCor = y; sh->zCor = z;
149  sh->xVel = (-1+(float)rand() / 1000000000/step)/5; 
150  sh->yVel = -.3;
151  sh->zVel = (1-(float)rand() / 1000000000/step)/5;
152  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
153  sh->next = lastShoot;
154  lastShoot = sh;
155  }
156void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction)
157{
158  //cout << "ShootRocket::addShoot" << endl;
159  shoot* sh = new shoot;
160  sh->type = SIDEACC;
161  sh->xCor = x; sh->yCor = y; sh->zCor = z;
162  switch (direction)
163    {
164    case LEFT:
165      sh->xVel = -.5; sh->yVel = .05; sh->zVel = 0;
166      break;
167    case RIGHT:
168      sh->xVel = .5; sh->yVel = .05; sh->zVel = 0;
169      break;
170    }
171  sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0;
172  sh->next = lastShoot;
173  lastShoot = sh;
174}
175
176void ShootRocket::addRotater(float x, float y, float z)
177{
178 
179  static float radius = 2;
180  rotateAngle+=.1;
181  //cout << "ShootRocket::addShoot" << endl;
182  shoot* sh = new shoot;
183  sh->type = ROTATER;
184  sh->xCor = x+radius*sin(rotateAngle); sh->yCor = y; sh->zCor = z+radius*cos(rotateAngle);
185  sh->xVel = .1*cos(rotateAngle)/step;
186  sh->yVel = 0.4/step;
187  sh->zVel = .1*sin(rotateAngle)/step;
188  sh->xAcc = 1.01; sh->yAcc = 1.01/step; sh->zAcc = 1.01;
189  sh->next = lastShoot;
190  lastShoot = sh;
191}
192
193void ShootRocket::setShootStep(float step) 
194{
195  cout << "ShootRocket::setShootStep to " << step << endl;
196  this->step = step;
197}
198
199
200/* Exterminate shoot from game, implement this method  */
201/* if you like to add animatiion */
202void ShootRocket::removeShoot(shoot* sh)
203{
204  glPushMatrix(); 
205  glTranslatef(sh->xCor, sh->yCor, sh->zCor);
206  glutWireCube(1.0);
207  glPopMatrix();
208}
Note: See TracBrowser for help on using the repository browser.