Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: many loadParams

File size: 6.4 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
22
23#include "test_gun.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "test_bullet.h"
28#include "weapon_manager.h"
29
30#include "state.h"
31#include "vector.h"
32#include "list.h"
33#include "animation3d.h"
34#include "sound_engine.h"
35
36#include "fast_factory.h"
37
38
39using namespace std;
40
41CREATE_FACTORY(TestGun);
42
43/**
44 *  standard constructor
45
46   creates a new weapon
47*/
48TestGun::TestGun (WeaponManager* weaponManager, int leftRight)
49  : Weapon(weaponManager)
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, PNODE_ALL);
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.0, -0.35);
67
68    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
69    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
70    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
71
72    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74
75    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
76    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
77  }
78  else if( this->leftRight == W_RIGHT)
79  {
80    this->setEmissionPoint(1.0, 0.0, 0.5);
81
82    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
83    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
84    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
85    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
86
87    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
88    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
89
90    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
91    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
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/test_gun.obj", OBJ, RP_CAMPAIGN);
116
117  this->setStateDuration(WS_SHOOTING, .4);
118  this->setStateDuration(WS_RELOADING, 1);
119  this->setStateDuration(WS_ACTIVATING, .4);
120  this->setStateDuration(WS_DEACTIVATING, .4);
121
122  this->setMaximumEnergy(1000, 10);
123  this->increaseEnergy(100);
124  //this->minCharge = 2;
125
126  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
127
128  this->setProjectile(CL_TEST_BULLET);
129  //this->getProjectileFactory()->prepare(100);
130}
131
132
133void TestGun::loadParams(const TiXmlElement* root)
134{
135
136
137}
138
139
140/**
141 *  this activates the weapon
142
143   This is needed, since there can be more than one weapon on a ship. the
144   activation can be connected with an animation. for example the weapon is
145   been armed out.
146*/
147void TestGun::activate()
148{
149}
150
151
152/**
153 *  this deactivates the weapon
154
155   This is needed, since there can be more than one weapon on a ship. the
156   activation can be connected with an animation. for example the weapon is
157   been armed out.
158*/
159void TestGun::deactivate()
160{
161}
162
163
164/**
165 *  fires the weapon
166
167   this is called from the player.cc, when fire-button is been pushed
168   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
169*/
170void TestGun::fire()
171{
172  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
173
174/*
175  PNode* target = this->getWeaponManager()->getFixedTarget();
176  if (target != NULL)
177  {
178    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
179  }
180  else*/
181  pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*20);
182
183  pj->setAbsCoor(this->getEmissionPoint());
184  pj->setAbsDir(this->getAbsDir());
185  State::getWorldEntityList()->add(pj);
186}
187
188
189/**
190 *  is called, when the weapon gets hit (=collide with something)
191 * @param from which entity it is been hit
192 * @param where it is been hit
193
194   this may not be used, since it would make the game relay complicated when one
195   can destroy the weapons of enemies or vice versa.
196*/
197void TestGun::hit (WorldEntity* entity, Vector* position)
198{}
199
200
201/**
202 *  is called, when the weapon is destroyed
203
204   this is in conjunction with the hit function, so when a weapon is able to get
205   hit, it can also be destoryed.
206*/
207void TestGun::destroy ()
208{}
209
210/**
211 *  this will draw the weapon
212*/
213void TestGun::draw ()
214{
215  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
216
217  /* draw gun body */
218  glMatrixMode(GL_MODELVIEW);
219  glPushMatrix();
220  float matrix[4][4];
221  glTranslatef (this->getAbsCoor ().x,
222                this->getAbsCoor ().y,
223                this->getAbsCoor ().z);
224  this->getAbsDir ().matrix (matrix);
225  glMultMatrixf((float*)matrix);
226  if( this->leftRight == W_RIGHT)
227    glScalef(1.0, 1.0, -1.0);
228  this->model->draw(1);
229  glPopMatrix();
230
231  /* draw objectComponent1: gun coil - animated stuff */
232  glMatrixMode(GL_MODELVIEW);
233  glPushMatrix();
234  glTranslatef (this->objectComponent1->getAbsCoor ().x,
235                this->objectComponent1->getAbsCoor ().y,
236                this->objectComponent1->getAbsCoor ().z);
237  this->objectComponent1->getAbsDir ().matrix (matrix);
238  glMultMatrixf((float*)matrix);
239  this->model->draw(0);
240  glPopMatrix();
241}
242
Note: See TracBrowser for help on using the repository browser.