Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: cleaned up the weapon/test_gun class. now it makes more sense.

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