Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/turret.cc @ 5877

Last change on this file since 5877 was 5819, checked in by bensch, 19 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.0 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
[4963]17#include "turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[5511]20#include "projectile.h"
[3618]21
[5511]22#include "model.h"
23
[5002]24#include "null_parent.h"
[4829]25#include "state.h"
[3629]26#include "list.h"
[3851]27#include "animation3d.h"
[4504]28#include "sound_engine.h"
[3618]29
[5355]30#include "factory.h"
[4287]31
[5750]32CREATE_FACTORY(Turret, CL_TURRET);
[4931]33
[3618]34using namespace std;
35
36/**
[4836]37 *  standard constructor
[5750]38 *
39 * creates a new Turret
40 */
41Turret::Turret ()
42  : Weapon()
[3683]43{
[4973]44  this->init();
[4597]45
[4973]46  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
47  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
48  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
[5819]49
50  this->loadModel("models/guns/turret1.obj");
[4973]51}
52
[5750]53/**
54 * creates a new Turret from a TiXmlElement
55 */
[4973]56Turret::Turret(const TiXmlElement* root)
57{
58  this->init();
59  this->loadParams(root);
60}
61
62/**
63 *  standard deconstructor
64*/
65Turret::~Turret ()
66{
67  // model will be deleted from WorldEntity-destructor
68}
69
70void Turret::init()
71{
72  this->setClassID(CL_TURRET, "Turret");
73
[5819]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);
[5456]96  this->setProjectileType(CL_ROCKET);
[4964]97
[4973]98
[4964]99  this->setEmissionPoint(1.684, 0.472, 0);
[4948]100  //this->getProjectileFactory()->prepare(100);
[3683]101}
[3618]102
[4973]103void Turret::loadParams(const TiXmlElement* root)
104{
105  static_cast<Weapon*>(this)->loadParams(root);
[3618]106
107}
108
[4963]109void Turret::activate()
[3980]110{
111}
[3618]112
[4963]113void Turret::deactivate()
[3980]114{
115}
[3618]116
[4964]117void Turret::tick(float dt)
118{
[5001]119  Quaternion quat;
[5750]120  Vector direction = this->getAbsCoor();/*this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();*/
[5001]121
[4964]122  direction.normalize();
[5001]123
[4969]124  if (likely (this->getParent() != NULL))
[5001]125    quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[4969]126  else
[5001]127    quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
128
[5414]129  this->setAbsDirSoft(quat, 5);
[4964]130}
131
[4963]132void Turret::fire()
[3620]133{
[5356]134  Projectile* pj = this->getProjectile();
135  if (pj == NULL)
136    return;
[3888]137
[5819]138  pj->setVelocity(this->getVelocity()+(this->getAbsDir().apply(Vector(1,0,0))*100.0 /*+ VECTOR_RAND(13) */
[5440]139            /*target->getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]140
[5819]141
[5002]142  pj->setParent(NullParent::getInstance());
[4927]143  pj->setAbsCoor(this->getEmissionPoint());
[3708]144  pj->setAbsDir(this->getAbsDir());
[5443]145  pj->activate();
[3620]146}
[3618]147
[4963]148void Turret::destroy ()
[3618]149{}
150
151/**
[4969]152 * draws the Turret
[3618]153*/
[5500]154void Turret::draw () const
[3750]155{
[5819]156  if (this->model != NULL)
157  {
158    /* draw gun body */
159    glMatrixMode(GL_MODELVIEW);
160    glPushMatrix();
161    glTranslatef (this->getAbsCoor ().x,
162                  this->getAbsCoor ().y,
163                  this->getAbsCoor ().z);
164    Vector tmpRot = this->getAbsDir().getSpacialAxis();
165    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]166
[5819]167    this->model->draw();
168    glPopMatrix();
169  }
[3750]170}
Note: See TracBrowser for help on using the repository browser.