Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10544 was 10415, checked in by patrick, 18 years ago

changed the path names to reflect the new data repos

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 "loading/fast_factory.h"
34
35
36ObjectListDefinition(TestGun);
37CREATE_FACTORY(TestGun);
38/**
39 *  standard constructor
40
41   creates a new weapon
42*/
43TestGun::TestGun ( int leftRight)
44  : Weapon()
45{
46  this->init();
47
48
49  this->leftRight = leftRight;
50
51  this->objectComponent1 = new PNode();
52  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
53  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
54  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
55  //parent->addChild(this->objectComponent1, PNODE_ALL);
56  this->addChild(this->objectComponent1);
57
58  animation1->setInfinity(ANIM_INF_CONSTANT);
59  animation2->setInfinity(ANIM_INF_CONSTANT);
60  animation3->setInfinity(ANIM_INF_CONSTANT);
61
62  if( this->leftRight == W_LEFT)
63  {
64    this->setEmissionPoint(1.0, -0.6, -0.2);
65
66    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
67    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
68    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
69
70    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
71    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
72
73    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
74    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
75  }
76  else if( this->leftRight == W_RIGHT)
77  {
78    this->setEmissionPoint(1.0, -0.6, 0.3);
79
80    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
81    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
82    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
83    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
84
85    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
86    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
87
88    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
89    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
90  }
91}
92
93
94TestGun::TestGun(const TiXmlElement* root)
95{
96  this->init();
97  if (root != NULL)
98    this->loadParams(root);
99}
100
101/**
102 *  standard deconstructor
103*/
104TestGun::~TestGun ()
105{
106  // model will be deleted from WorldEntity-destructor
107}
108
109
110void TestGun::init()
111{
112  this->registerObject(this, TestGun::_objectList);
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, "sounds/guns/laser.wav");
127  this->setActionSound(WA_ACTIVATE, "sounds/voices/lasers.wav");
128
129
130  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
131  this->setProjectileTypeC("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.