Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10836 was 10836, checked in by holzerj, 8 years ago

Added Mine, ice particle, rocketfire, psygun

File size: 4.0 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    IceGunProjectile::IceGunProjectile(Context* context) : Projectile(context)
51    {
52        RegisterObject(IceGunProjectile);
53
54        this->setCollisionShapeRadius(8.0f);
55
56        this->setFreezeTime(3.0);
57        this->setFreezeFactor(0.5);
58
59        Model* model = new Model(this->getContext());
60        model->setMeshSource("IceBolt.mesh");
61        model->setScale(15.0);
62        this->attach(model);
63        model->setPosition(Vector3(0,0,0));
64
65        // Add effect.
66        emitter_ = new ParticleEmitter(this->getContext());
67        this->attach(emitter_);
68        emitter_->setOrientation(this->getOrientation());
69        emitter_->setSource("Orxonox/ice");       
70    }
71
72    IceGunProjectile::~IceGunProjectile()
73    {
74        if (this->isInitialized())
75        {
76            const Vector3& pos = emitter_->getWorldPosition();
77            const Quaternion& rot = emitter_->getWorldOrientation();
78            this->detach(emitter_);
79            emitter_->setPosition(pos);
80            emitter_->setOrientation(rot);
81            emitter_->getParticleInterface()->setEnabled(false);
82            this->getScene()->getRootSceneNode()->addChild(const_cast<Ogre::SceneNode*>(emitter_->getNode()));
83
84            const ExecutorPtr& executor = createExecutor(createFunctor(&ParticleEmitter::destroy, emitter_));
85            new Timer(15, false, executor, true);
86        }
87    }
88
89    /**
90    @brief
91        Sets the freeze time variable to the passed value.
92    */
93    void IceGunProjectile::setFreezeTime(float freezeTime)
94    {
95        freezeTime_ = freezeTime;
96    }
97
98    /**
99    @brief
100        Sets the freeze factor variable to the passed value.
101    */
102    void IceGunProjectile::setFreezeFactor(float freezeFactor)
103    {
104        freezeFactor_ = freezeFactor;
105    }
106
107    bool IceGunProjectile::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* cs, btManifoldPoint& contactPoint)
108    {       
109        bool bCollision = Projectile::collidesAgainst(otherObject, cs, contactPoint);
110
111        if (bCollision)
112        {
113            // If there was a collision, attach a IceGunFreezer to the hit object.
114            IceGunFreezer* freezer = new IceGunFreezer(this->getContext());
115            freezer->setFreezeTime(freezeTime_);
116            freezer->setFreezeFactor(freezeFactor_);
117            otherObject->attach(freezer);           
118
119            Vector3 offset = this->getWorldPosition() - otherObject->getWorldPosition();
120            freezer->setPosition(Vector3(0,0,0));
121            freezer->translate(offset, WorldEntity::World);
122            // Start the freezing effect.
123            freezer->startFreezing();
124        }
125
126        return bCollision;
127    }
128}
Note: See TracBrowser for help on using the repository browser.