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
RevLine 
[3573]1
2
[4597]3/*
[3573]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
[4597]15   co-programmer:
[3573]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3573]18
19#include "projectile.h"
[3618]20
[3573]21#include "world_entity.h"
[3683]22#include "weapon.h"
[3646]23#include "null_parent.h"
[3678]24#include "model.h"
[3573]25
[4941]26#include "garbage_collector.h"
27
[3573]28using namespace std;
29
30
[3578]31/**
[4836]32 *  standard constructor
[3578]33*/
[4932]34Projectile::Projectile () : WorldEntity()
[3573]35{
[4322]36  this->setClassID(CL_PROJECTILE, "Projectile");
[4597]37
[4890]38  this->lifeCycle = 0.0;
[5063]39  this->lifeSpan = 1.0f; /* sec */
[6054]40  this->target.addNodeModeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT |
41                                PNODE_REPARENT_TO_NULLPARENT);
[4979]42
[5769]43  this->removeNode();
[3573]44}
45
46
[3578]47/**
[4836]48 *  standard deconstructor
[3578]49*/
[4597]50Projectile::~Projectile ()
[3573]51{
[4597]52  /*
53     do not delete the test projectModel, since it is pnode
54     and will be cleaned out by world
[3629]55  */
56  //delete this->projectileModel;
[3573]57}
58
[3578]59
[4948]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
[3578]76/**
[4836]77 *  this sets the flight direction of the projectile
78 * @param directin in which to flight
[3632]79
80   this function will calculate a vector out of this to be used in the
81   tick function
82*/
[4927]83void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]84{
85  Vector v(1, 0, 0);
[4890]86  this->flightDirection = flightDirection.apply(v);
87  this->flightDirection.normalize();
[3632]88}
89
90/**
[4836]91 *  sets the velocity vector to a spec speed
92 * @param velocity: vector of the velocity
[4464]93*/
94void Projectile::setVelocity(const Vector &velocity)
95{
[4955]96  //Vector offsetVel =
97  this->velocity = velocity;
98 // offsetVel.normalize();
99  //this->velocity += (offsetVel * 50.0);
[4464]100}
101
[5766]102
103
104void Projectile::setTarget(PNode* target)
105{
[6054]106  this->target.setParent(target);
[5766]107}
108
109
[4464]110/**
[4927]111 * signal tick, time dependent things will be handled here
[6056]112 * @param dt since last tick
[3578]113*/
[6056]114void Projectile::tick (float dt)
[3632]115{
[6056]116  Vector v = this->velocity * (dt);
[3686]117  this->shiftCoor(v);
[3683]118
[6056]119  if (this->tickLifeCycle(dt))
120    this->destroy();
[3632]121}
[3573]122
123
[3578]124/**
[4836]125 *  the function gets called, when the projectile is destroyed
[3578]126*/
[4597]127void Projectile::destroy ()
[3574]128{}
[3573]129
Note: See TracBrowser for help on using the repository browser.