Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/openAL/src/world_entities/test_gun.cc @ 4210

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

orxonox/branches/openAL: better values for the Sound-RollOff

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 "stdincl.h"
26#include "world_entity.h"
27#include "model.h"
28#include "test_bullet.h"
29
30#include "vector.h"
31#include "list.h"
32#include "animation3d.h"
33#include "sound_engine.h"
34
35using namespace std;
36
37
38/**
39   \brief standard constructor
40
41   creates a new weapon
42*/
43TestGun::TestGun (PNode* parent, const Vector& coordinate, const Quaternion& direction, int leftRight) 
44  :  Weapon (parent, coordinate, direction) 
45{
46  this->model = (Model*)ResourceManager::getInstance()->load("models/test_gun.obj", OBJ, RP_CAMPAIGN);
47  this->idleTime = 0.2f;
48  this->leftRight = leftRight;
49
50  this->objectComponent1 = new PNode();
51  this->animation1 = new Animation3D(this->objectComponent1);
52  this->animation2 = new Animation3D(this);
53  this->animation3 = new Animation3D(this);
54  //parent->addChild(this->objectComponent1, PNODE_ALL);
55  this->addChild(this->objectComponent1, PNODE_ALL);
56
57  this->animation1->setInfinity(ANIM_INF_CONSTANT);
58  this->animation2->setInfinity(ANIM_INF_CONSTANT);
59  this->animation3->setInfinity(ANIM_INF_CONSTANT);
60  if( this->leftRight == W_LEFT)
61    {
62      this->projectileOffset = Vector(1.0, 0.0, -0.35);
63
64      this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
65      this->animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
66      this->animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
67
68      this->animation2->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
69      this->animation2->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
70
71      this->animation3->addKeyFrame(Vector(-2.6, 0.1, 3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
72      this->animation3->addKeyFrame(Vector(-2.6, 0.1, 2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
73    }
74  else if( this->leftRight == W_RIGHT)
75    {
76      this->projectileOffset = Vector(1.0, 0.0, 0.5);
77
78      this->objectComponent1->setRelCoor(Vector(0,0,0.35));
79      this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
80      this->animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
81      this->animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
82
83      this->animation2->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
84      this->animation2->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
85
86      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -3.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
87      this->animation3->addKeyFrame(Vector(-2.6, 0.1, -2.0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT); 
88    }
89 
90  this->fireSound = (SoundBuffer*)ResourceManager::getInstance()->load("sound/shot1.wav", WAV);
91  this->weaponSource = new SoundSource(this->fireSound, this);
92  this->weaponSource->setRolloffFactor(.1);
93}
94
95
96/**
97   \brief standard deconstructor
98*/
99TestGun::~TestGun () 
100{
101  // model will be deleted from WorldEntity-destructor
102}
103
104
105/**
106   \brief this activates the weapon
107
108   This is needed, since there can be more than one weapon on a ship. the
109   activation can be connected with an animation. for example the weapon is
110   been armed out.
111*/
112void TestGun::activate()
113{
114  this->animation2->replay();
115}
116
117
118/**
119   \brief this deactivates the weapon
120
121   This is needed, since there can be more than one weapon on a ship. the
122   activation can be connected with an animation. for example the weapon is
123   been armed out.
124*/
125void TestGun::deactivate()
126{
127  this->animation3->replay();
128}
129
130
131/**
132   \brief fires the weapon
133   
134   this is called from the player.cc, when fire-button is been pushed
135*/
136void TestGun::fire()
137{
138  if( !this->hasWeaponIdleTimeElapsed())
139    {
140      this->weaponIdle();
141      return;
142    }
143
144  weaponSource->play();
145
146  Projectile* pj = new TestBullet(this);
147  pj->setAbsCoor(this->getAbsCoor() + this->projectileOffset);
148  pj->setAbsDir(this->getAbsDir());
149  pj->setFlightDirection(this->getAbsDir());
150  pj->setSpeed(this->getSpeed());
151  this->worldEntities->add(pj);
152  this->localTime = 0;
153 
154  this->animation1->replay();
155}
156
157
158/**
159   \brief is called, when the weapon gets hit (=collide with something)
160   \param from which entity it is been hit
161   \param where it is been hit
162
163   this may not be used, since it would make the game relay complicated when one
164   can destroy the weapons of enemies or vice versa.
165*/
166void TestGun::hit (WorldEntity* entity, Vector* position) 
167{}
168
169
170/**
171   \brief is called, when the weapon is destroyed
172
173   this is in conjunction with the hit function, so when a weapon is able to get
174   hit, it can also be destoryed.
175*/
176void TestGun::destroy () 
177{}
178
179
180/**
181   \brief tick signal for time dependent/driven stuff
182*/
183void TestGun::tick (float time) 
184{
185  this->localTime += time;
186}
187
188
189/**
190   \brief is called, when there is no fire button pressed
191*/
192void TestGun::weaponIdle()
193{}
194
195
196/**
197   \brief this will draw the weapon
198*/
199void TestGun::draw () 
200{
201  /* draw gun body */
202  glMatrixMode(GL_MODELVIEW);
203  glPushMatrix();
204  float matrix[4][4];
205  glTranslatef (this->getAbsCoor ().x, 
206                this->getAbsCoor ().y, 
207                this->getAbsCoor ().z); 
208  this->getAbsDir ().matrix (matrix);
209  glMultMatrixf((float*)matrix);
210  if( this->leftRight == W_RIGHT)
211    glScalef(1.0, 1.0, -1.0);
212  this->model->draw(1);
213  glPopMatrix();
214
215  /* draw objectComponent1: gun coil - animated stuff */
216  glMatrixMode(GL_MODELVIEW);
217  glPushMatrix();
218  glTranslatef (this->objectComponent1->getAbsCoor ().x, 
219                this->objectComponent1->getAbsCoor ().y, 
220                this->objectComponent1->getAbsCoor ().z);
221  this->objectComponent1->getAbsDir ().matrix (matrix);
222  glMultMatrixf((float*)matrix);
223  this->model->draw(0);
224  glPopMatrix();
225}
226
Note: See TracBrowser for help on using the repository browser.