Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 2.8 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 */
[4979]40
41  this->remove();
[3573]42}
43
44
[3578]45/**
[4836]46 *  standard deconstructor
[3578]47*/
[4597]48Projectile::~Projectile ()
[3573]49{
[4597]50  /*
51     do not delete the test projectModel, since it is pnode
52     and will be cleaned out by world
[3629]53  */
54  //delete this->projectileModel;
[3573]55}
56
[3578]57
[4948]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
[3578]74/**
[4836]75 *  this sets the flight direction of the projectile
76 * @param directin in which to flight
[3632]77
78   this function will calculate a vector out of this to be used in the
79   tick function
80*/
[4927]81void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]82{
83  Vector v(1, 0, 0);
[4890]84  this->flightDirection = flightDirection.apply(v);
85  this->flightDirection.normalize();
[3632]86}
87
88/**
[4836]89 *  sets the velocity vector to a spec speed
90 * @param velocity: vector of the velocity
[4464]91*/
92void Projectile::setVelocity(const Vector &velocity)
93{
[4955]94  //Vector offsetVel =
95  this->velocity = velocity;
96 // offsetVel.normalize();
97  //this->velocity += (offsetVel * 50.0);
[4464]98}
99
100/**
[4927]101 * signal tick, time dependent things will be handled here
[4836]102 * @param time since last tick
[3578]103*/
[4597]104void Projectile::tick (float time)
[3632]105{
[4464]106  Vector v = this->velocity * (time);
[3686]107  this->shiftCoor(v);
[3683]108
[4890]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");
[4941]115    //this->finalize();
116    GarbageCollector::getInstance()->collect(this);
[4890]117  }
[3632]118}
[3573]119
120
[3578]121/**
[4836]122 *  the function gets called, when the projectile is destroyed
[3578]123*/
[4597]124void Projectile::destroy ()
[3574]125{}
[3573]126
127
[5500]128void Projectile::draw () const
[3573]129{
130  glMatrixMode(GL_MODELVIEW);
131  glPushMatrix();
[3574]132
[4597]133  float matrix[4][4];
[3573]134  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
135  this->getAbsDir().matrix (matrix);
[4597]136  glMultMatrixf((float*)matrix);
[3672]137  this->model->draw();
[3573]138
139  glPopMatrix();
140}
141
Note: See TracBrowser for help on using the repository browser.