Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/projectile.cc @ 3658

Last change on this file since 3658 was 3646, checked in by patrick, 20 years ago

orxonox/trunk: implemented garbage collector, is not yet collecting, i have to update the list.h first.

File size: 2.8 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 "projectile.h"
20
21#include "world_entity.h"
22#include "null_parent.h"
23#include "objModel.h"
24#include "primitive.h"
25#include "vector.h"
26
27using namespace std;
28
29
30/**
31   \brief standard constructor
32*/
33Projectile::Projectile () : WorldEntity()
34{
35  //this->model = new OBJModel("");
36  this->projectileModel = new Primitive(P_SPHERE);
37  this->flightDirection = NULL;
38  this->currentLifeTime = 0.0f;
39  this->ttl = 1.0f;
40  this->speed = 1.1f;
41}
42
43
44/**
45   \brief standard deconstructor
46*/
47Projectile::~Projectile () 
48{
49  /*
50     do not delete the test projectModel, since it is pnode
51     and will be cleaned out by world
52  */
53  //delete this->projectileModel;
54}
55
56
57/**
58   \brief this sets the flight direction of the projectile
59   \param directin in which to flight
60
61   this function will calculate a vector out of this to be used in the
62   tick function
63*/
64void Projectile::setFlightDirection(Quaternion* flightDirection)
65{
66  if( this->flightDirection == NULL)
67    this->flightDirection = new Vector();
68  Vector v(1, 0, 0);
69  *this->flightDirection = flightDirection->apply(v);
70}
71
72
73/**
74   \brief this sets the time to life of the projectile
75   \param ttl in second
76
77   after this life time, the projectile will garbage collect itself
78*/
79void Projectile::setTTL(float ttl)
80{
81  this->ttl = ttl;
82}
83
84
85/**
86   \brief signal tick, time dependent things will be handled here
87   \param time since last tick
88*/
89void Projectile::tick (float time) 
90{
91  this->currentLifeTime += time;
92  if( this->ttl < this->currentLifeTime)
93    {
94      *this->flightDirection = *this->flightDirection * speed;
95      this->shiftCoor(this->flightDirection);
96      return;
97    }
98  this->finalize();
99  //NullParent* np = NullParent::getInstance();
100  /* garbage colelction */
101  // \fix: there is no gc in this class, its all been done by GarbageCollector
102}
103
104/**
105   \brief the projectile gets hit by another entity
106   \param the other entity
107   \param place where it is hit
108*/
109void Projectile::hit (WorldEntity* entity, Vector* place) 
110{}
111
112
113/**
114   \brief the function gets called, when the projectile is destroyed
115*/
116void Projectile::destroy () 
117{}
118
119
120void Projectile::draw () 
121{
122  glMatrixMode(GL_MODELVIEW);
123  glPushMatrix();
124
125  float matrix[4][4]; 
126  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
127  this->getAbsDir().matrix (matrix);
128  glMultMatrixf((float*)matrix); 
129  //this->model->draw();
130  this->projectileModel->draw();
131
132  glPopMatrix();
133}
134
Note: See TracBrowser for help on using the repository browser.