Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3992 was 3987, checked in by patrick, 20 years ago

orxonox/trunk: test gun component1 now gets displayed correctly again

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