Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/particleEffectsHS15/src/modules/weapons/projectiles/IceGunProjectile.cc @ 10948

Last change on this file since 10948 was 10911, checked in by fvultier, 9 years ago
File size: 4.1 KB
Line 
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 *      Fabien Vultier
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file IceGunProjectile.cc
31    @brief Implementation of the IceGunProjectile class.
32*/
33
34#include "IceGunProjectile.h"
35
36#include <OgreSceneManager.h>
37#include <OgreSceneNode.h>
38
39#include "core/CoreIncludes.h"
40#include "graphics/Model.h"
41#include "graphics/ParticleSpawner.h"
42#include "Scene.h"
43#include "core/command/Executor.h"
44#include "tools/ParticleInterface.h"
45
46namespace orxonox
47{
48    RegisterClass(IceGunProjectile);
49
50    const float IceGunProjectile::particleDestructionDelay_ = 15.0f;
51
52    IceGunProjectile::IceGunProjectile(Context* context) : Projectile(context)
53    {
54        RegisterObject(IceGunProjectile);
55
56        this->setCollisionShapeRadius(8.0f);
57
58        this->setFreezeTime(3.0);
59        this->setFreezeFactor(0.5);
60
61        Model* model = new Model(this->getContext());
62        model->setMeshSource("IceBolt.mesh");
63        model->setScale(15.0);
64        this->attach(model);
65        model->setPosition(Vector3(0,0,0));
66
67        // Add effect.
68        emitter_ = new ParticleEmitter(this->getContext());
69        this->attach(emitter_);
70        emitter_->setOrientation(this->getOrientation());
71        emitter_->setSource("Orxonox/ice");   
72        emitter_->setDeleteWithParent(false);     
73    }
74
75    IceGunProjectile::~IceGunProjectile()
76    {
77        if (this->isInitialized())
78        {
79            const Vector3& pos = emitter_->getWorldPosition();
80            const Quaternion& rot = emitter_->getWorldOrientation();
81            this->detach(emitter_);
82            emitter_->setPosition(pos);
83            emitter_->setOrientation(rot);
84            emitter_->getParticleInterface()->setEnabled(false);
85            this->getScene()->getRootSceneNode()->addChild(const_cast<Ogre::SceneNode*>(emitter_->getNode()));
86
87            const ExecutorPtr& executor = createExecutor(createFunctor(&ParticleEmitter::destroy, emitter_));
88            new Timer(particleDestructionDelay_, false, executor, true);
89        }
90    }
91
92    /**
93    @brief
94        Sets the freeze time variable to the passed value.
95    */
96    void IceGunProjectile::setFreezeTime(float freezeTime)
97    {
98        freezeTime_ = freezeTime;
99    }
100
101    /**
102    @brief
103        Sets the freeze factor variable to the passed value.
104    */
105    void IceGunProjectile::setFreezeFactor(float freezeFactor)
106    {
107        freezeFactor_ = freezeFactor;
108    }
109
110    bool IceGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
111    {       
112        bool bCollision = Projectile::collidesAgainst(otherObject, cs, contactPoint);
113
114        if (bCollision)
115        {
116            // If there was a collision, attach a IceGunFreezer to the hit object.
117            IceGunFreezer* freezer = new IceGunFreezer(this->getContext());
118            freezer->setFreezeTime(freezeTime_);
119            freezer->setFreezeFactor(freezeFactor_);
120            otherObject->attach(freezer);           
121
122            Vector3 offset = this->getWorldPosition() - otherObject->getWorldPosition();
123            freezer->setPosition(Vector3(0,0,0));
124            freezer->translate(offset, WorldEntity::World);
125            // Start the freezing effect.
126            freezer->startFreezing();
127        }
128
129        return bCollision;
130    }
131}
Note: See TracBrowser for help on using the repository browser.