Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4475 was 4464, checked in by patrick, 20 years ago

orxonox/trunk: reimplemented the shoot speed function

File size: 3.3 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   \brief standard constructor
32*/
33Projectile::Projectile (Weapon* weapon) : WorldEntity()
34{
35  this->setClassID(CL_PROJECTILE, "Projectile");
36  this->weapon = weapon;
37  this->flightDirection = NULL;
38  this->currentLifeTime = 0.0f;
39  this->ttl = 0.75f; /* sec */
40  this->speed = 2.0f;
41}
42
43
44/**
45   \brief standard deconstructor
46*/
47Projectile::~Projectile () 
48{
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;
54}
55
56
57/**
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);
70  this->flightDirection->normalize();
71}
72
73
74/**
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/**
87   \brief sets the speed of the projectile
88*/
89void Projectile::setSpeed(float speed)
90{
91  this->speed = speed * 3; /* fix speed settings */
92  PRINTF(4)("Projectile::setting speed to: %f\n", this->speed);
93}
94
95
96/**
97   \brief sets the velocity vector to a spec speed
98   \param velocity: vector of the velocity
99*/
100void Projectile::setVelocity(const Vector &velocity)
101{
102  this->offsetVel = this->velocity = velocity;
103  this->offsetVel.normalize();
104  this->velocity += (this->offsetVel * 50.0);
105}
106
107
108/**
109   \brief signal tick, time dependent things will be handled here
110   \param time since last tick
111*/
112void Projectile::tick (float time) 
113{
114  Vector v = this->velocity * (time);
115  this->shiftCoor(v);
116
117  this->currentLifeTime += time;
118  if( this->ttl < this->currentLifeTime)
119    {
120      PRINTF(5)("FINALIZE==========================\n");
121      PRINTF(5)("current life time is: %f/%f\n", this->currentLifeTime, this->ttl);
122      PRINTF(5)("FINALIZE===========================\n");
123      this->finalize();
124      this->currentLifeTime = 0.0f;
125    }
126}
127
128/**
129   \brief the projectile gets hit by another entity
130   \param the other entity
131   \param place where it is hit
132*/
133void Projectile::hit (WorldEntity* entity, Vector* place) 
134{}
135
136
137/**
138   \brief the function gets called, when the projectile is destroyed
139*/
140void Projectile::destroy () 
141{}
142
143
144void Projectile::draw () 
145{
146  glMatrixMode(GL_MODELVIEW);
147  glPushMatrix();
148
149  float matrix[4][4]; 
150  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
151  this->getAbsDir().matrix (matrix);
152  glMultMatrixf((float*)matrix); 
153  this->model->draw();
154
155  glPopMatrix();
156}
157
Note: See TracBrowser for help on using the repository browser.