Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Turret now turns into the dirrection of the Target, projectiles are aligned into this direction too.

File size: 3.6 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
46  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
47  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
48
49  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
50  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
51  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
52  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
53
54  animation1->setInfinity(ANIM_INF_CONSTANT);
55  animation2->setInfinity(ANIM_INF_CONSTANT);
56
57  this->setStateDuration(WS_SHOOTING, .4);
58  this->setStateDuration(WS_RELOADING, 2);
59  this->setStateDuration(WS_ACTIVATING, .4);
60  this->setStateDuration(WS_DEACTIVATING, .4);
61
62  this->setMaximumEnergy(1000, 10);
63  this->increaseEnergy(100);
64  //this->minCharge = 2;
65
66  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
67
68  this->setProjectile(CL_TEST_BULLET);
69
70  this->setEmissionPoint(1.684, 0.472, 0);
71  //this->getProjectileFactory()->prepare(100);
72}
73
74
75/**
76 *  standard deconstructor
77*/
78Turret::~Turret ()
79{
80  // model will be deleted from WorldEntity-destructor
81}
82
83void Turret::activate()
84{
85}
86
87void Turret::deactivate()
88{
89}
90
91void Turret::tick(float dt)
92{
93  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
94  direction.normalize();
95  Quaternion quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
96
97  this->setRelDir(quat);
98}
99
100/**
101 *  fires the weapon
102
103   this is called from the player.cc, when fire-button is been pushed
104*/
105void Turret::fire()
106{
107  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
108
109  PNode* target = this->getWeaponManager()->getFixedTarget();
110
111  if (target != NULL)
112  {
113    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
114    pj->setAbsDir(this->getAbsDir());
115  }
116  else
117    pj->setVelocity(target->getVelocity());
118
119
120  pj->setAbsCoor(this->getEmissionPoint());
121  pj->setAbsDir(this->getAbsDir());
122  State::getWorldEntityList()->add(pj);
123}
124
125
126/**
127 *  is called, when the weapon is destroyed
128
129   this is in conjunction with the hit function, so when a weapon is able to get
130   hit, it can also be destoryed.
131*/
132void Turret::destroy ()
133{}
134
135/**
136 *  this will draw the weapon
137*/
138void Turret::draw ()
139{
140  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
141
142  /* draw gun body */
143  glMatrixMode(GL_MODELVIEW);
144  glPushMatrix();
145  float matrix[4][4];
146  glTranslatef (this->getAbsCoor ().x,
147                this->getAbsCoor ().y,
148                this->getAbsCoor ().z);
149  this->getAbsDir ().matrix (matrix);
150  glMultMatrixf((float*)matrix);
151
152  this->model->draw();
153  glPopMatrix();
154}
155
Note: See TracBrowser for help on using the repository browser.