Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.older/src/world_entities/weapons/test_gun.cc @ 10764

Last change on this file since 10764 was 9002, checked in by bensch, 18 years ago

orxonox/trunk: redirect everything to see into the dof of the _centerNode

File size: 6.0 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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
22
23#include "test_gun.h"
24#include "world_entities/projectiles/projectile.h"
25
26#include "world_entity.h"
27#include "static_model.h"
28#include "weapon_manager.h"
29#include "util/loading/factory.h"
30
31#include "animation3d.h"
32
33#include "fast_factory.h"
34
35CREATE_FACTORY(TestGun, CL_TEST_GUN);
36
37/**
38 *  standard constructor
39
40   creates a new weapon
41*/
42TestGun::TestGun ( int leftRight)
43  : Weapon()
44{
45  this->init();
46
47
48  this->leftRight = leftRight;
49
50  this->objectComponent1 = new PNode();
51  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
52  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
53  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
54  //parent->addChild(this->objectComponent1, PNODE_ALL);
55  this->addChild(this->objectComponent1);
56
57  animation1->setInfinity(ANIM_INF_CONSTANT);
58  animation2->setInfinity(ANIM_INF_CONSTANT);
59  animation3->setInfinity(ANIM_INF_CONSTANT);
60
61  if( this->leftRight == W_LEFT)
62  {
63    this->setEmissionPoint(1.0, -0.6, -0.2);
64
65    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
66    animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
67    animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
68
69    animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
70    animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
71
72    animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
73    animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
74  }
75  else if( this->leftRight == W_RIGHT)
76  {
77    this->setEmissionPoint(1.0, -0.6, 0.3);
78
79    this->objectComponent1->setRelCoor(Vector(0,0,0.35));
80    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
81    animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
82    animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
83
84    animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
85    animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
86
87    animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
88    animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
89  }
90}
91
92
93TestGun::TestGun(const TiXmlElement* root)
94{
95  this->init();
96  if (root != NULL)
97    this->loadParams(root);
98}
99
100/**
101 *  standard deconstructor
102*/
103TestGun::~TestGun ()
104{
105  // model will be deleted from WorldEntity-destructor
106}
107
108
109void TestGun::init()
110{
111  this->setClassID(CL_TEST_GUN, "TestGun");
112
113//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
114
115  this->loadModel("models/guns/test_gun.obj");
116
117  this->setStateDuration(WS_SHOOTING, .1);
118  this->setStateDuration(WS_RELOADING, .1);
119  this->setStateDuration(WS_ACTIVATING, .4);
120  this->setStateDuration(WS_DEACTIVATING, .4);
121
122  this->setEnergyMax(10000);
123  this->increaseEnergy(10000);
124  //this->minCharge = 2;
125
126  this->setActionSound(WA_SHOOT, "sound/laser.wav");
127  this->setActionSound(WA_ACTIVATE, "sound/voices/lasers.wav");
128
129
130  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
131  this->setProjectileType(CL_LASER);
132  this->prepareProjectiles(100);
133
134}
135
136
137void TestGun::loadParams(const TiXmlElement* root)
138{
139  Weapon::loadParams(root);
140
141}
142
143
144/**
145 *  this activates the weapon
146
147   This is needed, since there can be more than one weapon on a ship. the
148   activation can be connected with an animation. for example the weapon is
149   been armed out.
150*/
151void TestGun::activate()
152{
153}
154
155
156/**
157 *  this deactivates the weapon
158
159   This is needed, since there can be more than one weapon on a ship. the
160   activation can be connected with an animation. for example the weapon is
161   been armed out.
162*/
163void TestGun::deactivate()
164{
165}
166
167
168/**
169 *  fires the weapon
170
171   this is called from the player.cc, when fire-button is been pushed
172   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
173*/
174void TestGun::fire()
175{
176  Projectile* pj =  this->getProjectile();
177  if (pj == NULL)
178    return;
179
180  pj->setParent(PNode::getNullParent());
181
182  pj->setVelocity(this->getAbsDir().apply(Vector(1,0,0))*250 + VECTOR_RAND(5));
183
184  pj->setAbsCoor(this->getEmissionPoint());
185  pj->setAbsDir(this->getAbsDir());
186  pj->activate();
187}
188
189
190
191/**
192 *  this will draw the weapon
193*/
194void TestGun::draw () const
195{
196  /* draw gun body */
197  glMatrixMode(GL_MODELVIEW);
198  glPushMatrix();
199  glTranslatef (this->getAbsCoor ().x,
200                this->getAbsCoor ().y,
201                this->getAbsCoor ().z);
202
203  Vector tmpRot = this->getAbsDir().getSpacialAxis();
204  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
205
206  if( this->leftRight == W_RIGHT)
207    glScalef(1.0, 1.0, -1.0);
208  static_cast<StaticModel*>(this->getModel())->draw(1);
209  glPopMatrix();
210
211  /* draw objectComponent1: gun coil - animated stuff */
212  glPushMatrix();
213  glTranslatef (this->objectComponent1->getAbsCoor ().x,
214                this->objectComponent1->getAbsCoor ().y,
215                this->objectComponent1->getAbsCoor ().z);
216  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
217  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
218  static_cast<StaticModel*>(this->getModel())->draw(0);
219  glPopMatrix();
220}
221
Note: See TracBrowser for help on using the repository browser.