Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.6 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
[9869]29#include "class_id_DEPRECATED.h"
30ObjectListDefinitionID(AimingTurret, CL_AIMING_TURRET);
31CREATE_FACTORY(AimingTurret);
[4931]32
[3618]33
34
35/**
[4836]36 *  standard constructor
[3618]37
38   creates a new weapon
39*/
[5745]40AimingTurret::AimingTurret ()
[9656]41    : Weapon(), target(this)
[3683]42{
[4973]43  this->init();
[5559]44  this->loadModel("models/guns/turret2.obj");
[4973]45}
46
47
[5527]48AimingTurret::AimingTurret(const TiXmlElement* root)
[9656]49    : target(this)
[4973]50{
51  this->init();
[7350]52  if (root != NULL)
53    this->loadParams(root);
[4973]54}
55
56/**
57 *  standard deconstructor
58*/
[5527]59AimingTurret::~AimingTurret ()
[4973]60{
61  // model will be deleted from WorldEntity-destructor
[9656]62  //  delete this->target;
[4973]63}
64
[5527]65void AimingTurret::init()
[4973]66{
[9869]67  this->registerObject(this, AimingTurret::_objectList);
[4973]68
[4964]69  Animation3D* animation1 = this->getAnimation(WS_ACTIVATING, this);
70  Animation3D* animation2 = this->getAnimation(WS_DEACTIVATING, this);
[3755]71
[4964]72  animation1->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
73  animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
74  animation2->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
75  animation2->addKeyFrame(Vector(0, -.5, 0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_CONSTANT);
76
[4893]77  animation1->setInfinity(ANIM_INF_CONSTANT);
78  animation2->setInfinity(ANIM_INF_CONSTANT);
[3888]79
[6760]80  this->setStateDuration(WS_SHOOTING, .9);
[5064]81  this->setStateDuration(WS_RELOADING, .1);
[4910]82  this->setStateDuration(WS_ACTIVATING, .4);
83  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]84
[6671]85  this->setEnergyMax(10000);
[5064]86  this->increaseEnergy(100000);
[4885]87
[5441]88  this->setCapability(WTYPE_ALLDIRS | WTYPE_TURRET);
[9869]89  this->setProjectileTypeC("GuidedMissile");
[4964]90
[4973]91
[4964]92  this->setEmissionPoint(1.684, 0.472, 0);
[4948]93  //this->getProjectileFactory()->prepare(100);
[5527]94
[9656]95  this->target.addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT | PNODE_PROHIBIT_CHILD_DELETE);
96  this->target.setVisibility(false);
97  this->target.setRange(400);
98  this->target.setAngle(M_PI_2);
[7070]99
100  this->setActionSound(WA_SHOOT, "sound/explosions/explosion_3.wav");
101  this->setActionSound(WA_ACTIVATE, "sound/voices/rockets.wav");
102  this->setActionSound(WA_RELOAD, "sound/vocals/reload.wav");
103
[3683]104}
[3618]105
[5527]106void AimingTurret::loadParams(const TiXmlElement* root)
[4973]107{
[6512]108  Weapon::loadParams(root);
[3618]109
110}
111
[5527]112void AimingTurret::activate()
[3980]113{
[9656]114  this->target.setVisibility(true);
[3980]115}
[3618]116
[5527]117void AimingTurret::deactivate()
[3980]118{
[9656]119  this->target.setVisibility(false);
[3980]120}
[3618]121
[5527]122void AimingTurret::tick(float dt)
[4964]123{
[6738]124  if (!Weapon::tickW(dt))
125    return;
[5001]126  Quaternion quat;
[9656]127  Vector direction = this->target.getAbsCoor() - this->getAbsCoor();
[5001]128
[4964]129  direction.normalize();
[5001]130
[4969]131  if (likely (this->getParent() != NULL))
[9656]132    //quat = Quaternion(direction, this->getParent()->getAbsDirY()) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
133    quat = Quaternion ( M_PI_2, this->getParent()->getAbsDirY()) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), this->getParent()->getAbsDirY());
[4969]134  else
[9656]135    //quat = Quaternion(direction, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)) ;
136    quat = Quaternion ( M_PI_2, Vector(0,1,0)) * Quaternion::lookAt(this->getAbsCoor(), this->target.getAbsCoor(), Vector(0,1,0));
[5001]137
[5559]138  this->setAbsDirSoft(quat, 5);
139
[9656]140  this->target.tick(dt);
[4964]141}
142
[5527]143void AimingTurret::fire()
[3620]144{
[5356]145  Projectile* pj = this->getProjectile();
146  if (pj == NULL)
147    return;
[3888]148
[9656]149  pj->setVelocity(/*this->getVelocity()+*/(this->getAbsDirX()*250.0 + VECTOR_RAND(4)
150                                          /*target.getAbsCoor() - this->getAbsCoor()*/)*.5);//this->getVelocity());
[4955]151
[6074]152  pj->setParent(PNode::getNullParent());
[4927]153  pj->setAbsCoor(this->getEmissionPoint());
[3708]154  pj->setAbsDir(this->getAbsDir());
[5443]155  pj->activate();
[3620]156}
[3618]157
158
159/**
[5527]160 * draws the AimingTurret
[3618]161*/
[5527]162void AimingTurret::draw () const
[3750]163{
[3886]164  /* draw gun body */
[3750]165  glMatrixMode(GL_MODELVIEW);
166  glPushMatrix();
[4592]167  glTranslatef (this->getAbsCoor ().x,
168                this->getAbsCoor ().y,
169                this->getAbsCoor ().z);
[5000]170  Vector tmpRot = this->getAbsDir().getSpacialAxis();
171  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]172
[7221]173  if (this->getModel())
174    this->getModel()->draw();
[3750]175  glPopMatrix();
176}
[3618]177
Note: See TracBrowser for help on using the repository browser.