Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5762 was 5762, checked in by snellen, 18 years ago

guided_missile updated

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