Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/weapons/cannon.cc @ 6046

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

orxonox/trunk: much cleaner Model Loading unloading, model is now private to WorldEntity (not protected)

File size: 5.2 KB
Line 
1
2
3/*
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
15   co-programmer:
16
17
18   @todo: direction in which the projectile flights
19   @todo: a target to set/hit
20*/
21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
22
23#include "cannon.h"
24
25#include "world_entity.h"
26#include "model.h"
27#include "test_bullet.h"
28#include "weapon_manager.h"
29#include "factory.h"
30
31#include "vector.h"
32#include "list.h"
33#include "animation3d.h"
34
35#include "null_parent.h"
36
37#include "fast_factory.h"
38
39
40using namespace std;
41
42CREATE_FACTORY(Cannon, CL_CANNON);
43
44/**
45 *  standard constructor
46
47   creates a new weapon
48*/
49Cannon::Cannon ()
50  : Weapon()
51{
52  this->init();
53}
54
55
56Cannon::Cannon(const TiXmlElement* root)
57{
58  this->init();
59  this->loadParams(root);
60}
61
62/**
63 *  standard deconstructor
64*/
65Cannon::~Cannon ()
66{
67  // model will be deleted from WorldEntity-destructor
68}
69
70
71void Cannon::init()
72{
73  this->setClassID(CL_CANNON, "Cannon");
74
75//  this->model = (Model*)ResourceManager::getInstance()->load("models/guns/test_gun.obj", OBJ, RP_CAMPAIGN);
76
77  this->loadModel("models/guns/cannon.obj");
78
79  this->setStateDuration(WS_SHOOTING, 2.0);
80  this->setStateDuration(WS_RELOADING, .1);
81  this->setStateDuration(WS_ACTIVATING, .1);
82  this->setStateDuration(WS_DEACTIVATING, .4);
83
84  this->setMaximumEnergy(100, 20);
85  this->increaseEnergy(100);
86  //this->minCharge = 2;
87
88  this->setActionSound(WA_SHOOT, "sound/explo.wav");
89  this->setActionSound(WA_ACTIVATE, "sound/voices/cannon.wav");
90
91  this->setCapability(WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
92  this->setProjectileType(CL_BOMB);
93  this->prepareProjectiles(5);
94
95//  this->objectComponent1 = new PNode();
96//  Animation3D* animation1 = this->getAnimation(WS_SHOOTING, this->objectComponent1);
97  Animation3D* animation2 = this->getAnimation(WS_ACTIVATING, this);
98  Animation3D* animation3 = this->getAnimation(WS_DEACTIVATING, this);
99  //parent->addChild(this->objectComponent1, PNODE_ALL);
100//  this->addChild(this->objectComponent1);
101
102//  animation1->setInfinity(ANIM_INF_CONSTANT);
103  animation2->setInfinity(ANIM_INF_CONSTANT);
104  animation3->setInfinity(ANIM_INF_CONSTANT);
105
106  this->setEmissionPoint(3.8, 1.2, 0);
107
108//     animation1->addKeyFrame(Vector(0, -1.5, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
109//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.1, ANIM_LINEAR, ANIM_NULL);
110//     animation1->addKeyFrame(Vector(0, 0, 0), Quaternion(), 0.0, ANIM_LINEAR, ANIM_NULL);
111
112  animation2->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
113  animation2->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
114
115  animation3->addKeyFrame(Vector(0.0, 0.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
116  animation3->addKeyFrame(Vector(0.0, -1.0, 0.0), Quaternion(), 0.3, ANIM_LINEAR, ANIM_NULL);
117}
118
119
120void Cannon::loadParams(const TiXmlElement* root)
121{
122
123
124}
125
126
127/**
128 *  this activates the weapon
129
130   This is needed, since there can be more than one weapon on a ship. the
131   activation can be connected with an animation. for example the weapon is
132   been armed out.
133*/
134void Cannon::activate()
135{
136}
137
138
139/**
140 *  this deactivates the weapon
141
142   This is needed, since there can be more than one weapon on a ship. the
143   activation can be connected with an animation. for example the weapon is
144   been armed out.
145*/
146void Cannon::deactivate()
147{
148}
149
150
151/**
152 *  fires the weapon
153
154   this is called from the player.cc, when fire-button is been pushed
155   @todo: the ObjectManager deliveres Projectiles not TestBullets! this should be diffrent
156*/
157void Cannon::fire()
158{
159  Projectile* pj =  this->getProjectile();
160  if (pj == NULL)
161    return;
162
163  pj->setParent(NullParent::getInstance());
164
165  pj->setVelocity(this->getVelocity() + this->getAbsDir().apply(Vector(1,0,0))*15+VECTOR_RAND(5));
166
167  pj->setAbsCoor(this->getEmissionPoint());
168  pj->setAbsDir(this->getAbsDir());
169  pj->activate();
170}
171
172/**
173 *  is called, when the weapon is destroyed
174 *
175 * this is in conjunction with the hit function, so when a weapon is able to get
176 * hit, it can also be destoryed.
177*/
178void Cannon::destroy ()
179{}
180
181/**
182 *  this will draw the weapon
183*/
184void Cannon::draw () const
185{
186  /* draw gun body */
187  glMatrixMode(GL_MODELVIEW);
188  glPushMatrix();
189  glTranslatef (this->getAbsCoor ().x,
190                this->getAbsCoor ().y,
191                this->getAbsCoor ().z);
192
193  Vector tmpRot = this->getAbsDir().getSpacialAxis();
194  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
195
196  this->getModel()->draw();
197  glPopMatrix();
198
199  /* draw objectComponent1: gun coil - animated stuff */
200/*  glMatrixMode(GL_MODELVIEW);
201  glPushMatrix();
202  glTranslatef (this->objectComponent1->getAbsCoor ().x,
203                this->objectComponent1->getAbsCoor ().y,
204                this->objectComponent1->getAbsCoor ().z);
205  tmpRot = this->objectComponent1->getAbsDir().getSpacialAxis();
206  glRotatef (this->objectComponent1->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
207  this->model->draw(0);
208
209  glPopMatrix();*/
210}
211
Note: See TracBrowser for help on using the repository browser.