Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/world_entities/weapons/turret.cc @ 5064

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

orxonox/trunk: shooting-star :)

File size: 4.0 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
16
17#include "turret.h"
18
19#include "weapon_manager.h"
20#include "test_bullet.h"
21
22#include "null_parent.h"
23#include "state.h"
24#include "vector.h"
25#include "list.h"
26#include "animation3d.h"
27#include "sound_engine.h"
28
29#include "fast_factory.h"
30
31CREATE_FACTORY(Turret);
32
33using namespace std;
34
35
36/**
37 *  standard constructor
38
39   creates a new weapon
40*/
41Turret::Turret (WeaponManager* weaponManager)
42  : Weapon(weaponManager)
43{
44  this->init();
45
46  this->loadModel("models/guns/turret1.obj");
47
48
49  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
50  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
51  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
52}
53
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  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
74  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
75
76  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
77  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
78  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
80
81  animation1->setInfinity(ANIM_INF_CONSTANT);
82  animation2->setInfinity(ANIM_INF_CONSTANT);
83
84  this->setStateDuration(WS_SHOOTING, .1);
85  this->setStateDuration(WS_RELOADING, .1);
86  this->setStateDuration(WS_ACTIVATING, .4);
87  this->setStateDuration(WS_DEACTIVATING, .4);
88
89  this->setMaximumEnergy(10000, 50);
90  this->increaseEnergy(100000);
91  //this->minCharge = 2;
92
93
94  this->setProjectile(CL_TEST_BULLET);
95
96
97  this->setEmissionPoint(1.684, 0.472, 0);
98  //this->getProjectileFactory()->prepare(100);
99
100
101}
102
103void Turret::loadParams(const TiXmlElement* root)
104{
105  static_cast<Weapon*>(this)->loadParams(root);
106
107}
108
109void Turret::activate()
110{
111}
112
113void Turret::deactivate()
114{
115}
116
117void Turret::tick(float dt)
118{
119  Quaternion quat;
120  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
121
122  direction.normalize();
123
124  if (likely (this->getParent() != NULL))
125    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
126  else
127    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
128
129  this->setAbsDir(quat);
130}
131
132void Turret::fire()
133{
134  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
135
136  PNode* target = this->getWeaponManager()->getFixedTarget();
137
138  if (target != NULL)
139  {
140    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
141    pj->setAbsDir(this->getAbsDir());
142  }
143  else
144    pj->setVelocity(target->getVelocity());
145
146  pj->setParent(NullParent::getInstance());
147  pj->setAbsCoor(this->getEmissionPoint());
148  pj->setAbsDir(this->getAbsDir());
149  State::getWorldEntityList()->add(pj);
150}
151
152
153void Turret::destroy ()
154{}
155
156/**
157 * draws the Turret
158*/
159void Turret::draw ()
160{
161  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
162
163  /* draw gun body */
164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
166  glTranslatef (this->getAbsCoor ().x,
167                this->getAbsCoor ().y,
168                this->getAbsCoor ().z);
169  Vector tmpRot = this->getAbsDir().getSpacialAxis();
170  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
171
172  this->model->draw();
173  glPopMatrix();
174}
175
Note: See TracBrowser for help on using the repository browser.