Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: naming of animation changed
Anim → Animation
tAnim → tAnimation
Animation → Animation3D

@paede: i hope you like it.

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