Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/cannon.cc @ 10651

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

changed the path names to reflect the new data repos

File size: 5.1 KB
RevLine 
[3618]1
2
[4592]3/*
[3618]4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific
14   main-programmer: Patrick Boenzli
[4592]15   co-programmer:
[3631]16
17
[4836]18   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
[3618]20*/
[5357]21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3618]22
[5621]23#include "cannon.h"
[3618]24
25#include "world_entity.h"
[3677]26#include "model.h"
[6434]27#include "world_entities/projectiles/projectile.h"
[4955]28#include "weapon_manager.h"
[7193]29#include "util/loading/factory.h"
[3618]30
31#include "vector.h"
[3851]32#include "animation3d.h"
[3618]33
[9869]34#include "loading/fast_factory.h"
[4287]35
[4931]36
[3618]37
[10114]38
39ObjectListDefinition(Cannon);
[9869]40CREATE_FACTORY(Cannon);
[9406]41
[3618]42/**
[4836]43 *  standard constructor
[3618]44
45   creates a new weapon
46*/
[5745]47Cannon::Cannon ()
48  : Weapon()
[3683]49{
[4974]50  this->init();
[4972]51}
[4885]52
53
[5621]54Cannon::Cannon(const TiXmlElement* root)
[4972]55{
56  this->init();
[6517]57  if (root != NULL)
58    this->loadParams(root);
[4972]59}
60
61/**
62 *  standard deconstructor
63*/
[5621]64Cannon::~Cannon ()
[4972]65{
66  // model will be deleted from WorldEntity-destructor
67}
68
69
[5621]70void Cannon::init()
[4972]71{
[9869]72  this->registerObject(this, Cannon::_objectList);
[4972]73
[5053]74//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
[4972]75
[6811]76  this->loadModel("models/guns/cannon.obj", 1.0);
[5053]77
[5744]78  this->setStateDuration(WS_SHOOTING, 2.0);
[5457]79  this->setStateDuration(WS_RELOADING, .1);
[5744]80  this->setStateDuration(WS_ACTIVATING, .1);
[4910]81  this->setStateDuration(WS_DEACTIVATING, .4);
[4885]82
[6671]83  this->setEnergyMax(100);
[5828]84  this->increaseEnergy(100);
[4927]85  //this->minCharge = 2;
[4885]86
[10415]87  this->setActionSound(WA_SHOOT, "sounds/explo.wav");
88  this->setActionSound(WA_ACTIVATE, "sounds/voices/cannon.wav");
[4934]89
[6803]90  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL | WTYPE_HEAVY);
[9869]91  this->setProjectileTypeC("Bomb");
[5744]92  this->prepareProjectiles(5);
[5457]93
[5623]94//  this->objectComponent1 = new PNode();
95//  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
96  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
97  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
98  //parent->addChild(this->objectComponent1, PNODE_ALL);
99//  this->addChild(this->objectComponent1);
100
101//  animation1->setInfinity(ANIM_INF_CONSTANT);
102  animation2->setInfinity(ANIM_INF_CONSTANT);
103  animation3->setInfinity(ANIM_INF_CONSTANT);
104
105  this->setEmissionPoint(3.8, 1.2, 0);
106
107//     animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
108//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
109//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
110
111  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
112  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
113
114  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
115  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
[3683]116}
[3618]117
118
[5621]119void Cannon::loadParams(const TiXmlElement* root)
[3618]120{
[6512]121  Weapon::loadParams(root);
[3618]122}
123
124
125/**
[4836]126 *  this activates the weapon
[3618]127
[4592]128   This is needed, since there can be more than one weapon on a ship. the
129   activation can be connected with an animation. for example the weapon is
130   been armed out.
[3618]131*/
[5621]132void Cannon::activate()
[3980]133{
134}
[3618]135
136
137/**
[4836]138 *  this deactivates the weapon
[3618]139
[4592]140   This is needed, since there can be more than one weapon on a ship. the
141   activation can be connected with an animation. for example the weapon is
[3618]142   been armed out.
143*/
[5621]144void Cannon::deactivate()
[3980]145{
146}
[3618]147
148
149/**
[4836]150 *  fires the weapon
[4592]151
[3618]152   this is called from the player.cc, when fire-button is been pushed
[4836]153   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
[3618]154*/
[5621]155void Cannon::fire()
[3620]156{
[5356]157  Projectile* pj =  this->getProjectile();
158  if (pj == NULL)
159    return;
[3888]160
[6074]161  pj->setParent(PNode::getNullParent());
[5000]162
[5744]163  pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5));
[4955]164
[4927]165  pj->setAbsCoor(this->getEmissionPoint());
[3708]166  pj->setAbsDir(this->getAbsDir());
[5443]167  pj->activate();
[3620]168}
[3618]169
170
171/**
[4836]172 *  this will draw the weapon
[3618]173*/
[5621]174void Cannon::draw () const
[3750]175{
[3886]176  /* draw gun body */
[3750]177  glMatrixMode(GL_MODELVIEW);
178  glPushMatrix();
[4592]179  glTranslatef (this->getAbsCoor ().x,
180                this->getAbsCoor ().y,
181                this->getAbsCoor ().z);
[5000]182
183  Vector tmpRot = this->getAbsDir().getSpacialAxis();
184  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
185
[5994]186  this->getModel()->draw();
[3752]187  glPopMatrix();
188
[3886]189  /* draw objectComponent1: gun coil - animated stuff */
[5621]190/*  glMatrixMode(GL_MODELVIEW);
[3752]191  glPushMatrix();
[4592]192  glTranslatef (this->objectComponent1->getAbsCoor ().x,
193                this->objectComponent1->getAbsCoor ().y,
194                this->objectComponent1->getAbsCoor ().z);
[5000]195  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
196  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
[3752]197  this->model->draw(0);
[5621]198
199  glPopMatrix();*/
[3750]200}
[3618]201
Note: See TracBrowser for help on using the repository browser.