Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/world_entities/projectile.cc @ 3766

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

orxonox/branches/textEngine: merged trunk here.
merged with command:
svn merge ../trunk textEngine -r 3467:HEAD
no conflicts

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