Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

finished animation on heavy blaster, started light blaster
code needs some cleanup

File size: 7.7 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  this->deconstr();
38     // model will be deleted from WorldEntity-destructor
39}
40
41void HeavyBlaster::loadParams(const TiXmlElement* root)
42{
43  Weapon::loadParams(root);
44}
45
46void HeavyBlaster::init(int leftRight)
47{
48
49  this->leftRight = leftRight;
50  //this->registerObject(this, HeavyBlaster::_objectList);
51
52//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
53
54  this->loadModel("models/guns/fragcannon.obj", .4);
55 
56
57  this->setStateDuration(WS_SHOOTING, 0.5);   // 2 Schuss pro Sekunde
58  this->setStateDuration(WS_RELOADING, 0);
59  this->setStateDuration(WS_ACTIVATING, .5);
60  this->setStateDuration(WS_DEACTIVATING, 1);
61
62  this->setEnergyMax(500);
63  this->increaseEnergy(500);
64  //this->minCharge = 2;
65
66  this->setActionSound(WA_SHOOT, "sound/laser.wav");
67  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
68  this->setActionSound(WA_RELOAD, "sound/spawn/alien_generator.wav");
69
70  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_LIGHT);
71  this->setProjectileTypeC("HBolt");   // FIXME temp project type until the blaste class exist
72  this->prepareProjectiles(5);
73
74  this->setBarrels(3);
75  this->setSegs(2);
76  this->activeBarrel = 0;
77//   this->init2();
78
79
80
81  this->objComp = new PNode**[this->getBarrels()];
82  this->emissionPoint = new PNode*[this->getBarrels()];
83  this->shootAnim = new Animation3D**[this->getBarrels()];
84  for (int i = 0; i < this->getBarrels(); i++)
85  {
86    this->objComp[i] = new PNode* [this->getSegs()];
87    this->emissionPoint[i] = new PNode;
88    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
89    this->emissionPoint[i]->setName("EmissionPoint");
90    this->emissionPoint[i]->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT);
91    this->shootAnim[i] = new Animation3D* [this->getSegs()];
92    for(int j = 0; j < this->getSegs(); j++)
93    {
94      this->objComp[i][j] = new PNode;
95      this->shootAnim[i][j] = new Animation3D(this->objComp[i][j]);
96      this->shootAnim[i][j]->setInfinity(ANIM_INF_CONSTANT);
97    }
98  }
99
100    this->emissionPoint[0]->setRelCoor(Vector(1.1, 0.14, 0.06));
101    this->emissionPoint[1]->setRelCoor(Vector(1.1, -.06, 0.14));
102    this->emissionPoint[2]->setRelCoor(Vector(1.1, 0.06, -.14));
103
104
105//   Animation3D* animB0Shoot = this->getAnimation(WS_SHOOTING0, this->objComp[0][0]);
106//   Animation3D* animB1Shoot = this->getAnimation(WS_SHOOTING1, this->objComp2);
107//   Animation3D* animB2Shoot = this->getAnimation(WS_SHOOTING2, this->objComp3);
108//   Animation3D* animT0Shoot = this->getAnimation(WS_SHOOTING3, this->objComp[0][1]);
109//   Animation3D* animT1Shoot = this->getAnimation(WS_SHOOTING4, this->objComp5);
110//   Animation3D* animT2Shoot = this->getAnimation(WS_SHOOTING5, this->objComp6);
111
112
113//   this->shootAnim[0][0]->setInfinity(ANIM_INF_CONSTANT);
114//   animB1Shoot->setInfinity(ANIM_INF_CONSTANT);
115//   animB2Shoot->setInfinity(ANIM_INF_CONSTANT);
116//   animT0Shoot->setInfinity(ANIM_INF_CONSTANT);
117//   animT1Shoot->setInfinity(ANIM_INF_CONSTANT);
118//   animT2Shoot->setInfinity(ANIM_INF_CONSTANT);
119
120  for (int i = 0; i < this->getBarrels(); i++){
121    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
122    this->shootAnim[i][0]->addKeyFrame(Vector(-0.3, 0.0, 0.0), Quaternion(), 1.0, ANIM_LINEAR, ANIM_NULL);
123    this->shootAnim[i][0]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.4, ANIM_LINEAR, ANIM_NULL);
124
125    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
126    this->shootAnim[i][1]->addKeyFrame(Vector(-0.4, 0.0, 0.0), Quaternion(), 1.0, ANIM_LINEAR, ANIM_NULL);
127    this->shootAnim[i][1]->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.4, ANIM_LINEAR, ANIM_NULL);
128  }
129
130  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
131  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
132
133  animation2->setInfinity(ANIM_INF_CONSTANT);
134  animation3->setInfinity(ANIM_INF_CONSTANT);
135
136//   this->setEmissionPoint(3.8, 1.2, 0, 0);
137
138  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
139  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
140
141  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.5, ANIM_LINEAR, ANIM_NULL);
142  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
143}
144
145
146void HeavyBlaster::fire()
147{
148  Projectile* pj =  this->getProjectile();
149  if (pj == NULL)
150    return;
151
152  // set the owner
153  pj->setOwner(this->getOwner());
154  pj->setParent(PNode::getNullParent());
155
156//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
157//   pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
158  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*130 + VECTOR_RAND(1));
159
160  pj->setAbsCoor(this->emissionPoint[this->activeBarrel]->getAbsCoor());
161//   pj->setAbsCoor(this->getEmissionPoint(0));
162  pj->setAbsDir(this->getAbsDir());
163//   pj->toList(OM_GROUP_01_PROJ);
164  pj->activate();
165
166  // initiate animation
167  for (int i = 0; i < this->getSegs(); i++)
168    this->shootAnim[this->activeBarrel][i]->replay();
169
170  // switch barrel
171  this->activeBarrel = (this->activeBarrel + 1) % this->getBarrels();
172}
173
174/**
175 *  this activates the weapon
176*/
177void HeavyBlaster::activate()
178{
179}
180
181/**
182 *  this deactivates the weapon
183*/
184void HeavyBlaster::deactivate()
185{
186}
187
188
189void HeavyBlaster::draw() const
190{
191  glMatrixMode(GL_MODELVIEW);
192  glPushMatrix();
193  glTranslatef (this->getAbsCoor ().x,
194                this->getAbsCoor ().y,
195                this->getAbsCoor ().z);
196
197  if (this->leftRight == W_LEFT)
198    glScalef(1.0, 1.0, -1.0);
199
200  static_cast<StaticModel*>(this->getModel())->draw(6);
201
202  glPushMatrix();
203    glTranslatef (this->objComp[0][0]->getAbsCoor().x, this->objComp[0][0]->getAbsCoor().y, this->objComp[0][0]->getAbsCoor().z);
204    static_cast<StaticModel*>(this->getModel())->draw(1);
205  glPopMatrix();
206
207  glPushMatrix();
208  glTranslatef (this->objComp[1][0]->getAbsCoor().x, this->objComp[1][0]->getAbsCoor().y, this->objComp[1][0]->getAbsCoor().z);
209  static_cast<StaticModel*>(this->getModel())->draw(2);
210  glPopMatrix();
211
212  glPushMatrix();
213  glTranslatef (this->objComp[2][0]->getAbsCoor().x, this->objComp[2][0]->getAbsCoor().y, this->objComp[2][0]->getAbsCoor().z);
214  static_cast<StaticModel*>(this->getModel())->draw(0);
215  glPopMatrix();
216
217  glPushMatrix();
218  glTranslatef (this->objComp[0][1]->getAbsCoor().x, this->objComp[0][1]->getAbsCoor().y, this->objComp[0][1]->getAbsCoor().z);
219    static_cast<StaticModel*>(this->getModel())->draw(4);
220  glPopMatrix();
221
222  glPushMatrix();
223  glTranslatef (this->objComp[1][1]->getAbsCoor().x, this->objComp[1][1]->getAbsCoor().y, this->objComp[1][1]->getAbsCoor().z);
224  static_cast<StaticModel*>(this->getModel())->draw(5);
225  glPopMatrix();
226
227  glPushMatrix();
228  glTranslatef (this->objComp[2][1]->getAbsCoor().x, this->objComp[2][1]->getAbsCoor().y, this->objComp[2][1]->getAbsCoor().z);
229  static_cast<StaticModel*>(this->getModel())->draw(3);
230  glPopMatrix();
231
232  glPopMatrix();
233}
Note: See TracBrowser for help on using the repository browser.