Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/shoot_laser.cc @ 3346

Last change on this file since 3346 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
RevLine 
[1896]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
[2036]20
21#include <GL/glut.h>
[1896]22#include <iostream>
23
[2036]24#include "stdincl.h"
25#include "data_tank.h"
[1896]26
[2036]27#include "shoot_laser.h"
28
[1896]29using namespace std;
30
31
32
33ShootLaser::ShootLaser () 
34{
35  lastShoot = null;
[1900]36  step = 1.0;
[1929]37  inhibitor = 0;
[1896]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;
[1898]50  shoot* lastRef = null;
[1896]51  while( tmpShoot != null )
52    {
53      glPushMatrix(); 
54      glTranslatef(tmpShoot->xCor, tmpShoot->yCor, tmpShoot->zCor);
[1920]55      tmpShoot->xCor+=tmpShoot->xVel;
56      tmpShoot->yCor+=tmpShoot->yVel;
[1896]57      glScalef(0.1, 0.1, 0.1);
58      glutWireCube(1.0);
59      glPopMatrix();
[1898]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 */
[1899]64      /* fix3: more efficent and nicer please */
[1919]65      if (tmpShoot->yCor - DataTank::yOffset > 20) 
[1898]66        {
[1900]67          /* normal case: delete one element, link the others */
[1898]68          if (lastRef != null) 
69            {
[1900]70              //cout << "garbage collection" << endl;
[1898]71              lastRef->next = tmpShoot->next;
72              delete tmpShoot;
[1900]73              tmpShoot = lastRef->next;
74              //cout << "garbage collection left" << endl;
[1898]75            }
76          else
77            {
[1900]78              /* special case: first element to be processed */
79              //cout << "garbage collecton: first el in queue" << endl;
[1898]80              lastRef = tmpShoot->next;
81              delete tmpShoot;
82              tmpShoot = lastRef;
[1900]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;
[1898]98            }
99        }
100      else 
101        {
102          lastRef = tmpShoot;
103          tmpShoot = tmpShoot->next;
104        }
[1896]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
[1898]116void ShootLaser::addShoot(float x, float y, float z)
[1896]117{
118  //cout << "ShootLaser::addShoot" << endl;
119  shoot* sh = new shoot;
120  sh->xCor = x; sh->yCor = y; sh->zCor = z;
[1920]121  sh->xVel = 0; sh->yVel = .4/step; sh->zVel = 0;
[1896]122  sh->next = lastShoot;
123  lastShoot = sh;
124}
125
[1900]126void ShootLaser::addShootExt(float x, float y, float z, 
[1920]127                             float xVel, float yVel, float zVel)
[1900]128{
129  //cout << "ShootLaser::addShootExtended" << endl;
130  shoot* sh = new shoot;
131  sh->xCor = x; sh->yCor = y; sh->zCor = z;
[1920]132  sh->xVel = xVel/step; sh->yVel = yVel/step; sh->zVel = zVel/step;
[1900]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;
[2036]141  cout << "ShootLaser::setShootStep end " << step << endl;
[1900]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.