Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some smaller fixes, to make Weapon more local

File size: 2.5 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->lifeCycle = 0.0;
39  this->lifeSpan = 0.75f; /* sec */
40}
41
42
43/**
44 *  standard deconstructor
45*/
46Projectile::~Projectile ()
47{
48  /*
49     do not delete the test projectModel, since it is pnode
50     and will be cleaned out by world
51  */
52  //delete this->projectileModel;
53}
54
55
56/**
57 *  this sets the flight direction of the projectile
58 * @param directin in which to flight
59
60   this function will calculate a vector out of this to be used in the
61   tick function
62*/
63void Projectile::setFlightDirection(const Quaternion& flightDirection)
64{
65  Vector v(1, 0, 0);
66  this->flightDirection = flightDirection.apply(v);
67  this->flightDirection.normalize();
68}
69
70/**
71 *  sets the velocity vector to a spec speed
72 * @param velocity: vector of the velocity
73*/
74void Projectile::setVelocity(const Vector &velocity)
75{
76  Vector offsetVel = this->velocity = velocity;
77  offsetVel.normalize();
78  this->velocity += (offsetVel * 50.0);
79}
80
81/**
82 * signal tick, time dependent things will be handled here
83 * @param time since last tick
84*/
85void Projectile::tick (float time)
86{
87  Vector v = this->velocity * (time);
88  this->shiftCoor(v);
89
90  this->lifeCycle += time/this->lifeSpan;
91  if( this->lifeCycle >= 1)
92  {
93    PRINTF(5)("FINALIZE==========================\n");
94    PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
95    PRINTF(5)("FINALIZE===========================\n");
96    this->finalize();
97  }
98}
99
100
101/**
102 *  the function gets called, when the projectile is destroyed
103*/
104void Projectile::destroy ()
105{}
106
107
108void Projectile::draw ()
109{
110  glMatrixMode(GL_MODELVIEW);
111  glPushMatrix();
112
113  float matrix[4][4];
114  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
115  this->getAbsDir().matrix (matrix);
116  glMultMatrixf((float*)matrix);
117  this->model->draw();
118
119  glPopMatrix();
120}
121
Note: See TracBrowser for help on using the repository browser.