Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/aiming_turret.cc @ 7612

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

orxonox/trunk: our first cheat :)

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