Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: animation of weapon reimplemented (but only with Linear interpolation.
doxy-tags

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