Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/map/src/orxonox/objects/RadarViewable.cc @ 2942

Last change on this file since 2942 was 2942, checked in by Naaduun, 15 years ago

=added dynamic libs to orxonox/tools. changed humancontroller to use mouseview

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