Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/john/src/shoot_laser.cc @ 3177

Last change on this file since 3177 was 1956, checked in by bensch, 20 years ago

orxonox/trunk: now the Trunk should be merged with the new Makefile. Hopefully it works

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