Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some minor cleanup, of the mess i made with AutoMake-sh

File size: 4.0 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*/
[5357]15#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3618]16
[4963]17#include "turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[3710]20#include "test_bullet.h"
[3618]21
[5002]22#include "null_parent.h"
[4829]23#include "state.h"
[3618]24#include "vector.h"
[3629]25#include "list.h"
[3851]26#include "animation3d.h"
[4504]27#include "sound_engine.h"
[3618]28
[5355]29#include "factory.h"
[4287]30
[4973]31CREATE_FACTORY(Turret);
[4931]32
[3618]33using namespace std;
34
35
36/**
[4836]37 *  standard constructor
[3618]38
39   creates a new weapon
40*/
[4963]41Turret::Turret (WeaponManager* weaponManager)
[4955]42  : Weapon(weaponManager)
[3683]43{
[4973]44  this->init();
[4597]45
[4982]46  this->loadModel("models/guns/turret1.obj");
[3752]47
[4973]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
[4964]73  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
74  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]75
[4964]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
[4893]81  animation1->setInfinity(ANIM_INF_CONSTANT);
82  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]83
[5064]84  this->setStateDuration(WS_SHOOTING, .1);
85  this->setStateDuration(WS_RELOADING, .1);
[4910]86  this->setStateDuration(WS_ACTIVATING, .4);
87  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]88
[5064]89  this->setMaximumEnergy(10000, 50);
90  this->increaseEnergy(100000);
[4927]91  //this->minCharge = 2;
[4885]92
[4934]93
[5356]94  this->setProjectileType(CL_TEST_BULLET);
[4964]95
[4973]96
[4964]97  this->setEmissionPoint(1.684, 0.472, 0);
[4948]98  //this->getProjectileFactory()->prepare(100);
[4973]99
100
[3683]101}
[3618]102
[4973]103void Turret::loadParams(const TiXmlElement* root)
104{
105  static_cast<Weapon*>(this)->loadParams(root);
[3618]106
107}
108
[4963]109void Turret::activate()
[3980]110{
111}
[3618]112
[4963]113void Turret::deactivate()
[3980]114{
115}
[3618]116
[4964]117void Turret::tick(float dt)
118{
[5001]119  Quaternion quat;
[4964]120  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
[5001]121
[4964]122  direction.normalize();
[5001]123
[4969]124  if (likely (this->getParent() != NULL))
[5001]125    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]126  else
[5001]127    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
128
129  this->setAbsDir(quat);
[4964]130}
131
[4963]132void Turret::fire()
[3620]133{
[5356]134  Projectile* pj = this->getProjectile();
135  if (pj == NULL)
136    return;
[3888]137
[4955]138  PNode* target = this->getWeaponManager()->getFixedTarget();
139
140  if (target != NULL)
141  {
[4959]142    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
[4964]143    pj->setAbsDir(this->getAbsDir());
[4955]144  }
145  else
146    pj->setVelocity(target->getVelocity());
147
[5002]148  pj->setParent(NullParent::getInstance());
[4927]149  pj->setAbsCoor(this->getEmissionPoint());
[3708]150  pj->setAbsDir(this->getAbsDir());
[4829]151  State::getWorldEntityList()->add(pj);
[3620]152}
[3618]153
154
[4963]155void Turret::destroy ()
[3618]156{}
157
158/**
[4969]159 * draws the Turret
[3618]160*/
[4963]161void Turret::draw ()
[3750]162{
[4955]163  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
164
[3886]165  /* draw gun body */
[3750]166  glMatrixMode(GL_MODELVIEW);
167  glPushMatrix();
[4592]168  glTranslatef (this->getAbsCoor ().x,
169                this->getAbsCoor ().y,
170                this->getAbsCoor ().z);
[5000]171  Vector tmpRot = this->getAbsDir().getSpacialAxis();
172  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]173
[4963]174  this->model->draw();
[3750]175  glPopMatrix();
176}
[3618]177
Note: See TracBrowser for help on using the repository browser.