Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: debug-information for ResourceManager

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