Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3686 was 3686, checked in by patrick, 19 years ago

orxonox/trunk: fixed speed issue, was a problem with the current track defined in the debug level

File size: 3.5 KB
RevLine 
[3573]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
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
27using namespace std;
28
29
[3578]30/**
31   \brief standard constructor
32*/
[3683]33Projectile::Projectile (Weapon* weapon) : WorldEntity()
[3573]34{
[3676]35  this->model = (Model*)ResourceManager::getInstance()->load("sphere", PRIM, RP_LEVEL);
[3683]36  this->weapon = weapon;
[3632]37  this->flightDirection = NULL;
[3646]38  this->currentLifeTime = 0.0f;
[3685]39  this->ttl = 0.75f; /* sec */
[3670]40  this->speed = 2.0f;
[3573]41}
42
43
[3578]44/**
45   \brief standard deconstructor
46*/
[3573]47Projectile::~Projectile () 
48{
[3629]49  /*
50     do not delete the test projectModel, since it is pnode
51     and will be cleaned out by world
52  */
53  //delete this->projectileModel;
[3573]54}
55
[3578]56
57/**
[3632]58   \brief this sets the flight direction of the projectile
59   \param directin in which to flight
60
61   this function will calculate a vector out of this to be used in the
62   tick function
63*/
64void Projectile::setFlightDirection(Quaternion* flightDirection)
65{
66  if( this->flightDirection == NULL)
67    this->flightDirection = new Vector();
68  Vector v(1, 0, 0);
69  *this->flightDirection = flightDirection->apply(v);
[3683]70  this->flightDirection->normalize();
[3632]71}
72
73
74/**
[3646]75   \brief this sets the time to life of the projectile
76   \param ttl in second
77
78   after this life time, the projectile will garbage collect itself
79*/
80void Projectile::setTTL(float ttl)
81{
82  this->ttl = ttl;
83}
84
85
86/**
[3670]87   \brief sets the speed of the projectile
88*/
89void Projectile::setSpeed(float speed)
90{
[3685]91  this->speed = speed * 3;
92  PRINTF(4)("Projectile::setting speed to: %f\n", this->speed);
[3670]93}
94
95/**
[3578]96   \brief signal tick, time dependent things will be handled here
97   \param time since last tick
98*/
[3574]99void Projectile::tick (float time) 
[3632]100{
[3686]101  this->speed = this->weapon->getSpeed() * 3; 
102  Vector v;
103  v = *this->flightDirection * this->speed * time;
104  this->shiftCoor(v);
105  //printf("PROJECTILE: current direction is:    (%f, %f, %f)\n",this->flightDirection->x, this->flightDirection->y, this->flightDirection->z );
106  //printf("PROJECTILE: current shift vector is: (%f, %f, %f)\n", v.x, v.y, v.z);
107  //printf("PROJECTILE: current speed is: %f\n", this->speed);
108  //printf("PROJECTILE: current dt is:    %f\n", time);
109  //this->debug();
[3683]110
[3646]111  this->currentLifeTime += time;
[3685]112  if( this->ttl < this->currentLifeTime)
113    {
114      PRINTF(5)("FINALIZE=============================================================\n");
115      PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl);
116      PRINTF(5)("FINALIZE=============================================================\n");
117      this->finalize();
[3686]118      this->currentLifeTime = 0.0f;
[3685]119    }
[3632]120}
[3573]121
[3578]122/**
123   \brief the projectile gets hit by another entity
124   \param the other entity
125   \param place where it is hit
126*/
127void Projectile::hit (WorldEntity* entity, Vector* place) 
[3574]128{}
[3573]129
[3578]130
131/**
132   \brief the function gets called, when the projectile is destroyed
133*/
[3574]134void Projectile::destroy () 
135{}
[3573]136
137
138void Projectile::draw () 
139{
140  glMatrixMode(GL_MODELVIEW);
141  glPushMatrix();
[3574]142
143  float matrix[4][4]; 
[3573]144  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
145  this->getAbsDir().matrix (matrix);
[3574]146  glMultMatrixf((float*)matrix); 
[3672]147  this->model->draw();
[3573]148
149  glPopMatrix();
150}
151
Note: See TracBrowser for help on using the repository browser.