Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/Radar.cc @ 6344

Last change on this file since 6344 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.8 KB
RevLine 
[1818]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 *      Felix Schulthess
26 *
27 */
28
29/**
[3196]30@file
31@brief
[1818]32*/
33
34#include "Radar.h"
[3196]35
[1818]36#include <cassert>
[3196]37
38//#include "util/Math.h"
[1818]39#include "core/ConsoleCommand.h"
[3196]40#include "core/ObjectList.h"
41#include "interfaces/RadarListener.h"
[1818]42
43namespace orxonox
44{
45
46    Radar::Radar()
47        : focus_(0)
48        , objectTypeCounter_(0)
49    {
50        // TODO: make this mapping configurable. Maybe there's a possibility with self configured
51        //       configValues..
52        this->objectTypes_["Asteroid"] = RadarViewable::Dot;
53        this->objectTypes_["SpaceShip"] = RadarViewable::Square;
54        this->objectTypes_["AsdfQwerty"] = RadarViewable::Triangle;
55
56        /*WorldEntity* object;
57        object = new WorldEntity();
58        object->setPosition(2000.0, 0.0, 0.0);
59        addRadarObject(object, ColourValue(0.5, 0, 0, 1));
60        object = new WorldEntity();
61        object->setPosition(0.0, 2000.0, 0.0);
62        addRadarObject(object, ColourValue(0.5, 0, 0, 1));
63        object = new WorldEntity();
64        object->setPosition(0.0, 0.0, 2000.0);
65        addRadarObject(object, ColourValue(0.5, 0, 0, 1));
66        object = new WorldEntity();
67        object->setPosition(10000.0,16000.0,0.0);
68        addRadarObject(object);*/
69
70    }
71
72    Radar::~Radar()
73    {
74    }
75
76    const RadarViewable* Radar::getFocus()
77    {
[5929]78        if (this->itFocus_)
79            return *(this->itFocus_);
80        else
81            return 0;
[1818]82    }
83
84    RadarViewable::Shape Radar::addObjectDescription(const std::string name)
85    {
86        std::map<std::string, RadarViewable::Shape>::iterator it = this->objectTypes_.find(name);
87        if (it == this->objectTypes_.end())
88            return this->objectTypes_[name] = RadarViewable::Square; // default, configure!!
89        else
90            return this->objectTypes_[name];
91    }
92
93
94    void Radar::tick(float dt)
95    {
[2662]96        SUPER(Radar, tick, dt);
97
[5929]98        if (this->itFocus_ && (this->focus_ != *(this->itFocus_)))
[1818]99        {
100            // focus object was deleted, release focus
101            this->focus_ = 0;
102            this->itFocus_ = 0;
103        }
104
105        for (ObjectList<RadarListener>::iterator itListener = ObjectList<RadarListener>::begin(); itListener; ++itListener)
106        {
107            (*itListener)->radarTick(dt);
108
109            for (ObjectList<RadarViewable>::iterator itElement = ObjectList<RadarViewable>::begin(); itElement; ++itElement)
110            {
[3064]111                if ((*itElement)->getRadarVisibility())
112                    if ((*itListener)->getRadarSensitivity() > (*itElement)->getRadarObjectCamouflage())
113                        (*itListener)->displayObject(*itElement, *itElement == this->focus_);
[1818]114            }
115        }
116    }
117
118    void Radar::cycleFocus()
119    {
120        if (ObjectList<RadarViewable>::begin() == 0)
121        {
122            // list is empty
123            this->itFocus_ = 0;
124            this->focus_ = 0;
125        }
[2662]126/*
127        else if (this->owner_)
[1818]128        {
[2662]129            Vector3 localPosition = this->owner_->getPosition();
[1818]130            Vector3 targetPosition = localPosition;
131            if (*(this->itFocus_))
[2662]132                targetPosition = this->itFocus_->getRVWorldPosition();
[1818]133
134            // find the closed object further away than targetPosition
135            float currentDistance = localPosition.squaredDistance(targetPosition);
136            float nextDistance = FLT_MAX;
137            float minimumDistance = FLT_MAX;
138            ObjectList<RadarViewable>::iterator itFallback = 0;
139
140            for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it)
141            {
[2896]142                if (*it == static_cast<RadarViewable*>(this)->owner_)
[1818]143                    continue;
[2662]144
145                float targetDistance = localPosition.squaredDistance((*it)->getRVWorldPosition());
[1818]146                if (targetDistance > currentDistance && targetDistance < nextDistance)
147                {
148                    this->itFocus_ = it;
149                    nextDistance = targetDistance;
150                }
151                if (targetDistance < minimumDistance)
152                {
153                    itFallback = it;
154                    minimumDistance = targetDistance;
155                }
156            }
157
158            if (nextDistance == FLT_MAX)
159            {
160                // we already had the furthest object
161                this->itFocus_ = itFallback;
162                this->focus_ = *itFallback;
163            }
164            else
165            {
166                this->focus_ = *(this->itFocus_);
167            }
168        }
[2662]169*/
[1818]170    }
171
172    void Radar::releaseFocus()
173    {
174        this->itFocus_ = 0;
175        this->focus_ = 0;
176    }
177
178    void Radar::listObjects() const
179    {
180        COUT(3) << "List of RadarObjects:\n";
181        // iterate through all Radar Objects
182        unsigned int i = 0;
183        for (ObjectList<RadarViewable>::iterator it = ObjectList<RadarViewable>::begin(); it; ++it, ++i)
184        {
[2662]185            COUT(3) << i++ << ": " << (*it)->getRVWorldPosition() << std::endl;
[1818]186        }
187    }
188}
Note: See TracBrowser for help on using the repository browser.