Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more small optimisations, and a convenience inline-tick-life-cycle functions for projectiles

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#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  this->target.addNodeModeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT |
41                                PNODE_REPARENT_TO_NULLPARENT);
42
43  this->removeNode();
44}
45
46
47/**
48 *  standard deconstructor
49*/
50Projectile::~Projectile ()
51{
52  /*
53     do not delete the test projectModel, since it is pnode
54     and will be cleaned out by world
55  */
56  //delete this->projectileModel;
57}
58
59
60void Projectile::setEnergies(float energyMin, float energyMax)
61{
62  this->energyMin = energyMin;
63  if (energyMax <= energyMin)
64  {
65    this->bChargeable = false;
66    this->energyMax = energyMin;
67  }
68  else
69  {
70    this->bChargeable = true;
71    this->energyMax = energyMax;
72  }
73}
74
75
76/**
77 *  this sets the flight direction of the projectile
78 * @param directin in which to flight
79
80   this function will calculate a vector out of this to be used in the
81   tick function
82*/
83void Projectile::setFlightDirection(const Quaternion& flightDirection)
84{
85  Vector v(1, 0, 0);
86  this->flightDirection = flightDirection.apply(v);
87  this->flightDirection.normalize();
88}
89
90/**
91 *  sets the velocity vector to a spec speed
92 * @param velocity: vector of the velocity
93*/
94void Projectile::setVelocity(const Vector &velocity)
95{
96  //Vector offsetVel =
97  this->velocity = velocity;
98 // offsetVel.normalize();
99  //this->velocity += (offsetVel * 50.0);
100}
101
102
103
104void Projectile::setTarget(PNode* target)
105{
106  this->target.setParent(target);
107}
108
109
110/**
111 * signal tick, time dependent things will be handled here
112 * @param dt since last tick
113*/
114void Projectile::tick (float dt)
115{
116  Vector v = this->velocity * (dt);
117  this->shiftCoor(v);
118
119  if (this->tickLifeCycle(dt))
120    this->destroy();
121}
122
123
124/**
125 *  the function gets called, when the projectile is destroyed
126*/
127void Projectile::destroy ()
128{}
129
Note: See TracBrowser for help on using the repository browser.