Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3755 was 3755, checked in by patrick, 19 years ago

orxonox/trunk: now got two weapons firing syncronized

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