Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/aiming_turret.cc @ 6434

Last change on this file since 6434 was 6434, checked in by bensch, 18 years ago

orxonox/trunk: moved the projectiles to Projectiles

File size: 4.1 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
[5527]17#include "aiming_turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[5559]20#include "aim.h"
[6434]21#include "world_entities/projectiles/projectile.h"
[3618]22
[5511]23#include "model.h"
24
[3851]25#include "animation3d.h"
[3618]26
[5355]27#include "factory.h"
[4287]28
[5622]29CREATE_FACTORY(AimingTurret, CL_AIMING_TURRET);
[4931]30
[3618]31using namespace std;
32
33
34/**
[4836]35 *  standard constructor
[3618]36
37   creates a new weapon
38*/
[5745]39AimingTurret::AimingTurret ()
40  : Weapon()
[3683]41{
[4973]42  this->init();
[4597]43
[5559]44  this->loadModel("models/guns/turret2.obj");
[3752]45
[4973]46
47  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
[5819]48  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
[4973]49  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
50}
51
52
[5527]53AimingTurret::AimingTurret(const TiXmlElement* root)
[4973]54{
55  this->init();
56  this->loadParams(root);
57}
58
59/**
60 *  standard deconstructor
61*/
[5527]62AimingTurret::~AimingTurret ()
[4973]63{
64  // model will be deleted from WorldEntity-destructor
[5574]65//  delete this->target;
[4973]66}
67
[5527]68void AimingTurret::init()
[4973]69{
[5527]70  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
[4973]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
[5064]83  this->setStateDuration(WS_SHOOTING, .1);
84  this->setStateDuration(WS_RELOADING, .1);
[4910]85  this->setStateDuration(WS_ACTIVATING, .4);
86  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]87
[5064]88  this->setMaximumEnergy(10000, 50);
89  this->increaseEnergy(100000);
[4885]90
[5441]91  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[6426]92  this->setProjectileType(CL_ROCKET);
[4964]93
[4973]94
[4964]95  this->setEmissionPoint(1.684, 0.472, 0);
[4948]96  //this->getProjectileFactory()->prepare(100);
[5527]97
[5567]98  this->target = new Aim(this);
[5560]99  this->target->setVisibility(false);
[3683]100}
[3618]101
[5527]102void AimingTurret::loadParams(const TiXmlElement* root)
[4973]103{
104  static_cast<Weapon*>(this)->loadParams(root);
[3618]105
106}
107
[5527]108void AimingTurret::activate()
[3980]109{
[5560]110  this->target->setVisibility(true);
[3980]111}
[3618]112
[5527]113void AimingTurret::deactivate()
[3980]114{
[5560]115  this->target->setVisibility(false);
[3980]116}
[3618]117
[5527]118void AimingTurret::tick(float dt)
[4964]119{
[5001]120  Quaternion quat;
[5527]121  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
[5001]122
[4964]123  direction.normalize();
[5001]124
[4969]125  if (likely (this->getParent() != NULL))
[5001]126    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]127  else
[5001]128    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
129
[5559]130  this->setAbsDirSoft(quat, 5);
131
132  this->target->tick(dt);
[4964]133}
134
[5527]135void AimingTurret::fire()
[3620]136{
[5356]137  Projectile* pj = this->getProjectile();
138  if (pj == NULL)
139    return;
[3888]140
[5915]141  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
[5440]142            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]143
[6074]144  pj->setParent(PNode::getNullParent());
[4927]145  pj->setAbsCoor(this->getEmissionPoint());
[3708]146  pj->setAbsDir(this->getAbsDir());
[5443]147  pj->activate();
[5576]148  this->target->searchTarget(100);
[3620]149}
[3618]150
[5527]151void AimingTurret::destroy ()
[3618]152{}
153
154/**
[5527]155 * draws the AimingTurret
[3618]156*/
[5527]157void AimingTurret::draw () const
[3750]158{
[3886]159  /* draw gun body */
[3750]160  glMatrixMode(GL_MODELVIEW);
161  glPushMatrix();
[4592]162  glTranslatef (this->getAbsCoor ().x,
163                this->getAbsCoor ().y,
164                this->getAbsCoor ().z);
[5000]165  Vector tmpRot = this->getAbsDir().getSpacialAxis();
166  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]167
[5994]168  this->getModel()->draw();
[3750]169  glPopMatrix();
170}
[3618]171
Note: See TracBrowser for help on using the repository browser.