Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Slots are now PNodes

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
22
23#include "test_gun.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "test_bullet.h"
28
29#include "state.h"
30#include "vector.h"
31#include "list.h"
32#include "animation3d.h"
33#include "sound_engine.h"
34
35#include "fast_factory.h"
36
37
38using namespace std;
39
40
41/**
42 *  standard constructor
43
44   creates a new weapon
45*/
46TestGun::TestGun (int leftRight)
47{
48  this->setClassID(CL_TEST_GUN, "TestGun");
49
50  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
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  if( this->leftRight == W_LEFT)
64    {
65      this->setEmissionPoint(1.0, 0.0, -0.35);
66
67      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
68      animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
69      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
70
71      animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72      animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73
74      animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
75      animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
76    }
77  else if( this->leftRight == W_RIGHT)
78    {
79      this->setEmissionPoint(1.0, 0.0, 0.5);
80
81      this->objectComponent1->setRelCoor(Vector(0,0,0.35));
82      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
83      animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
84      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
85
86      animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
87      animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
88
89      animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
90      animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
91    }
92/*
93  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
94  this->weaponSource = new SoundSource(this->fireSound, this);
95  this->weaponSource->setRolloffFactor(.1);*/
96  Projectile* p = new TestBullet();
97
98  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
99  //ObjectManager::getInstance()->debug();
100
101  this->setStateDuration(WS_SHOOTING, .4);
102  this->setStateDuration(WS_RELOADING, 1);
103  this->setStateDuration(WS_ACTIVATING, .4);
104  this->setStateDuration(WS_DEACTIVATING, .4);
105
106  this->setMaximumEnergy(1000, 10);
107  this->increaseEnergy(100);
108  //this->minCharge = 2;
109
110  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
111
112  this->setProjectile(CL_TEST_BULLET);
113  //this->getProjectileFactory()->prepare(100);
114}
115
116
117/**
118 *  standard deconstructor
119*/
120TestGun::~TestGun ()
121{
122  // model will be deleted from WorldEntity-destructor
123}
124
125
126/**
127 *  this activates the weapon
128
129   This is needed, since there can be more than one weapon on a ship. the
130   activation can be connected with an animation. for example the weapon is
131   been armed out.
132*/
133void TestGun::activate()
134{
135}
136
137
138/**
139 *  this deactivates the weapon
140
141   This is needed, since there can be more than one weapon on a ship. the
142   activation can be connected with an animation. for example the weapon is
143   been armed out.
144*/
145void TestGun::deactivate()
146{
147}
148
149
150/**
151 *  fires the weapon
152
153   this is called from the player.cc, when fire-button is been pushed
154   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
155*/
156void TestGun::fire()
157{
158  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
159
160  pj->setAbsCoor(this->getEmissionPoint());
161  pj->setAbsDir(this->getAbsDir());
162  pj->setVelocity(this->getVelocity());
163  State::getWorldEntityList()->add(pj);
164}
165
166
167/**
168 *  is called, when the weapon gets hit (=collide with something)
169 * @param from which entity it is been hit
170 * @param where it is been hit
171
172   this may not be used, since it would make the game relay complicated when one
173   can destroy the weapons of enemies or vice versa.
174*/
175void TestGun::hit (WorldEntity* entity, Vector* position)
176{}
177
178
179/**
180 *  is called, when the weapon is destroyed
181
182   this is in conjunction with the hit function, so when a weapon is able to get
183   hit, it can also be destoryed.
184*/
185void TestGun::destroy ()
186{}
187
188/**
189 *  this will draw the weapon
190*/
191void TestGun::draw ()
192{
193  /* draw gun body */
194  glMatrixMode(GL_MODELVIEW);
195  glPushMatrix();
196  float matrix[4][4];
197  glTranslatef (this->getAbsCoor ().x,
198                this->getAbsCoor ().y,
199                this->getAbsCoor ().z);
200  this->getAbsDir ().matrix (matrix);
201  glMultMatrixf((float*)matrix);
202  if( this->leftRight == W_RIGHT)
203    glScalef(1.0, 1.0, -1.0);
204  this->model->draw(1);
205  glPopMatrix();
206
207  /* draw objectComponent1: gun coil - animated stuff */
208  glMatrixMode(GL_MODELVIEW);
209  glPushMatrix();
210  glTranslatef (this->objectComponent1->getAbsCoor ().x,
211                this->objectComponent1->getAbsCoor ().y,
212                this->objectComponent1->getAbsCoor ().z);
213  this->objectComponent1->getAbsDir ().matrix (matrix);
214  glMultMatrixf((float*)matrix);
215  this->model->draw(0);
216  glPopMatrix();
217}
218
Note: See TracBrowser for help on using the repository browser.