Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/netp4/src/orxonox/objects/RadarViewable.cc @ 3126

Last change on this file since 3126 was 3110, checked in by rgrieder, 15 years ago

Removed old msvc specific support for precompiled header files.

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