Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/world_entities/weapons/aiming_turret.cc @ 9617

Last change on this file since 9617 was 9617, checked in by bensch, 18 years ago

orxonox/proxy: some nicer fading

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