Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/RotatingProjectile.cc @ 1627

Last change on this file since 1627 was 1558, checked in by landauf, 16 years ago

added support for isVisible() and isActive() to all objects.
those functions are provided by BaseObject, combined with virtual functions changedVisibility and changedActivity respectively.
use them, to make orxonox scriptable, say: to change the state of objects with 2 simple functions instead of changing all meshes and emitters and billboards of an object. don't forget to pass calls to changedVisibility and changedActivity to the parent class.

additionally there is a new function, isInitialized(), provided by BaseObject too. this returns true if the constructor of BaseObject passed the object registration. this allows you, to check whether an object was properly initialized or if the constructor returned (as this is the case while creating the class hierarchy). use isInitialized() in your destructor before deleting something.

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 */
27
28#include "OrxonoxStableHeaders.h"
29#include "RotatingProjectile.h"
30
31#include "core/CoreIncludes.h"
32#include "core/ConfigValueIncludes.h"
33#include <OgreBillboard.h>
34
35namespace orxonox
36{
37    CreateFactory(RotatingProjectile);
38
39    RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner)
40    {
41        RegisterObject(RotatingProjectile);
42
43        this->time_ = 0;
44
45        if (/*this->owner_*/true)
46        {
47            this->rotatingBillboard1_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
48            this->rotatingBillboard2_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
49
50            this->rotatingNode1_ = this->getNode()->createChildSceneNode(this->getName() + "rotating1", Vector3(0, 50, 0));
51            this->rotatingNode2_ = this->getNode()->createChildSceneNode(this->getName() + "rotating2", Vector3(0, -50, 0));
52            this->rotatingNode1_->attachObject(this->rotatingBillboard1_.getBillboardSet());
53            this->rotatingNode2_->attachObject(this->rotatingBillboard2_.getBillboardSet());
54            this->rotatingNode1_->scale(0.3, 0.3, 0.3);
55            this->rotatingNode2_->scale(0.3, 0.3, 0.3);
56        }
57
58        this->setConfigValues();
59    }
60
61    RotatingProjectile::~RotatingProjectile()
62    {
63    }
64
65    void RotatingProjectile::setConfigValues()
66    {
67        SetConfigValue(colour_, ColourValue(1.0, 0.0, 0.0));
68
69        this->rotatingBillboard1_.getBillboardSet()->getBillboard(0)->setColour(this->colour_);
70        this->rotatingBillboard2_.getBillboardSet()->getBillboard(0)->setColour(this->colour_);
71    }
72
73    void RotatingProjectile::tick(float dt)
74    {
75        if (this->isActive())
76        {
77            this->time_ += dt;
78
79            this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20));
80            this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20));
81        }
82
83        Projectile::tick(dt);
84    }
85
86    void RotatingProjectile::changedVisibility()
87    {
88        BillboardProjectile::changedVisibility();
89        this->rotatingBillboard1_.setVisible(this->isVisible());
90        this->rotatingBillboard2_.setVisible(this->isVisible());
91    }
92}
Note: See TracBrowser for help on using the repository browser.