Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/world_entities/src/world_entities/weapons/aiming_turret.cc @ 5567

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

orxonox/branches/world_entities: smoother aiming, and also displaying Distance (this is not too nice, but quite good to explain a few Things …

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