Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 4967 was 4967, checked in by bensch, 19 years ago

orxonox/trunk: multiple sounds on the turret
this does not really work, as openAL is only really able to play back one effect on a SoundSource, this is rather silly…. check it out …

File size: 3.8 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*/
15
16
[4963]17#include "turret.h"
[3618]18
[4963]19#include "weapon_manager.h"
[3710]20#include "test_bullet.h"
[3618]21
[4829]22#include "state.h"
[3618]23#include "vector.h"
[3629]24#include "list.h"
[3851]25#include "animation3d.h"
[4504]26#include "sound_engine.h"
[3618]27
[4940]28#include "fast_factory.h"
[4287]29
[4931]30
[3618]31using namespace std;
32
33
34/**
[4836]35 *  standard constructor
[3618]36
37   creates a new weapon
38*/
[4963]39Turret::Turret (WeaponManager* weaponManager)
[4955]40  : Weapon(weaponManager)
[3683]41{
[4963]42  this->setClassID(CL_TURRET, "Turret");
[4597]43
[4963]44  this->model = (Model*)ResourceManager::getInstance()->load("models/turret1.obj", OBJ, RP_CAMPAIGN);
[3752]45
[4964]46  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
47  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]48
[4964]49  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
50  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
51  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
52  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
53
[4893]54  animation1->setInfinity(ANIM_INF_CONSTANT);
55  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]56
[4906]57  this->setStateDuration(WS_SHOOTING, .4);
[4964]58  this->setStateDuration(WS_RELOADING, 2);
[4910]59  this->setStateDuration(WS_ACTIVATING, .4);
60  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]61
[4930]62  this->setMaximumEnergy(1000, 10);
[4927]63  this->increaseEnergy(100);
64  //this->minCharge = 2;
[4885]65
66  this->setActionSound(WA_SHOOT, "sound/shot1.wav");
[4967]67  this->setActionSound(WA_ACTIVATE, "sound/vocals/missiles.wav");
68  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
[4934]69
[4947]70  this->setProjectile(CL_TEST_BULLET);
[4964]71
72  this->setEmissionPoint(1.684, 0.472, 0);
[4948]73  //this->getProjectileFactory()->prepare(100);
[3683]74}
[3618]75
76
77/**
[4836]78 *  standard deconstructor
[3618]79*/
[4963]80Turret::~Turret ()
[3618]81{
82  // model will be deleted from WorldEntity-destructor
83}
84
[4963]85void Turret::activate()
[3980]86{
87}
[3618]88
[4963]89void Turret::deactivate()
[3980]90{
91}
[3618]92
[4964]93void Turret::tick(float dt)
94{
95  Vector direction = this->getWeaponManager()->getFixedTarget()->getAbsCoor() - this->getAbsCoor();
96  direction.normalize();
[4966]97  Quaternion quat = Quaternion(direction, this->getParent()->getAbsDir().apply(Vector(0,1,0))) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
[3618]98
[4965]99  this->setAbsDir(quat);
[4964]100}
101
[3618]102/**
[4836]103 *  fires the weapon
[4592]104
[3618]105   this is called from the player.cc, when fire-button is been pushed
106*/
[4963]107void Turret::fire()
[3620]108{
[4947]109  Projectile* pj =  dynamic_cast<Projectile*>(this->getProjectileFactory()->resurrect());
[3888]110
[4955]111  PNode* target = this->getWeaponManager()->getFixedTarget();
112
113  if (target != NULL)
114  {
[4959]115    pj->setVelocity(this->getVelocity()+(target->getAbsCoor() - this->getAbsCoor())*.5);//this->getVelocity());
[4964]116    pj->setAbsDir(this->getAbsDir());
[4955]117  }
118  else
119    pj->setVelocity(target->getVelocity());
120
121
[4927]122  pj->setAbsCoor(this->getEmissionPoint());
[3708]123  pj->setAbsDir(this->getAbsDir());
[4829]124  State::getWorldEntityList()->add(pj);
[3620]125}
[3618]126
127
128/**
[4836]129 *  is called, when the weapon is destroyed
[3618]130
131   this is in conjunction with the hit function, so when a weapon is able to get
132   hit, it can also be destoryed.
133*/
[4963]134void Turret::destroy ()
[3618]135{}
136
137/**
[4836]138 *  this will draw the weapon
[3618]139*/
[4963]140void Turret::draw ()
[3750]141{
[4955]142  this->getWeaponManager()->getFixedTarget()->debugDraw(10);
143
[3886]144  /* draw gun body */
[3750]145  glMatrixMode(GL_MODELVIEW);
146  glPushMatrix();
147  float matrix[4][4];
[4592]148  glTranslatef (this->getAbsCoor ().x,
149                this->getAbsCoor ().y,
150                this->getAbsCoor ().z);
[3886]151  this->getAbsDir ().matrix (matrix);
152  glMultMatrixf((float*)matrix);
[3752]153
[4963]154  this->model->draw();
[3750]155  glPopMatrix();
156}
[3618]157
Note: See TracBrowser for help on using the repository browser.