Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: f*g object manager is hard to get done right, trying it differently

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