Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new style for resources (prework/movement)

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