Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: movement stuff in the data-filestructure adapted

File size: 3.9 KB
RevLine 
[4592]1/*
[3618]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
[4963]12   main-programmer: Benjamin Grauer
[4592]13   co-programmer:
[3618]14*/
15
16
[4963]17#include "turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[3710]20#include "test_bullet.h"
[3618]21
[4829]22#include "state.h"
[3618]23#include "vector.h"
[3629]24#include "list.h"
[3851]25#include "animation3d.h"
[4504]26#include "sound_engine.h"
[3618]27
[4940]28#include "fast_factory.h"
[4287]29
[4973]30CREATE_FACTORY(Turret);
[4931]31
[3618]32using namespace std;
33
34
35/**
[4836]36 *  standard constructor
[3618]37
38   creates a new weapon
39*/
[4963]40Turret::Turret (WeaponManager* weaponManager)
[4955]41  : Weapon(weaponManager)
[3683]42{
[4973]43  this->init();
[4597]44
[4982]45  this->loadModel("models/guns/turret1.obj");
[3752]46
[4973]47
48  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
49  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
50  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
51}
52
53
54Turret::Turret(const TiXmlElement* root)
55{
56  this->init();
57  this->loadParams(root);
58}
59
60/**
61 *  standard deconstructor
62*/
63Turret::~Turret ()
64{
65  // model will be deleted from WorldEntity-destructor
66}
67
68void Turret::init()
69{
70  this->setClassID(CL_TURRET, "Turret");
71
[4964]72  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
73  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]74
[4964]75  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
76  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
77  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
78  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
79
[4893]80  animation1->setInfinity(ANIM_INF_CONSTANT);
81  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]82
[4906]83  this->setStateDuration(WS_SHOOTING, .4);
[4964]84  this->setStateDuration(WS_RELOADING, 2);
[4910]85  this->setStateDuration(WS_ACTIVATING, .4);
86  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]87
[4930]88  this->setMaximumEnergy(1000, 10);
[4927]89  this->increaseEnergy(100);
90  //this->minCharge = 2;
[4885]91
[4934]92
[4947]93  this->setProjectile(CL_TEST_BULLET);
[4964]94
[4973]95
[4964]96  this->setEmissionPoint(1.684, 0.472, 0);
[4948]97  //this->getProjectileFactory()->prepare(100);
[4973]98
99
[3683]100}
[3618]101
[4973]102void Turret::loadParams(const TiXmlElement* root)
103{
104  static_cast<Weapon*>(this)->loadParams(root);
[3618]105
106}
107
[4963]108void Turret::activate()
[3980]109{
110}
[3618]111
[4963]112void Turret::deactivate()
[3980]113{
114}
[3618]115
[4964]116void Turret::tick(float dt)
117{
118  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
119  direction.normalize();
[4969]120  if (likely (this->getParent() != NULL))
121  {
122    Quaternion quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
123    this->setAbsDir(quat);
124  }
125  else
126  {
127    Quaternion quat = Quaternion(direction, this->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
128    this->setAbsDir(quat);
129  }
[4964]130}
131
[4963]132void Turret::fire()
[3620]133{
[4947]134  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
[3888]135
[4955]136  PNode* target = this->getWeaponManager()->getFixedTarget();
137
138  if (target != NULL)
139  {
[4959]140    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
[4964]141    pj->setAbsDir(this->getAbsDir());
[4955]142  }
143  else
144    pj->setVelocity(target->getVelocity());
145
146
[4927]147  pj->setAbsCoor(this->getEmissionPoint());
[3708]148  pj->setAbsDir(this->getAbsDir());
[4829]149  State::getWorldEntityList()->add(pj);
[3620]150}
[3618]151
152
[4963]153void Turret::destroy ()
[3618]154{}
155
156/**
[4969]157 * draws the Turret
[3618]158*/
[4963]159void Turret::draw ()
[3750]160{
[4955]161  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
162
[3886]163  /* draw gun body */
[3750]164  glMatrixMode(GL_MODELVIEW);
165  glPushMatrix();
166  float matrix[4][4];
[4592]167  glTranslatef (this->getAbsCoor ().x,
168                this->getAbsCoor ().y,
169                this->getAbsCoor ().z);
[3886]170  this->getAbsDir ().matrix (matrix);
171  glMultMatrixf((float*)matrix);
[3752]172
[4963]173  this->model->draw();
[3750]174  glPopMatrix();
175}
[3618]176
Note: See TracBrowser for help on using the repository browser.