Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: rockets added (in 3D)

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