Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6693 was 6693, checked in by patrick, 18 years ago

branches: removed spaceshipcontrol branche

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
[6693]88  this->setEnergyMax(10000);
[5064]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);
[6693]100  this->target->setRange(100);
101  this->target->setAngle(M_PI);
[3683]102}
[3618]103
[5527]104void AimingTurret::loadParams(const TiXmlElement* root)
[4973]105{
[6512]106  Weapon::loadParams(root);
[3618]107
108}
109
[5527]110void AimingTurret::activate()
[3980]111{
[5560]112  this->target->setVisibility(true);
[3980]113}
[3618]114
[5527]115void AimingTurret::deactivate()
[3980]116{
[5560]117  this->target->setVisibility(false);
[3980]118}
[3618]119
[5527]120void AimingTurret::tick(float dt)
[4964]121{
[5001]122  Quaternion quat;
[5527]123  Vector direction = this->target->getAbsCoor() - this->getAbsCoor();
[5001]124
[4964]125  direction.normalize();
[5001]126
[4969]127  if (likely (this->getParent() != NULL))
[5001]128    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]129  else
[5001]130    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
131
[5559]132  this->setAbsDirSoft(quat, 5);
133
134  this->target->tick(dt);
[4964]135}
136
[5527]137void AimingTurret::fire()
[3620]138{
[5356]139  Projectile* pj = this->getProjectile();
140  if (pj == NULL)
141    return;
[3888]142
[5915]143  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDir().apply(Vector(1,0,0))*250.0 + VECTOR_RAND(13)
[5440]144            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]145
[6074]146  pj->setParent(PNode::getNullParent());
[4927]147  pj->setAbsCoor(this->getEmissionPoint());
[3708]148  pj->setAbsDir(this->getAbsDir());
[5443]149  pj->activate();
[6693]150  this->target->searchTarget();
[3620]151}
[3618]152
[5527]153void AimingTurret::destroy ()
[3618]154{}
155
156/**
[5527]157 * draws the AimingTurret
[3618]158*/
[5527]159void AimingTurret::draw () const
[3750]160{
[3886]161  /* draw gun body */
[3750]162  glMatrixMode(GL_MODELVIEW);
163  glPushMatrix();
[4592]164  glTranslatef (this->getAbsCoor ().x,
165                this->getAbsCoor ().y,
166                this->getAbsCoor ().z);
[5000]167  Vector tmpRot = this->getAbsDir().getSpacialAxis();
168  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]169
[5994]170  this->getModel()->draw();
[3750]171  glPopMatrix();
172}
[3618]173
Note: See TracBrowser for help on using the repository browser.