Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/world_entities/weapons/aiming_turret.cc @ 6133

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

branches/powerups: merged the trunk to branches/powerup
merged with commandsvn merge ../trunk/ powerups/ -r5848:HEAD
conflicts resolved in favor of the trunk

File size: 4.1 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
29#include "factory.h"
30
31CREATE_FACTORY(AimingTurret, CL_AIMING_TURRET);
32
33using namespace std;
34
35
36/**
37 *  standard constructor
38
39   creates a new weapon
40*/
41AimingTurret::AimingTurret ()
42  : Weapon()
43{
44  this->init();
45
46  this->loadModel("models/guns/turret2.obj");
47
48
49  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
50  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
51  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
52}
53
54
55AimingTurret::AimingTurret(const TiXmlElement* root)
56{
57  this->init();
58  this->loadParams(root);
59}
60
61/**
62 *  standard deconstructor
63*/
64AimingTurret::~AimingTurret ()
65{
66  // model will be deleted from WorldEntity-destructor
67//  delete this->target;
68}
69
70void AimingTurret::init()
71{
72  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
73
74  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
75  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
76
77  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
78  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
81
82  animation1->setInfinity(ANIM_INF_CONSTANT);
83  animation2->setInfinity(ANIM_INF_CONSTANT);
84
85  this->setStateDuration(WS_SHOOTING, .1);
86  this->setStateDuration(WS_RELOADING, .1);
87  this->setStateDuration(WS_ACTIVATING, .4);
88  this->setStateDuration(WS_DEACTIVATING, .4);
89
90  this->setMaximumEnergy(10000, 50);
91  this->increaseEnergy(100000);
92
93  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
94  this->setProjectileType(CL_GUIDED_MISSILE);
95
96
97  this->setEmissionPoint(1.684, 0.472, 0);
98  //this->getProjectileFactory()->prepare(100);
99
100  this->target = new Aim(this);
101  this->target->setVisibility(false);
102}
103
104void AimingTurret::loadParams(const TiXmlElement* root)
105{
106  static_cast<Weapon*>(this)->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  Quaternion quat;
123  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
124
125  direction.normalize();
126
127  if (likely (this->getParent() != NULL))
128    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
129  else
130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131
132  this->setAbsDirSoft(quat, 5);
133
134  this->target->tick(dt);
135}
136
137void AimingTurret::fire()
138{
139  Projectile* pj = this->getProjectile();
140  if (pj == NULL)
141    return;
142
143  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
144            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
145
146  pj->setTarget(this->target->getParent());
147  pj->setParent(NullParent::getInstance());
148  pj->setAbsCoor(this->getEmissionPoint());
149  pj->setAbsDir(this->getAbsDir());
150  pj->activate();
151  this->target->searchTarget(100);
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  this->model->draw();
172  glPopMatrix();
173}
174
Note: See TracBrowser for help on using the repository browser.