Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/weapons/laser_cannon.cc @ 9149

Last change on this file since 9149 was 9131, checked in by bensch, 18 years ago

added laser_cannon

File size: 6.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Patrick Boenzli
13   co-programmer:
14
15
16   @todo: direction in which the projectile flights
17   @todo: a target to set/hit
18*/
19#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
20
21#include "laser_cannon.h"
22#include "world_entities/projectiles/projectile.h"
23
24#include "world_entity.h"
25#include "static_model.h"
26#include "weapon_manager.h"
27#include "util/loading/factory.h"
28
29#include "animation3d.h"
30
31#include "fast_factory.h"
32
33CREATE_FACTORY(LaserCannon, CL_LASER_CANNON);
34
35/**
36 *  standard constructor
37
38   creates a new weapon
39*/
40LaserCannon::LaserCannon ( int leftRight)
41  : Weapon()
42{
43  this->init();
44
45
46  this->leftRight = leftRight;
47
48  this->objectComponent1 = new PNode();
49  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
50  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
51  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
52  //parent->addChild(this->objectComponent1, PNODE_ALL);
53  this->addChild(this->objectComponent1);
54
55  animation1->setInfinity(ANIM_INF_CONSTANT);
56  animation2->setInfinity(ANIM_INF_CONSTANT);
57  animation3->setInfinity(ANIM_INF_CONSTANT);
58
59  if( this->leftRight == W_LEFT)
60  {
61    this->setEmissionPoint(1.0, -0.6, -0.2);
62
63    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
64    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
65    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
66
67    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
68    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
69
70    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
71    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
72  }
73  else if( this->leftRight == W_RIGHT)
74  {
75    this->setEmissionPoint(1.0, -0.6, 0.3);
76
77    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
78    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
79    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
80    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
81
82    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
83    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
84
85    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
86    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
87  }
88}
89
90
91LaserCannon::LaserCannon(const TiXmlElement* root)
92{
93  this->init();
94  if (root != NULL)
95    this->loadParams(root);
96}
97
98/**
99 *  standard deconstructor
100*/
101LaserCannon::~LaserCannon ()
102{
103  // model will be deleted from WorldEntity-destructor
104}
105
106
107void LaserCannon::init()
108{
109  this->setClassID(CL_LASER_CANNON, "LaserCannon");
110
111//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/laser_cannon.obj", OBJ, RP_CAMPAIGN);
112
113  this->loadModel("models/guns/laser_cannon.obj");
114
115  this->setStateDuration(WS_SHOOTING, .1);
116  this->setStateDuration(WS_RELOADING, .1);
117  this->setStateDuration(WS_ACTIVATING, .4);
118  this->setStateDuration(WS_DEACTIVATING, .4);
119
120  this->setEnergyMax(10000);
121  this->increaseEnergy(10000);
122  //this->minCharge = 2;
123
124  this->setActionSound(WA_SHOOT, "sound/laser.wav");
125  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
126
127
128  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
129  this->setProjectileType(CL_LASER);
130  this->prepareProjectiles(100);
131
132}
133
134
135void LaserCannon::loadParams(const TiXmlElement* root)
136{
137  Weapon::loadParams(root);
138
139}
140
141
142/**
143 *  this activates the weapon
144
145   This is needed, since there can be more than one weapon on a ship. the
146   activation can be connected with an animation. for example the weapon is
147   been armed out.
148*/
149void LaserCannon::activate()
150{
151}
152
153
154/**
155 *  this deactivates the weapon
156
157   This is needed, since there can be more than one weapon on a ship. the
158   activation can be connected with an animation. for example the weapon is
159   been armed out.
160*/
161void LaserCannon::deactivate()
162{
163}
164
165
166/**
167 *  fires the weapon
168
169   this is called from the player.cc, when fire-button is been pushed
170   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
171*/
172void LaserCannon::fire()
173{
174  Projectile* pj =  this->getProjectile();
175  if (pj == NULL)
176    return;
177
178  pj->setParent(PNode::getNullParent());
179
180  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
181
182  pj->setAbsCoor(this->getEmissionPoint());
183  pj->setAbsDir(this->getAbsDir());
184  pj->activate();
185}
186
187
188
189/**
190 *  this will draw the weapon
191*/
192void LaserCannon::draw () const
193{
194  /* draw gun body */
195  glMatrixMode(GL_MODELVIEW);
196  glPushMatrix();
197  glTranslatef (this->getAbsCoor ().x,
198                this->getAbsCoor ().y,
199                this->getAbsCoor ().z);
200
201  Vector tmpRot = this->getAbsDir().getSpacialAxis();
202  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
203
204  if( this->leftRight == W_RIGHT)
205    glScalef(1.0, 1.0, -1.0);
206  static_cast<StaticModel*>(this->getModel())->draw(1);
207  glPopMatrix();
208
209  /* draw objectComponent1: gun coil - animated stuff */
210  glPushMatrix();
211  glTranslatef (this->objectComponent1->getAbsCoor ().x,
212                this->objectComponent1->getAbsCoor ().y,
213                this->objectComponent1->getAbsCoor ().z);
214  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
215  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
216  static_cast<StaticModel*>(this->getModel())->draw(0);
217  glPopMatrix();
218}
219
Note: See TracBrowser for help on using the repository browser.