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 "test_bullet.h" |
---|
20 | |
---|
21 | #include "model.h" |
---|
22 | #include "vector.h" |
---|
23 | #include "garbage_collector.h" |
---|
24 | #include "fast_factory.h" |
---|
25 | |
---|
26 | #include "obb_tree.h" |
---|
27 | |
---|
28 | using namespace std; |
---|
29 | |
---|
30 | CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET); |
---|
31 | |
---|
32 | /** |
---|
33 | * standard constructor |
---|
34 | */ |
---|
35 | TestBullet::TestBullet () : Projectile() |
---|
36 | { |
---|
37 | this->setClassID(CL_TEST_BULLET, "TestBullet"); |
---|
38 | |
---|
39 | float modelSize = .3; |
---|
40 | this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3); |
---|
41 | |
---|
42 | this->energyMin = 1; |
---|
43 | this->energyMax = 10; |
---|
44 | this->remove(); |
---|
45 | this->lifeSpan = 5; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | /** |
---|
50 | * standard deconstructor |
---|
51 | */ |
---|
52 | TestBullet::~TestBullet () |
---|
53 | { |
---|
54 | /* |
---|
55 | do not delete the test projectModel, since it is pnode |
---|
56 | and will be cleaned out by world |
---|
57 | */ |
---|
58 | //delete this->projectileModel; |
---|
59 | } |
---|
60 | |
---|
61 | void TestBullet::collidesWith(WorldEntity* entity, const Vector& location) |
---|
62 | { |
---|
63 | this->destroy(); |
---|
64 | } |
---|
65 | |
---|
66 | /** |
---|
67 | * signal tick, time dependent things will be handled here |
---|
68 | * @param time since last tick |
---|
69 | */ |
---|
70 | void TestBullet::tick (float time) |
---|
71 | { |
---|
72 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
73 | Vector v = this->velocity * (time); |
---|
74 | this->shiftCoor(v); |
---|
75 | |
---|
76 | this->lifeCycle += time/this->lifeSpan; |
---|
77 | if( this->lifeCycle >= 1) |
---|
78 | { |
---|
79 | PRINTF(5)("FINALIZE==========================\n"); |
---|
80 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
81 | PRINTF(5)("FINALIZE===========================\n"); |
---|
82 | // this->finalize(); |
---|
83 | GarbageCollector::getInstance()->collect(this); |
---|
84 | this->lifeCycle = 0.0; //! @todo should not be here |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * the function gets called, when the projectile is destroyed |
---|
90 | */ |
---|
91 | void TestBullet::destroy () |
---|
92 | { |
---|
93 | |
---|
94 | |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | void TestBullet::draw () |
---|
99 | { |
---|
100 | glMatrixMode(GL_MODELVIEW); |
---|
101 | glPushMatrix(); |
---|
102 | |
---|
103 | float matrix[4][4]; |
---|
104 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
105 | this->getAbsDir().matrix (matrix); |
---|
106 | glMultMatrixf((float*)matrix); |
---|
107 | glScalef(2.0, 2.0, 2.0); |
---|
108 | this->model->draw(); |
---|
109 | |
---|
110 | glPopMatrix(); |
---|
111 | } |
---|
112 | |
---|