Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/avi_play/src/world_entities/weapons/turret.cc @ 5963

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

orxonox/branches/avi_play: merged the trunk back to the avi_play branche again
merged with command
svn merge -r 5924:HEAD ../trunk/ avi_play/

File size: 3.9 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 "turret.h"
18
19#include "weapon_manager.h"
20#include "projectile.h"
21
22#include "model.h"
23
24#include "null_parent.h"
25#include "state.h"
26#include "list.h"
27#include "animation3d.h"
28
29#include "factory.h"
30
31CREATE_FACTORY(Turret, CL_TURRET);
32
33using namespace std;
34
35/**
36 *  standard constructor
37 *
38 * creates a new Turret
39 */
40Turret::Turret ()
41  : Weapon()
42{
43  this->init();
44
45  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
46  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
47  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
48
49  this->loadModel("models/guns/turret1.obj");
50}
51
52/**
53 * creates a new Turret from a TiXmlElement
54 */
55Turret::Turret(const TiXmlElement* root)
56{
57  this->init();
58  this->loadParams(root);
59}
60
61/**
62 *  standard deconstructor
63*/
64Turret::~Turret ()
65{
66  // model will be deleted from WorldEntity-destructor
67}
68
69void Turret::init()
70{
71  this->setClassID(CL_TURRET, "Turret");
72
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  //this->minCharge = 2;
93
94  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
95  this->setProjectileType(CL_ROCKET);
96
97
98  this->setEmissionPoint(1.684, 0.472, 0);
99  //this->getProjectileFactory()->prepare(100);
100}
101
102void Turret::loadParams(const TiXmlElement* root)
103{
104  static_cast<Weapon*>(this)->loadParams(root);
105
106}
107
108void Turret::activate()
109{
110}
111
112void Turret::deactivate()
113{
114}
115
116void Turret::tick(float dt)
117{
118  Quaternion quat;
119  Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();*/
120
121  direction.normalize();
122
123  if (likely (this->getParent() != NULL))
124    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
125  else
126    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
127
128  this->setAbsDirSoft(quat, 5);
129}
130
131void Turret::fire()
132{
133  Projectile* pj = this->getProjectile();
134  if (pj == NULL)
135    return;
136
137  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */
138            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
139
140
141  pj->setParent(NullParent::getInstance());
142  pj->setAbsCoor(this->getEmissionPoint());
143  pj->setAbsDir(this->getAbsDir());
144  pj->activate();
145}
146
147void Turret::destroy ()
148{}
149
150/**
151 * draws the Turret
152*/
153void Turret::draw () const
154{
155  if (this->model != NULL)
156  {
157    /* draw gun body */
158    glMatrixMode(GL_MODELVIEW);
159    glPushMatrix();
160    glTranslatef (this->getAbsCoor ().x,
161                  this->getAbsCoor ().y,
162                  this->getAbsCoor ().z);
163    Vector tmpRot = this->getAbsDir().getSpacialAxis();
164    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
165
166    this->model->draw();
167    glPopMatrix();
168  }
169}
Note: See TracBrowser for help on using the repository browser.