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
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*/
17
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#include "vector.h"
26
[4941]27#include "garbage_collector.h"
28
[3573]29using namespace std;
30
31
[3578]32/**
[4836]33 *  standard constructor
[3578]34*/
[4932]35Projectile::Projectile () : WorldEntity()
[3573]36{
[4322]37  this->setClassID(CL_PROJECTILE, "Projectile");
[4597]38
[4890]39  this->lifeCycle = 0.0;
40  this->lifeSpan = 0.75f; /* sec */
[3573]41}
42
43
[3578]44/**
[4836]45 *  standard deconstructor
[3578]46*/
[4597]47Projectile::~Projectile ()
[3573]48{
[4597]49  /*
50     do not delete the test projectModel, since it is pnode
51     and will be cleaned out by world
[3629]52  */
53  //delete this->projectileModel;
[3573]54}
55
[3578]56
57/**
[4836]58 *  this sets the flight direction of the projectile
59 * @param directin in which to flight
[3632]60
61   this function will calculate a vector out of this to be used in the
62   tick function
63*/
[4927]64void Projectile::setFlightDirection(const Quaternion& flightDirection)
[3632]65{
66  Vector v(1, 0, 0);
[4890]67  this->flightDirection = flightDirection.apply(v);
68  this->flightDirection.normalize();
[3632]69}
70
71/**
[4836]72 *  sets the velocity vector to a spec speed
73 * @param velocity: vector of the velocity
[4464]74*/
75void Projectile::setVelocity(const Vector &velocity)
76{
[4890]77  Vector offsetVel = this->velocity = velocity;
78  offsetVel.normalize();
79  this->velocity += (offsetVel * 50.0);
[4464]80}
81
82/**
[4927]83 * signal tick, time dependent things will be handled here
[4836]84 * @param time since last tick
[3578]85*/
[4597]86void Projectile::tick (float time)
[3632]87{
[4464]88  Vector v = this->velocity * (time);
[3686]89  this->shiftCoor(v);
[3683]90
[4890]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");
[4941]97    //this->finalize();
98    GarbageCollector::getInstance()->collect(this);
[4890]99  }
[3632]100}
[3573]101
102
[3578]103/**
[4836]104 *  the function gets called, when the projectile is destroyed
[3578]105*/
[4597]106void Projectile::destroy ()
[3574]107{}
[3573]108
109
[4597]110void Projectile::draw ()
[3573]111{
112  glMatrixMode(GL_MODELVIEW);
113  glPushMatrix();
[3574]114
[4597]115  float matrix[4][4];
[3573]116  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
117  this->getAbsDir().matrix (matrix);
[4597]118  glMultMatrixf((float*)matrix);
[3672]119  this->model->draw();
[3573]120
121  glPopMatrix();
122}
123
Note: See TracBrowser for help on using the repository browser.