Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: renamed all the \param → @param and so on in Doxygen tags.
Thanks a lot to the kDevelop team. this took since the last commit :)

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