Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/guidedmissile/src/world_entities/weapons/aiming_turret.cc @ 5765

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

orxonox/branches/guidedmissile: more balanced

File size: 4.2 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#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
16
17#include "aiming_turret.h"
18
19#include "weapon_manager.h"
20#include "aim.h"
21#include "projectile.h"
22
23#include "model.h"
24
25#include "null_parent.h"
26
27#include "animation3d.h"
28#include "sound_engine.h"
29
30#include "factory.h"
31
32CREATE_FACTORY(AimingTurret, CL_AIMING_TURRET);
33
34using namespace std;
35
36
37/**
38 *  standard constructor
39
40   creates a new weapon
41*/
42AimingTurret::AimingTurret ()
43  : Weapon()
44{
45  this->init();
46
47  this->loadModel("models/guns/turret2.obj");
48
49
50  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
51  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
52  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
53}
54
55
56AimingTurret::AimingTurret(const TiXmlElement* root)
57{
58  this->init();
59  this->loadParams(root);
60}
61
62/**
63 *  standard deconstructor
64*/
65AimingTurret::~AimingTurret ()
66{
67  // model will be deleted from WorldEntity-destructor
68//  delete this->target;
69}
70
71void AimingTurret::init()
72{
73  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
74
75  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
76  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
77
78  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
82
83  animation1->setInfinity(ANIM_INF_CONSTANT);
84  animation2->setInfinity(ANIM_INF_CONSTANT);
85
86  this->setStateDuration(WS_SHOOTING, 1.0);
87  this->setStateDuration(WS_RELOADING, 2.0);
88  this->setStateDuration(WS_ACTIVATING, .4);
89  this->setStateDuration(WS_DEACTIVATING, .4);
90
91  this->setMaximumEnergy(10000, 50);
92  this->increaseEnergy(100000);
93  //this->minCharge = 2;
94
95  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
96  this->setProjectileType(CL_GUIDED_MISSILE);
97
98
99  this->setEmissionPoint(1.684, 0.472, 0);
100  //this->getProjectileFactory()->prepare(100);
101
102  this->target = new Aim(this);
103  this->target->setVisibility(false);
104}
105
106void AimingTurret::loadParams(const TiXmlElement* root)
107{
108  static_cast<Weapon*>(this)->loadParams(root);
109
110}
111
112void AimingTurret::activate()
113{
114  this->target->setVisibility(true);
115}
116
117void AimingTurret::deactivate()
118{
119  this->target->setVisibility(false);
120}
121
122void AimingTurret::tick(float dt)
123{
124  Quaternion quat;
125  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
126
127  direction.normalize();
128
129//   if (likely (this->getParent() != NULL))
130//     quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131//   else
132//     quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
133
134   quat = Quaternion(.5, Vector(0,0,1));
135
136  this->setRelDir(quat);
137
138  this->target->tick(dt);
139}
140
141void AimingTurret::fire()
142{
143  Projectile* pj = this->getProjectile();
144  if (pj == NULL)
145    return;
146
147    pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*50.0 + VECTOR_RAND(13)
148            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
149    pj->setTarget(this->target->getParent());
150
151
152  pj->setParent(NullParent::getInstance());
153  pj->setAbsCoor(this->getEmissionPoint());
154  pj->setAbsDir(this->getAbsDir());
155  pj->activate();
156  this->target->searchTarget(100);
157}
158
159void AimingTurret::destroy ()
160{}
161
162/**
163 * draws the AimingTurret
164*/
165void AimingTurret::draw () const
166{
167  /* draw gun body */
168  glMatrixMode(GL_MODELVIEW);
169  glPushMatrix();
170  glTranslatef (this->getAbsCoor ().x,
171                this->getAbsCoor ().y,
172                this->getAbsCoor ().z);
173  Vector tmpRot = this->getAbsDir().getSpacialAxis();
174  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
175
176  this->model->draw();
177  glPopMatrix();
178}
179
Note: See TracBrowser for help on using the repository browser.