Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4941 was 4941, checked in by bensch, 19 years ago

orxonox/trunk: new garbage-collection-algorithm works, but the entities are not correctly setup for re-entering the scene.

File size: 2.5 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 "weapon.h"
23#include "null_parent.h"
24#include "model.h"
25#include "vector.h"
26
27#include "garbage_collector.h"
28
29using namespace std;
30
31
32/**
33 *  standard constructor
34*/
35Projectile::Projectile () : WorldEntity()
36{
37  this->setClassID(CL_PROJECTILE, "Projectile");
38
39  this->lifeCycle = 0.0;
40  this->lifeSpan = 0.75f; /* sec */
41}
42
43
44/**
45 *  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 *  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(const Quaternion& flightDirection)
65{
66  Vector v(1, 0, 0);
67  this->flightDirection = flightDirection.apply(v);
68  this->flightDirection.normalize();
69}
70
71/**
72 *  sets the velocity vector to a spec speed
73 * @param velocity: vector of the velocity
74*/
75void Projectile::setVelocity(const Vector &velocity)
76{
77  Vector offsetVel = this->velocity = velocity;
78  offsetVel.normalize();
79  this->velocity += (offsetVel * 50.0);
80}
81
82/**
83 * signal tick, time dependent things will be handled here
84 * @param time since last tick
85*/
86void Projectile::tick (float time)
87{
88  Vector v = this->velocity * (time);
89  this->shiftCoor(v);
90
91  this->lifeCycle += time/this->lifeSpan;
92  if( this->lifeCycle >= 1)
93  {
94    PRINTF(5)("FINALIZE==========================\n");
95    PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
96    PRINTF(5)("FINALIZE===========================\n");
97    //this->finalize();
98    GarbageCollector::getInstance()->collect(this);
99  }
100}
101
102
103/**
104 *  the function gets called, when the projectile is destroyed
105*/
106void Projectile::destroy ()
107{}
108
109
110void Projectile::draw ()
111{
112  glMatrixMode(GL_MODELVIEW);
113  glPushMatrix();
114
115  float matrix[4][4];
116  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
117  this->getAbsDir().matrix (matrix);
118  glMultMatrixf((float*)matrix);
119  this->model->draw();
120
121  glPopMatrix();
122}
123
Note: See TracBrowser for help on using the repository browser.