Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more cleanup of the WorldEntity (includes rearanged)

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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
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
26#include "garbage_collector.h"
27
28using namespace std;
29
30
31/**
32 *  standard constructor
33*/
34Projectile::Projectile () : WorldEntity()
35{
36  this->setClassID(CL_PROJECTILE, "Projectile");
37
38  this->lifeCycle = 0.0;
39  this->lifeSpan = 1.0f; /* sec */
40
41  this->remove();
42}
43
44
45/**
46 *  standard deconstructor
47*/
48Projectile::~Projectile ()
49{
50  /*
51     do not delete the test projectModel, since it is pnode
52     and will be cleaned out by world
53  */
54  //delete this->projectileModel;
55}
56
57
58void Projectile::setEnergies(float energyMin, float energyMax)
59{
60  this->energyMin = energyMin;
61  if (energyMax <= energyMin)
62  {
63    this->bChargeable = false;
64    this->energyMax = energyMin;
65  }
66  else
67  {
68    this->bChargeable = true;
69    this->energyMax = energyMax;
70  }
71}
72
73
74/**
75 *  this sets the flight direction of the projectile
76 * @param directin in which to flight
77
78   this function will calculate a vector out of this to be used in the
79   tick function
80*/
81void Projectile::setFlightDirection(const Quaternion& flightDirection)
82{
83  Vector v(1, 0, 0);
84  this->flightDirection = flightDirection.apply(v);
85  this->flightDirection.normalize();
86}
87
88/**
89 *  sets the velocity vector to a spec speed
90 * @param velocity: vector of the velocity
91*/
92void Projectile::setVelocity(const Vector &velocity)
93{
94  //Vector offsetVel =
95  this->velocity = velocity;
96 // offsetVel.normalize();
97  //this->velocity += (offsetVel * 50.0);
98}
99
100/**
101 * signal tick, time dependent things will be handled here
102 * @param time since last tick
103*/
104void Projectile::tick (float time)
105{
106  Vector v = this->velocity * (time);
107  this->shiftCoor(v);
108
109  this->lifeCycle += time/this->lifeSpan;
110  if( this->lifeCycle >= 1)
111  {
112    PRINTF(5)("FINALIZE==========================\n");
113    PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
114    PRINTF(5)("FINALIZE===========================\n");
115    //this->finalize();
116    GarbageCollector::getInstance()->collect(this);
117  }
118}
119
120
121/**
122 *  the function gets called, when the projectile is destroyed
123*/
124void Projectile::destroy ()
125{}
126
127
128void Projectile::draw () const
129{
130  glMatrixMode(GL_MODELVIEW);
131  glPushMatrix();
132
133  float matrix[4][4];
134  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
135  this->getAbsDir().matrix (matrix);
136  glMultMatrixf((float*)matrix);
137  this->model->draw();
138
139  glPopMatrix();
140}
141
Note: See TracBrowser for help on using the repository browser.