Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: patch to use relative coordinates again, some smaller changes in the preLoading/loading mechanisms

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