Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4542 was 4504, checked in by bensch, 20 years ago

orxonox/trunk: merged the SoundEngine into the Trunk.
merged file by file, but merged all the files in favor of the new trunk

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