Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged branches world_entities to trunk again
merged with command
svn merge -r5795:HEAD branches/world_entities/ trunk/
no conflicts (what a wonder)

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"
[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");
[5819]51  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
[4973]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);
[4885]93
[5441]94  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[5456]95  this->setProjectileType(CL_ROCKET);
[4964]96
[4973]97
[4964]98  this->setEmissionPoint(1.684, 0.472, 0);
[4948]99  //this->getProjectileFactory()->prepare(100);
[5527]100
[5567]101  this->target = new Aim(this);
[5560]102  this->target->setVisibility(false);
[3683]103}
[3618]104
[5527]105void AimingTurret::loadParams(const TiXmlElement* root)
[4973]106{
107  static_cast<Weapon*>(this)->loadParams(root);
[3618]108
109}
110
[5527]111void AimingTurret::activate()
[3980]112{
[5560]113  this->target->setVisibility(true);
[3980]114}
[3618]115
[5527]116void AimingTurret::deactivate()
[3980]117{
[5560]118  this->target->setVisibility(false);
[3980]119}
[3618]120
[5527]121void AimingTurret::tick(float dt)
[4964]122{
[5001]123  Quaternion quat;
[5527]124  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
[5001]125
[4964]126  direction.normalize();
[5001]127
[4969]128  if (likely (this->getParent() != NULL))
[5001]129    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]130  else
[5001]131    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
132
[5559]133  this->setAbsDirSoft(quat, 5);
134
135  this->target->tick(dt);
[4964]136}
137
[5527]138void AimingTurret::fire()
[3620]139{
[5356]140  Projectile* pj = this->getProjectile();
141  if (pj == NULL)
142    return;
[3888]143
[5559]144    pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
[5440]145            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]146
[5002]147  pj->setParent(NullParent::getInstance());
[4927]148  pj->setAbsCoor(this->getEmissionPoint());
[3708]149  pj->setAbsDir(this->getAbsDir());
[5443]150  pj->activate();
[5576]151  this->target->searchTarget(100);
[3620]152}
[3618]153
[5527]154void AimingTurret::destroy ()
[3618]155{}
156
157/**
[5527]158 * draws the AimingTurret
[3618]159*/
[5527]160void AimingTurret::draw () const
[3750]161{
[3886]162  /* draw gun body */
[3750]163  glMatrixMode(GL_MODELVIEW);
164  glPushMatrix();
[4592]165  glTranslatef (this->getAbsCoor ().x,
166                this->getAbsCoor ().y,
167                this->getAbsCoor ().z);
[5000]168  Vector tmpRot = this->getAbsDir().getSpacialAxis();
169  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]170
[4963]171  this->model->draw();
[3750]172  glPopMatrix();
173}
[3618]174
Note: See TracBrowser for help on using the repository browser.