Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Turret is fixed onto the ship as it should.
TestGun fires staight again
PNode now know getParent(), as this is a quite usefull function
Vector still has an error in the getNormalized function, and i am not able to determine the cause of this

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