Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/modularships/src/modules/weapons/projectiles/Rocket.cc @ 10001

Last change on this file since 10001 was 9995, checked in by noep, 11 years ago

Modified collision-detecting-process, such that collisions can be traced back to single child-CollisionShapes of Compound-CollisionShapes

  • Property svn:eol-style set to native
File size: 8.9 KB
RevLine 
[6119]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss
24 *   Co-authors:
[8706]25 *      simonmie
[6119]26 *
27 */
28
[8855]29/**
30    @file Rocket.h
31    @brief Implementation of the Rocket class.
32*/
33
[6119]34#include "Rocket.h"
35
[6378]36#include <BulletDynamics/Dynamics/btRigidBody.h>
37
38#include "core/CoreIncludes.h"
[6119]39#include "core/XMLPort.h"
[8855]40
41#include "Scene.h"
42#include "controllers/Controller.h"
43#include "graphics/Model.h"
[6119]44#include "graphics/ParticleSpawner.h"
[8855]45#include "infos/PlayerInfo.h"
[6119]46#include "objects/collisionshapes/ConeCollisionShape.h"
[6247]47#include "sound/WorldSound.h"
[8855]48#include "worldentities/CameraPosition.h"
49#include "worldentities/pawns/Pawn.h"
[6247]50
[6119]51namespace orxonox
52{
[9667]53    RegisterClass(Rocket);
[6119]54
55    /**
56    @brief
57        Constructor. Registers the object and initializes some default values.
58    */
[9667]59    Rocket::Rocket(Context* context)
60        : ControllableEntity(context)
[8738]61        , BasicProjectile()
[9667]62        , RadarViewable(this, static_cast<WorldEntity*>(this))
[6119]63    {
[8855]64        RegisterObject(Rocket);// Register the Rocket class to the core
[6119]65
[6120]66        this->localAngularVelocity_ = 0;
[8855]67        this->lifetime_ = 100.0f;
[6387]68
[6119]69        if (GameMode::isMaster())
70        {
71            this->setCollisionType(WorldEntity::Kinematic);
72            this->setVelocity(0,0,-100);
[6387]73
[8855]74            // Create rocket model
[9667]75            Model* model = new Model(this->getContext());
[6167]76            model->setMeshSource("rocket.mesh");
[6502]77            model->scale(0.7f);
[6167]78            this->attach(model);
[8855]79
80            // Add effects.
[9667]81            ParticleEmitter* fire = new ParticleEmitter(this->getContext());
[6119]82            this->attach(fire);
83            fire->setOrientation(this->getOrientation());
84            fire->setSource("Orxonox/rocketfire");
[6387]85
[6119]86            this->enableCollisionCallback();
87            this->setCollisionResponse(false);
88            this->setCollisionType(Kinematic);
89
[8855]90            // Add collision shape
[9667]91            ConeCollisionShape* collisionShape = new ConeCollisionShape(this->getContext());
[6167]92            collisionShape->setRadius(3);
93            collisionShape->setHeight(500);
94            this->attachCollisionShape(collisionShape);
[6119]95
[8855]96            this->destroyTimer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&BasicProjectile::destroyObject, this)));
[6387]97
[8855]98            // Add sound
[9667]99            this->defSndWpnEngine_ = new WorldSound(this->getContext());
[6313]100            this->defSndWpnEngine_->setLooping(true);
101            this->defSndWpnEngine_->setSource("sounds/Rocket_engine.ogg");
[7848]102            this->defSndWpnEngine_->setVolume(1.0f);
[6313]103            this->attach(defSndWpnEngine_);
[6285]104
[9667]105            this->defSndWpnLaunch_ = new WorldSound(this->getContext());
[6313]106            this->defSndWpnLaunch_->setLooping(false);
107            this->defSndWpnLaunch_->setSource("sounds/Rocket_launch.ogg");
[7848]108            this->defSndWpnLaunch_->setVolume(1.0f);
[6313]109            this->attach(defSndWpnLaunch_);
110        }
111        else
112        {
113            this->defSndWpnEngine_ = 0;
114            this->defSndWpnLaunch_ = 0;
115        }
[6387]116
[8855]117        // Add camera
[9667]118        CameraPosition* camPosition = new CameraPosition(this->getContext());
[6315]119        camPosition->setPosition(0,4,15);
120        camPosition->setAllowMouseLook(true);
121        this->addCameraPosition(camPosition);
[8738]122
123        this->setRadarObjectColour(ColourValue(1.0, 0.5, 0.0)); // orange
124        this->setRadarObjectShape(RadarViewable::Triangle);
125        this->setRadarObjectScale(0.5f);
[6119]126    }
127
128    /**
129    @brief
[6247]130        Destructor. Destroys controller, if present and kills sounds, if playing.
[6119]131    */
132    Rocket::~Rocket()
133    {
134        if(this->isInitialized())
135        {
[7163]136            if (GameMode::isMaster())
137            {
138                this->destructionEffect();
[6383]139
[7163]140                if (this->getPlayer() && this->getController())
141                    this->player_->stopTemporaryControl();
142            }
143
[6315]144            if ( this->defSndWpnEngine_ )
[6381]145                this->defSndWpnEngine_->destroy();
[6383]146
[6315]147            if ( this->defSndWpnLaunch_ )
[6381]148                this->defSndWpnLaunch_->destroy();
[6119]149        }
150    }
151
152    /**
153    @brief
[8855]154        Sets the entity that fired the Rocket.
155    @param shooter
156        A pointer to the Pawn that fired the Rocket.
[6119]157    */
[8855]158    void Rocket::setShooter(Pawn* shooter)
[6119]159    {
[8855]160        this->BasicProjectile::setShooter(shooter);
161       
162        this->player_ = this->getShooter()->getPlayer();
[9016]163        if(this->player_)
164            this->player_->startTemporaryControl(this);
[6387]165
[6315]166        if( GameMode::isMaster() )
167        {
168            this->defSndWpnEngine_->play();
169            this->defSndWpnLaunch_->play();
170        }
[6119]171    }
172
173    /**
174    @brief
175        Defines which actions the Rocket has to take in each tick.
176    @param dt
177        The length of the tick.
178    */
179    void Rocket::tick(float dt)
180    {
181        SUPER(Rocket, tick, dt);
[6387]182
[6119]183        if( this->hasLocalController() )
184        {
185            this->setAngularVelocity(this->getOrientation() * this->localAngularVelocity_);
186            this->setVelocity( this->getOrientation()*WorldEntity::FRONT*this->getVelocity().length() );
187            this->localAngularVelocity_ = 0;
[7163]188        }
[6387]189
[8855]190       this->destroyCheck();
[6119]191    }
[6387]192
[6119]193    bool Rocket::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
194    {
[8855]195        return this->processCollision(otherObject, contactPoint);
[6119]196    }
[6387]197
[9995]198    bool Rocket::customCollidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
199    {
200        return this->customProcessCollision(otherObject, contactPoint, cs);
201    }
202
[8855]203    /**
204    @brief
205        Destroys the Rocket and stops the sound,
206    */
207    void Rocket::destroyObject(void)
[6119]208    {
[8855]209        if (GameMode::isMaster() && this->defSndWpnEngine_->isPlaying())
210            this->defSndWpnEngine_->stop();
211
212        this->BasicProjectile::destroyObject();
[6119]213    }
[6387]214
[8855]215    /**
216    @brief
217        Destroys the Rocket upon pressing "fire".
218    */
[6119]219    void Rocket::fired(unsigned int firemode)
220    {
[8855]221        this->destroyObject();
[7163]222    }
[7848]223
[8855]224    /**
225    @brief
226        The effects that are displayed, when the Rocket is destroyed.
227    */
[7163]228    void Rocket::destructionEffect()
229    {
230        ParticleSpawner *effect1, *effect2;
[8855]231        if(this->getShooter())
[6119]232        {
[9667]233            effect1 = new ParticleSpawner(this->getShooter()->getContext());
234            effect2 = new ParticleSpawner(this->getShooter()->getContext());
[6119]235        }
[7163]236        else
237        {
[9667]238            effect1 = new ParticleSpawner(this->getContext());
239            effect2 = new ParticleSpawner(this->getContext());
[7163]240        }
[7848]241
[7163]242        effect1->setPosition(this->getPosition());
243        effect1->setOrientation(this->getOrientation());
244        effect1->setDestroyAfterLife(true);
245        effect1->setSource("Orxonox/explosion4");
246        effect1->setLifetime(2.0f);
[7848]247
[7163]248        effect2->setPosition(this->getPosition());
249        effect2->setOrientation(this->getOrientation());
250        effect2->setDestroyAfterLife(true);
251        effect2->setSource("Orxonox/smoke4");
252        effect2->setLifetime(3.0f);
[6119]253    }
254
255    /**
256    @brief
257        Rotates the Rocket around the y-axis by the amount specified by the first component of the input 2-dim vector.
258    @param value
259        The vector determining the amount of the angular movement.
260    */
261    void Rocket::rotateYaw(const Vector2& value)
262    {
263        ControllableEntity::rotateYaw(value);
[6387]264
[6119]265        if( !this->isInMouseLook() )
266            this->localAngularVelocity_.y += value.x;
267    }
268
269    /**
270    @brief
271        Rotates the Rocket around the x-axis by the amount specified by the first component of the input 2-dim vector.
272    @param value
273        The vector determining the amount of the angular movement.
274    */
275    void Rocket::rotatePitch(const Vector2& value)
276    {
277        ControllableEntity::rotatePitch(value);
[6387]278
[6119]279        if( !this->isInMouseLook() )
280            this->localAngularVelocity_.x += value.x;
281    }
282
283    /**
284    @brief
285        Rotates the Rocket around the z-axis by the amount specified by the first component of the input 2-dim vector.
286    @param value
287        The vector determining the amount of the angular movement.
288    */
289    void Rocket::rotateRoll(const Vector2& value)
290    {
291        ControllableEntity::rotateRoll(value);
[6387]292
[6119]293        if( !this->isInMouseLook() )
294            this->localAngularVelocity_.z += value.x;
295    }
[6387]296
[6119]297}
Note: See TracBrowser for help on using the repository browser.