Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/trackManager/src/shoot_laser.cc @ 3388

Last change on this file since 3388 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: 3.4 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:
16*/
17
18
19
20
21#include <GL/glut.h>
22#include <iostream>
23
24#include "stdincl.h"
25#include "data_tank.h"
26
27#include "shoot_laser.h"
28
29using namespace std;
30
31
32
33ShootLaser::ShootLaser () 
34{
35  lastShoot = null;
36  step = 1.0;
37  inhibitor = 0;
38}
39
40
41ShootLaser::~ShootLaser () {}
42
43
44void ShootLaser::drawShoot() 
45{
46
47  //cout << "ShootLaser::drawShoot" << endl;
48  /* now draw all the shoots (many) */
49  shoot* tmpShoot = lastShoot;
50  shoot* lastRef = null;
51  while( tmpShoot != null )
52    {
53      glPushMatrix(); 
54      glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor);
55      tmpShoot->xCor+=tmpShoot->xVel;
56      tmpShoot->yCor+=tmpShoot->yVel;
57      glScalef(0.1, 0.1, 0.1);
58      glutWireCube(1.0);
59      glPopMatrix();
60
61      /* garbage collection: look if shoot is outside world */
62      /* fix1: weak boundaries check all four sides */
63      /* fix2: conditions, that a struct tree can be cut off */
64      /* fix3: more efficent and nicer please */
65      if (tmpShoot->yCor - DataTank::yOffset > 20) 
66        {
67          /* normal case: delete one element, link the others */
68          if (lastRef != null) 
69            {
70              //cout << "garbage collection" << endl;
71              lastRef->next = tmpShoot->next;
72              delete tmpShoot;
73              tmpShoot = lastRef->next;
74              //cout << "garbage collection left" << endl;
75            }
76          else
77            {
78              /* special case: first element to be processed */
79              //cout << "garbage collecton: first el in queue" << endl;
80              lastRef = tmpShoot->next;
81              delete tmpShoot;
82              tmpShoot = lastRef;
83              lastShoot = tmpShoot;
84              if (tmpShoot != null) 
85                {
86                  tmpShoot = tmpShoot->next;
87                  //cout << "noch nich null" << endl;
88                }
89              else 
90                {
91                  lastRef = null;
92                  tmpShoot = null;
93                  lastShoot = null;
94                  //cout << "endl null" << endl;
95                }
96             
97              //cout << "garbage collection: firtst el in queue left" << endl;
98            }
99        }
100      else 
101        {
102          lastRef = tmpShoot;
103          tmpShoot = tmpShoot->next;
104        }
105    }
106  //cout << "ShootLaser::drawShoot - finished" << endl;
107}
108
109
110void ShootLaser::addShoot(shoot* sh) 
111{
112  sh->next = null;
113  lastShoot = sh;
114}
115
116void ShootLaser::addShoot(float x, float y, float z)
117{
118  //cout << "ShootLaser::addShoot" << endl;
119  shoot* sh = new shoot;
120  sh->xCor = x; sh->yCor = y; sh->zCor = z;
121  sh->xVel = 0; sh->yVel = .4/step; sh->zVel = 0;
122  sh->next = lastShoot;
123  lastShoot = sh;
124}
125
126void ShootLaser::addShootExt(float x, float y, float z, 
127                             float xVel, float yVel, float zVel)
128{
129  //cout << "ShootLaser::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->next = lastShoot;
134  lastShoot = sh;
135}
136
137void ShootLaser::setShootStep(float step) 
138{
139  cout << "ShootLaser::setShootStep to " << step << endl;
140  this->step = step;
141  cout << "ShootLaser::setShootStep end " << step << endl;
142}
143
144
145/* Exterminate shoot from game, implement this method  */
146/* if you like to add animatiion */
147void ShootLaser::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.