Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/weapons/test_gun.cc @ 6691

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

orxonox/trunk: loadParams is now virtual.
ALL THE CLASSES HAVE TO CALL

SuperClass::loadParams(root);

isntead of:
static_cast<SuperClass*>(this)→loadParams(root);

which was quite stupid anyways

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