Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: less output of Weapon

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 "null_parent.h"
37
38#include "fast_factory.h"
39
40
41using namespace std;
42
43CREATE_FACTORY(TestGun);
44
45/**
46 *  standard constructor
47
48   creates a new weapon
49*/
50TestGun::TestGun (WeaponManager* weaponManager, int leftRight)
51  : Weapon(weaponManager)
52{
53  this->init();
54
55
56  this->leftRight = leftRight;
57
58  this->objectComponent1 = new PNode();
59  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
60  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
61  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
62  //parent->addChild(this->objectComponent1, PNODE_ALL);
63  this->addChild(this->objectComponent1, PNODE_ALL);
64
65  animation1->setInfinity(ANIM_INF_CONSTANT);
66  animation2->setInfinity(ANIM_INF_CONSTANT);
67  animation3->setInfinity(ANIM_INF_CONSTANT);
68
69  if( this->leftRight == W_LEFT)
70  {
71    this->setEmissionPoint(1.0, 0.0, -0.35);
72
73    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
74    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
75    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
76
77    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
78    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79
80    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82  }
83  else if( this->leftRight == W_RIGHT)
84  {
85    this->setEmissionPoint(1.0, 0.0, 0.5);
86
87    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
88    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
89    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
90    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
91
92    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
93    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
94
95    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
96    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
97  }
98}
99
100
101TestGun::TestGun(const TiXmlElement* root)
102{
103  this->init();
104  this->loadParams(root);
105}
106
107/**
108 *  standard deconstructor
109*/
110TestGun::~TestGun ()
111{
112  // model will be deleted from WorldEntity-destructor
113}
114
115
116void TestGun::init()
117{
118  this->setClassID(CL_TEST_GUN, "TestGun");
119
120  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
121
122  this->setStateDuration(WS_SHOOTING, .4);
123  this->setStateDuration(WS_RELOADING, 1);
124  this->setStateDuration(WS_ACTIVATING, .4);
125  this->setStateDuration(WS_DEACTIVATING, .4);
126
127  this->setMaximumEnergy(1000, 10);
128  this->increaseEnergy(100);
129  //this->minCharge = 2;
130
131  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
132
133  this->setProjectile(CL_TEST_BULLET);
134  this->getProjectileFactory()->prepare(20);
135}
136
137
138void TestGun::loadParams(const TiXmlElement* root)
139{
140
141
142}
143
144
145/**
146 *  this activates the weapon
147
148   This is needed, since there can be more than one weapon on a ship. the
149   activation can be connected with an animation. for example the weapon is
150   been armed out.
151*/
152void TestGun::activate()
153{
154}
155
156
157/**
158 *  this deactivates the weapon
159
160   This is needed, since there can be more than one weapon on a ship. the
161   activation can be connected with an animation. for example the weapon is
162   been armed out.
163*/
164void TestGun::deactivate()
165{
166}
167
168
169/**
170 *  fires the weapon
171
172   this is called from the player.cc, when fire-button is been pushed
173   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
174*/
175void TestGun::fire()
176{
177  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
178
179  pj->setParent(NullParent::getInstance());
180
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  /* draw gun body */
216  glMatrixMode(GL_MODELVIEW);
217  glPushMatrix();
218  glTranslatef (this->getAbsCoor ().x,
219                this->getAbsCoor ().y,
220                this->getAbsCoor ().z);
221
222  Vector tmpRot = this->getAbsDir().getSpacialAxis();
223  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
224
225  if( this->leftRight == W_RIGHT)
226    glScalef(1.0, 1.0, -1.0);
227  this->model->draw(1);
228  glPopMatrix();
229
230  /* draw objectComponent1: gun coil - animated stuff */
231  glMatrixMode(GL_MODELVIEW);
232  glPushMatrix();
233  glTranslatef (this->objectComponent1->getAbsCoor ().x,
234                this->objectComponent1->getAbsCoor ().y,
235                this->objectComponent1->getAbsCoor ().z);
236  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
237  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
238  this->model->draw(0);
239  glPopMatrix();
240}
241
Note: See TracBrowser for help on using the repository browser.