Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: implemented the objectmanager debug functon, some small fixed in the ol code

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