Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4969 was 4969, checked in by bensch, 20 years ago

orxonox/trunk: ability to set a Slots Direction

File size: 3.7 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->loadModel("models/turret1.obj");
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  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
68  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
69
70  this->setProjectile(CL_TEST_BULLET);
71
72  this->setEmissionPoint(1.684, 0.472, 0);
73  //this->getProjectileFactory()->prepare(100);
74}
75
76
77/**
78 *  standard deconstructor
79*/
80Turret::~Turret ()
81{
82  // model will be deleted from WorldEntity-destructor
83}
84
85void Turret::activate()
86{
87}
88
89void Turret::deactivate()
90{
91}
92
93void Turret::tick(float dt)
94{
95  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
96  direction.normalize();
97  if (likely (this->getParent() != NULL))
98  {
99    Quaternion quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
100    this->setAbsDir(quat);
101  }
102  else
103  {
104    Quaternion quat = Quaternion(direction, this->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
105    this->setAbsDir(quat);
106  }
107}
108
109void Turret::fire()
110{
111  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
112
113  PNode* target = this->getWeaponManager()->getFixedTarget();
114
115  if (target != NULL)
116  {
117    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
118    pj->setAbsDir(this->getAbsDir());
119  }
120  else
121    pj->setVelocity(target->getVelocity());
122
123
124  pj->setAbsCoor(this->getEmissionPoint());
125  pj->setAbsDir(this->getAbsDir());
126  State::getWorldEntityList()->add(pj);
127}
128
129
130void Turret::destroy ()
131{}
132
133/**
134 * draws the Turret
135*/
136void Turret::draw ()
137{
138  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
139
140  /* draw gun body */
141  glMatrixMode(GL_MODELVIEW);
142  glPushMatrix();
143  float matrix[4][4];
144  glTranslatef (this->getAbsCoor ().x,
145                this->getAbsCoor ().y,
146                this->getAbsCoor ().z);
147  this->getAbsDir ().matrix (matrix);
148  glMultMatrixf((float*)matrix);
149
150  this->model->draw();
151  glPopMatrix();
152}
153
Note: See TracBrowser for help on using the repository browser.