Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: new Animation3D is now ready for setting up of the Functions

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