Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/sound3/src/orxonox/interfaces/RadarViewable.cc @ 5945

Last change on this file since 5945 was 5929, checked in by rgrieder, 15 years ago

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

  • Property svn:eol-style set to native
File size: 5.5 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 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "RadarViewable.h"
30
31#include <OgreSceneManager.h>
32#include <OgreSceneNode.h>
33#include <OgreEntity.h>
34
35#include "util/StringUtils.h"
36#include "core/CoreIncludes.h"
37#include "tools/DynamicLines.h"
38#include "worldentities/WorldEntity.h"
39#include "Radar.h"
40#include "Scene.h"
41#include "overlays/Map.h"
42
43namespace orxonox
44{
45    /**
46        @brief Constructor.
47    */
48    RadarViewable::RadarViewable()
49        : MapNode_(NULL)
50        , MapEntity_(NULL)
51        , line_(NULL)
52        , LineNode_(NULL)
53        , radarObjectCamouflage_(0.0f)
54        , radarObjectShape_(Dot)
55        , radarObjectDescription_("staticObject")
56    {
57        RegisterRootObject(RadarViewable);
58
59        this->bVisibility_ = true;
60        this->isHumanShip_ = false;
61
62        this->uniqueId_=getUniqueNumberString();
63/*
64        if(Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr())
65        {
66            this->addEntity();
67        }
68
69        */
70    }
71
72
73    RadarViewable::~RadarViewable()
74    {
75        if (this->isHumanShip_ && MapNode_)
76            MapNode_->removeAllChildren();
77
78        if (MapNode_)
79            delete MapNode_;
80
81        if (MapEntity_)
82            delete MapEntity_;
83
84        if (line_)
85            delete line_;
86
87        if (LineNode_)
88            delete LineNode_;
89    }
90
91    void RadarViewable::addMapEntity()
92    { //TODO Check shape and add accordantly
93        if( this->MapNode_ && !this->MapEntity_ && Map::getSingletonPtr() && Map::getSingletonPtr()->getMapSceneManagerPtr() )
94        {
95            COUT(0) << "Adding " << this->uniqueId_ << " to Map.\n";
96            this->MapEntity_ = Map::getSingletonPtr()->getMapSceneManagerPtr()->createEntity( this->uniqueId_, "drone.mesh");
97            /*this->line_ =  Map::getSingletonPtr()->getMapSceneManagerPtr()->createManualObject(this->uniqueId_ + "_l");
98            this->line_->begin("Map/line_", Ogre::RenderOperation::OT_LINE_STRIP);
99            //line_->position(0, -it->getRVWorldPosition().y, 0);
100            //this->line_->position(0, -20, 0);
101            this->line_->position(0, 0, -10); //Front Arrow
102            this->line_->position(0, 0, 0);
103
104            this->line_->end(); */
105            this->line_ = new Ogre::DynamicLines(Ogre::RenderOperation::OT_LINE_LIST);
106            this->line_->addPoint( Vector3(0,0,0) );
107            this->line_->addPoint( Vector3(0,0,0) );
108
109            this->MapNode_->attachObject( this->MapEntity_ );
110
111            this->LineNode_ = this->MapNode_->createChildSceneNode();
112            this->LineNode_->attachObject( this->line_ );
113        }
114        else
115        {
116            COUT(0) << "Unable to load " << this->uniqueId_ << " to Map.\n";
117        }
118    }
119
120    void RadarViewable::updateMapPosition()
121    {
122        if( this->MapNode_ )
123        {
124            this->MapNode_->setPosition( this->getRVWorldPosition() );
125            this->MapNode_->translate( this->getRVOrientedVelocity(), static_cast<Ogre::Node::TransformSpace>(3) );
126            this->MapNode_->setOrientation( this->getWorldEntity()->getOrientation() );
127//Vector3 v = this->getRVWorldPosition();
128            //this->line_->setPoint(1, Vector3(0,v.y,0) );
129            this->line_->setPoint(1, Vector3( 0, static_cast<float>(static_cast<int>( -Map::getSingletonPtr()->movablePlane_->getDistance( this->getRVWorldPosition() ) ) ) ,0 ));
130            this->line_->update();
131            if( Map::getSingletonPtr()->playerShipNode_ )
132                this->LineNode_->setDirection( Map::getSingletonPtr()->playerShipNode_->getLocalAxes().GetColumn(1) ,Ogre::Node::TS_WORLD,Vector3::UNIT_Y);
133        }
134    }
135
136    void RadarViewable::setRadarObjectDescription(const std::string& str)
137    {
138        Radar* radar = this->getWorldEntity()->getScene()->getRadar();
139        if (radar)
140            this->radarObjectShape_ = radar->addObjectDescription(str);
141        else
142        {
143            CCOUT(2) << "Attempting to access the radar, but the radar is non existent." << std::endl;
144        }
145        this->radarObjectDescription_ = str;
146    }
147
148    const Vector3& RadarViewable::getRVWorldPosition() const
149    {
150        const WorldEntity* object = this->getWorldEntity();
151        validate(object);
152        return object->getWorldPosition();
153    }
154
155    Vector3 RadarViewable::getRVOrientedVelocity() const
156    {
157        const WorldEntity* object = this->getWorldEntity();
158        validate(object);
159        return object->getWorldOrientation() * object->getVelocity();
160    }
161
162    void RadarViewable::validate(const WorldEntity* object) const
163    {
164        if (!object)
165        {
166            COUT(1) << "Assertation: Every RadarViewable has to be assigned a WorldEntity pointer!" << std::endl;
167            assert(0);
168        }
169    }
170}
Note: See TracBrowser for help on using the repository browser.