Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/shoot_rocket.cc @ 3185

Last change on this file since 3185 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
RevLine 
[1920]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>
[2036]20#include <math.h>
21#include <GL/glut.h>
[1920]22
[2036]23#include "stdincl.h"
24#include "data_tank.h"
25#include "npc.h"
[1920]26
[2036]27#include "shoot_rocket.h"
28
[1920]29using namespace std;
30
31
32
[1921]33ShootRocket::ShootRocket ()
[1920]34{
35  lastShoot = null;
36  step = 1.0;
[1921]37  inhibitor =0;
[1926]38  rotateAngle = 0.0;
[1920]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);
[1957]56      tmpShoot->age+=step;
[1924]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;
[1925]70              tmpShoot->yCor+=tmpShoot->yVel;
[1924]71              tmpShoot->xVel*=tmpShoot->xAcc;
72            }
73          else
74            {
[1925]75              tmpShoot->xCor+=tmpShoot->xVel;
[1924]76              tmpShoot->yCor+=tmpShoot->yVel;
77              tmpShoot->yVel+=tmpShoot->yVel*tmpShoot->yAcc;
78            }
79          break;
[1926]80       
81        case ROTATER:
[1927]82          tmpShoot->xCor+=tmpShoot->xVel;
[1926]83          tmpShoot->yCor+=tmpShoot->yVel;
[1927]84          tmpShoot->zCor+=tmpShoot->zVel;
[1926]85          break;
86       
[1924]87        }
[1926]88     
[1920]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 */
[1957]97      if (tmpShoot->age > tmpShoot->lifetime) 
[1920]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
[1924]148void ShootRocket::addBackParable(float x, float y, float z)
[1920]149{
[1926]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;
[1955]155  sh->xVel = (-1+(float)rand() / 1000000000/step)/5; 
[1926]156  sh->yVel = -.3;
[1955]157  sh->zVel = (1-(float)rand() / 1000000000/step)/5;
[1926]158  sh->xAcc = 0; sh->yAcc = .01/step; sh->zAcc = 0;
[1957]159  sh->age=0;
160  sh->lifetime=5; 
[1926]161  sh->next = lastShoot;
162  lastShoot = sh;
[1929]163  }
[1924]164void ShootRocket::addSideAcc(float x, float y, float z, enum RocketDirection direction)
[1920]165{
[1926]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)
[1924]171    {
[1926]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;
[1924]178    }
[1926]179  sh->xAcc = .9; sh->yAcc = .02; sh->zAcc = 0;
[1957]180  sh->age=0;
181  sh->lifetime=10; 
[1926]182  sh->next = lastShoot;
183  lastShoot = sh;
[1929]184}
[1926]185
186void ShootRocket::addRotater(float x, float y, float z)
187{
188 
189  static float radius = 2;
[1927]190  rotateAngle+=.1;
[1926]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);
[1957]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; 
[1926]201  sh->next = lastShoot;
202  lastShoot = sh;
203}
[1920]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.