Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/test_gun.cc @ 9853

Last change on this file since 9853 was 9656, checked in by bensch, 18 years ago

orxonox/trunk: merged the proxy bache back with no conflicts

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