Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/weapons/heavy_blaster.cc @ 10485

Last change on this file since 10485 was 10485, checked in by nicolasc, 17 years ago

2nd weapon anim fix

File size: 8.3 KB
Line 
1#include "heavy_blaster.h"
2#include "world_entities/projectiles/projectile.h"
3
4#include "world_entity.h"
5#include "static_model.h"
6#include "weapon_manager.h"
7#include "util/loading/factory.h"
8
9#include "animation3d.h"
10
11#include "loading/fast_factory.h"
12
13CREATE_FACTORY(HeavyBlaster);
14/**
15 * Standard constructor
16 */
17HeavyBlaster::HeavyBlaster (int leftRight)
18 : Weapon()
19{
20    this->init(leftRight);
21}
22
23HeavyBlaster::HeavyBlaster (const TiXmlElement* root = NULL)
24 : Weapon()
25{
26    // TODO add leftRight to params
27    this->init(0);
28    if (root != NULL)
29      this->loadParams(root);
30}
31
32/**
33 * Default destructor
34 */
35HeavyBlaster::~HeavyBlaster()
36{
37  for (int i = 0; i < this->getBarrels(); i++)
38  {
39   delete [] this->shootAnim[i];
40   delete [] this->objComp[i];
41  }
42  delete [] this->emissionPoint;
43
44   delete [] this->shootAnim;
45   delete [] this->objComp;
46/*
47    for(int j = 0; j < this->getSegs(); j++)
48    {
49      delete this->shootAnim[i][j];
50      delete this->objComp[i][j];
51    }
52    delete this->shootAnim[i];
53    delete this->objComp[i];
54    delete this->emissionPoint[i];
55  }*/
56
57//  this->deconstr();
58     // model will be deleted from WorldEntity-destructor
59}
60
61void HeavyBlaster::loadParams(const TiXmlElement* root)
62{
63  Weapon::loadParams(root);
64}
65
66void HeavyBlaster::init(int leftRight)
67{
68
69  this->leftRight = leftRight;
70  //this->registerObject(this, HeavyBlaster::_objectList);
71
72//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
73
74  this->loadModel("models/guns/frag_cannon.obj", .4);
75
76
77  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
78  this->setStateDuration(WS_RELOADING, 0);
79  this->setStateDuration(WS_ACTIVATING, .5);
80  this->setStateDuration(WS_DEACTIVATING, 1);
81
82  this->setEnergyMax(500);
83  this->increaseEnergy(500);
84  //this->minCharge = 2;
85
86  this->setActionSound(WA_SHOOT, "sounds/guns/laser.wav");
87//   this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
88  this->setActionSound(WA_RELOAD, "sounds/spawn/alien_generator.wav");
89
90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
91  this->setProjectileTypeC("HBolt");
92  this->prepareProjectiles(5);
93
94  this->setBarrels(3);
95  this->setSegs(2);
96  this->activeBarrel = 0;
97
98
99
100  this->objComp = new PNode**[this->getBarrels()];
101  this->emissionPoint = new PNode*[this->getBarrels()];
102  this->shootAnim = new Animation3D**[this->getBarrels()];
103  for (int i = 0; i < this->getBarrels(); i++)
104  {
105    this->objComp[i] = new PNode* [this->getSegs()];
106    this->emissionPoint[i] = new PNode;
107    this->emissionPoint[i]->setParent(this);             //< One EmissionPoint, that is a PNode connected to the weapon. You can set this to the exitting point of the Projectiles
108    this->emissionPoint[i]->setName("EmissionPoint");
109    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
110    this->shootAnim[i] = new Animation3D* [this->getSegs()];
111    for(int j = 0; j < this->getSegs(); j++)
112    {
113      this->objComp[i][j] = new PNode;
114      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
115      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
116    }
117  }
118
119  if (this->leftRight == W_RIGHT)
120  {
121    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
122    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
123    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
124  }
125  else {
126    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, -.06));
127    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, -.14));
128    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, 0.14));
129  }
130
131
132//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
133//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
134//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
135//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
136//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
137//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
138
139
140//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
141//   animB1Shoot->setInfinity(ANIM_INF_CONSTANT);
142//   animB2Shoot->setInfinity(ANIM_INF_CONSTANT);
143//   animT0Shoot->setInfinity(ANIM_INF_CONSTANT);
144//   animT1Shoot->setInfinity(ANIM_INF_CONSTANT);
145//   animT2Shoot->setInfinity(ANIM_INF_CONSTANT);
146
147  for (int i = 0; i < this->getBarrels(); i++){
148    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
149    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 0.9, ANIM_LINEAR, ANIM_NULL);
150    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.55, ANIM_LINEAR, ANIM_NULL);
151
152    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.05, ANIM_LINEAR, ANIM_NULL);
153    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.2, ANIM_LINEAR, ANIM_NULL);
154    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.25, ANIM_LINEAR, ANIM_NULL);
155  }
156
157  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
158  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
159
160  animation2->setInfinity(ANIM_INF_CONSTANT);
161  animation3->setInfinity(ANIM_INF_CONSTANT);
162
163//   this->setEmissionPoint(3.8, 1.2, 0, 0);
164
165  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
166  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
167
168  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
169  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
170}
171
172
173void HeavyBlaster::fire()
174{
175  Projectile* pj =  this->getProjectile();
176  if (pj == NULL)
177    return;
178
179  // set the owner
180  pj->setOwner(this->getOwner());
181  pj->setParent(PNode::getNullParent());
182
183//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
184//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
185  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
186
187  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
188//   pj->setAbsCoor(this->getEmissionPoint(0));
189  pj->setAbsDir(this->getAbsDir());
190//   pj->toList(OM_GROUP_01_PROJ);
191  pj->activate();
192
193  // initiate animation
194  for (int i = 0; i < this->getSegs(); i++)
195    this->shootAnim[this->activeBarrel][i]->replay();
196
197  // switch barrel
198  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
199}
200
201/**
202 *  this activates the weapon
203*/
204void HeavyBlaster::activate()
205{
206}
207
208/**
209 *  this deactivates the weapon
210*/
211void HeavyBlaster::deactivate()
212{
213}
214
215
216void HeavyBlaster::draw() const
217{
218  glMatrixMode(GL_MODELVIEW);
219  glPushMatrix();
220  glTranslatef (this->getAbsCoor ().x,
221                this->getAbsCoor ().y,
222                this->getAbsCoor ().z);
223
224  if (this->leftRight == W_LEFT)
225    glScalef(1.0, 1.0, -1.0);
226
227  static_cast<StaticModel*>(this->getModel())->draw(6);
228
229  glPushMatrix();
230    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
231    static_cast<StaticModel*>(this->getModel())->draw(2);
232  glPopMatrix();
233
234  glPushMatrix();
235    glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
236    static_cast<StaticModel*>(this->getModel())->draw(3);
237  glPopMatrix();
238
239  glPushMatrix();
240    glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
241    static_cast<StaticModel*>(this->getModel())->draw(1);
242  glPopMatrix();
243
244  glPushMatrix();
245    glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
246    static_cast<StaticModel*>(this->getModel())->draw(4);
247  glPopMatrix();
248
249  glPushMatrix();
250    glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
251    static_cast<StaticModel*>(this->getModel())->draw(5);
252  glPopMatrix();
253
254  glPushMatrix();
255    glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
256    static_cast<StaticModel*>(this->getModel())->draw(0);
257  glPopMatrix();
258
259  glPopMatrix();
260}
Note: See TracBrowser for help on using the repository browser.