Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapons/turret.cc @ 4963

Last change on this file since 4963 was 4963, checked in by bensch, 19 years ago

orxonox/trunk: added class turret, a subclass for turrets, this is not finished yet, but will be in some time from now…

File size: 5.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific
12   main-programmer: Benjamin Grauer
13   co-programmer:
14*/
15
16
17#include "turret.h"
18
19#include "weapon_manager.h"
20#include "test_bullet.h"
21
22#include "state.h"
23#include "vector.h"
24#include "list.h"
25#include "animation3d.h"
26#include "sound_engine.h"
27
28#include "fast_factory.h"
29
30
31using namespace std;
32
33
34/**
35 *  standard constructor
36
37   creates a new weapon
38*/
39Turret::Turret (WeaponManager* weaponManager)
40  : Weapon(weaponManager)
41{
42  this->setClassID(CL_TURRET, "Turret");
43
44  this->model = (Model*)ResourceManager::getInstance()->load("models/turret1.obj", OBJ, RP_CAMPAIGN);
45  this->leftRight = leftRight;
46
47/*  this->objectComponent1 = new PNode();
48  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
49  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
50  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
51  //parent->addChild(this->objectComponent1, PNODE_ALL);
52  this->addChild(this->objectComponent1, PNODE_ALL);
53
54  animation1->setInfinity(ANIM_INF_CONSTANT);
55  animation2->setInfinity(ANIM_INF_CONSTANT);
56  animation3->setInfinity(ANIM_INF_CONSTANT);
57  if( this->leftRight == W_LEFT)
58    {
59      this->setEmissionPoint(1.0, 0.0, -0.35);
60
61      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
62      animation1->addKeyFrame(Vector(-0.4, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
63      animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
64
65      animation2->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
66      animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
67
68      animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
69      animation3->addKeyFrame(Vector(0.0, 0.0, -1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
70    }
71  else if( this->leftRight == W_RIGHT)
72    {
73      this->setEmissionPoint(1.0, 0.0, 0.5);
74
75      this->objectComponent1->setRelCoor(Vector(0,0,0.35));
76      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
77      animation1->addKeyFrame(Vector(-0.4, 0, .5), Quaternion(), 0.1, ANIM_LINEAR, ANIM_CONSTANT);
78      animation1->addKeyFrame(Vector(0, 0, .5), Quaternion(), 0.0, ANIM_LINEAR, ANIM_CONSTANT);
79
80      animation2->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81      animation2->addKeyFrame(Vector(.0, .0, .0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82
83      animation3->addKeyFrame(Vector(.0, .0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
84      animation3->addKeyFrame(Vector(.0, .0, 1.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
85    }*/
86
87  //  ObjectManager::getInstance()->cache(CL_TEST_BULLET, 100, p);
88  //ObjectManager::getInstance()->debug();
89
90  this->setStateDuration(WS_SHOOTING, .4);
91  this->setStateDuration(WS_RELOADING, 1);
92  this->setStateDuration(WS_ACTIVATING, .4);
93  this->setStateDuration(WS_DEACTIVATING, .4);
94
95  this->setMaximumEnergy(1000, 10);
96  this->increaseEnergy(100);
97  //this->minCharge = 2;
98
99  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
100
101  this->setProjectile(CL_TEST_BULLET);
102  //this->getProjectileFactory()->prepare(100);
103}
104
105
106/**
107 *  standard deconstructor
108*/
109Turret::~Turret ()
110{
111  // model will be deleted from WorldEntity-destructor
112}
113
114
115/**
116 *  this activates 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 Turret::activate()
123{
124}
125
126
127/**
128 *  this deactivates the weapon
129
130   This is needed, since there can be more than one weapon on a ship. the
131   activation can be connected with an animation. for example the weapon is
132   been armed out.
133*/
134void Turret::deactivate()
135{
136}
137
138
139/**
140 *  fires the weapon
141
142   this is called from the player.cc, when fire-button is been pushed
143   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
144*/
145void Turret::fire()
146{
147  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
148
149  PNode* target = this->getWeaponManager()->getFixedTarget();
150
151  if (target != NULL)
152  {
153    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
154  }
155  else
156    pj->setVelocity(target->getVelocity());
157
158
159  pj->setAbsCoor(this->getEmissionPoint());
160  pj->setAbsDir(this->getAbsDir());
161  State::getWorldEntityList()->add(pj);
162}
163
164
165/**
166 *  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 Turret::destroy ()
172{}
173
174/**
175 *  this will draw the weapon
176*/
177void Turret::draw ()
178{
179  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
180
181  /* draw gun body */
182  glMatrixMode(GL_MODELVIEW);
183  glPushMatrix();
184  float matrix[4][4];
185  glTranslatef (this->getAbsCoor ().x,
186                this->getAbsCoor ().y,
187                this->getAbsCoor ().z);
188  this->getAbsDir ().matrix (matrix);
189  glMultMatrixf((float*)matrix);
190
191  this->model->draw();
192  glPopMatrix();
193}
194
Note: See TracBrowser for help on using the repository browser.