Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: our first cheat :)

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"
[6434]21#include "world_entities/projectiles/projectile.h"
[3618]22
[5511]23#include "model.h"
24
[3851]25#include "animation3d.h"
[3618]26
[7193]27#include "util/loading/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();
[5559]43  this->loadModel("models/guns/turret2.obj");
[4973]44}
45
46
[5527]47AimingTurret::AimingTurret(const TiXmlElement* root)
[4973]48{
49  this->init();
[7350]50  if (root != NULL)
51    this->loadParams(root);
[4973]52}
53
54/**
55 *  standard deconstructor
56*/
[5527]57AimingTurret::~AimingTurret ()
[4973]58{
59  // model will be deleted from WorldEntity-destructor
[5574]60//  delete this->target;
[4973]61}
62
[5527]63void AimingTurret::init()
[4973]64{
[5527]65  this->setClassID(CL_AIMING_TURRET, "AimingTurret");
[4973]66
[4964]67  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
68  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]69
[4964]70  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
71  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
72  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74
[4893]75  animation1->setInfinity(ANIM_INF_CONSTANT);
76  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]77
[6760]78  this->setStateDuration(WS_SHOOTING, .9);
[5064]79  this->setStateDuration(WS_RELOADING, .1);
[4910]80  this->setStateDuration(WS_ACTIVATING, .4);
81  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]82
[6671]83  this->setEnergyMax(10000);
[5064]84  this->increaseEnergy(100000);
[4885]85
[5441]86  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[7070]87  this->setProjectileType(CL_GUIDED_MISSILE);
[4964]88
[4973]89
[4964]90  this->setEmissionPoint(1.684, 0.472, 0);
[4948]91  //this->getProjectileFactory()->prepare(100);
[5527]92
[5567]93  this->target = new Aim(this);
[5560]94  this->target->setVisibility(false);
[6760]95  this->target->setRange(400);
96  this->target->setAngle(M_PI_2);
[7070]97
98  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
99  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
100  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
101
[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{
[6738]122  if (!Weapon::tickW(dt))
123    return;
[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
[5915]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
[6074]148  pj->setParent(PNode::getNullParent());
[4927]149  pj->setAbsCoor(this->getEmissionPoint());
[3708]150  pj->setAbsDir(this->getAbsDir());
[5443]151  pj->activate();
[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
[7221]171  if (this->getModel())
172    this->getModel()->draw();
[3750]173  glPopMatrix();
174}
[3618]175
Note: See TracBrowser for help on using the repository browser.