Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/hud/RadarOverlayElement.cc @ 1494

Last change on this file since 1494 was 1494, checked in by rgrieder, 16 years ago
  • set the svn:eol-style property to all files so, that where ever you check out, you'll get the right line endings (had to change every file with mixed endings to windows in order to set the property)
  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[1494]1/* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
[1454]2 *   Author:
3 *      Yuning Chai
4 *   Co-authors:
5 *      Felix Schulthess
6 *
7 */
[1283]8
[1373]9#include "OrxonoxStableHeaders.h"
[1283]10#include "RadarOverlayElement.h"
11
[1410]12#include <string>
[1406]13#include <OgreOverlayManager.h>
14#include <OgreStringConverter.h>
15
16#include "GraphicsEngine.h"
17#include "core/Tickable.h"
18#include "core/ConsoleCommand.h"
19#include "objects/SpaceShip.h"
[1410]20#include "RadarObject.h"
[1406]21#include "HUD.h"
22
[1283]23namespace orxonox
24{
[1302]25    using namespace Ogre;
[1283]26
[1406]27    RadarOverlayElement::RadarOverlayElement(const String& name):PanelOverlayElement(name){
[1302]28    }
[1283]29
[1302]30    RadarOverlayElement::~RadarOverlayElement(){
31    }
[1283]32
[1406]33    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, OverlayContainer* container){
[1339]34        // some initial data
[1410]35        om = &OverlayManager::getSingleton();
[1314]36        dimRel_ = dimRel;
37        leftRel_ = leftRel;
38        topRel_ = topRel;
[1302]39        container_ = container;
[1283]40
[1406]41        setMetricsMode(GMM_PIXELS);
[1310]42        setMaterialName("Orxonox/Radar");
[1314]43        resize();
[1339]44
[1335]45        container_->addChild(this);
[1283]46    }
[1302]47
[1314]48    void RadarOverlayElement::resize() {
49        // if window is resized, we must adapt these...
50        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
51        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
[1342]52        dim_ = (int) (dimRel_*windowH_);
53        left_ = (int) (leftRel_*windowW_-dim_/2);
54        top_ = (int) (topRel_*windowH_-dim_/2);
[1314]55        setPosition(left_, top_);
56        setDimensions(dim_,dim_);
57    }
58
[1302]59    void RadarOverlayElement::update() {
[1384]60        shipPos_ = SpaceShip::getLocalShip()->getPosition();
[1406]61        currentDir_ = SpaceShip::getLocalShip()->getDir();
[1410]62        currentOrth_ = SpaceShip::getLocalShip()->getOrth();
[1339]63        // iterate through all RadarObjects
[1456]64        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
[1410]65        // calc position on radar...
[1456]66            float radius = calcRadius(shipPos_, currentDir_, currentOrth_, (*it));
67            float phi = calcPhi(shipPos_, currentDir_, currentOrth_, (*it));
68            bool right = calcRight(shipPos_, currentDir_, currentOrth_, (*it));
[1346]69
70            // set size to fit distance...
[1456]71            float d = ((*it)->getPosition()-shipPos_).length();
[1463]72            if(d<10000) (*it)->panel_->setDimensions(4,4);
73            else if(d<20000) (*it)->panel_->setDimensions(3,3);
74            else (*it)->panel_->setDimensions(2,2);
[1346]75
[1406]76            if (right){
[1456]77                (*it)->panel_->setPosition(sin(phi)*radius/
[1406]78                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
[1339]79            }
80            else {
[1456]81                (*it)->panel_->setPosition(-sin(phi)*radius/
[1406]82                    3.5*dim_/2+dim_/2+left_-2,-cos(phi)*radius/3.5*dim_/2+dim_/2+top_-2);
[1339]83            }
[1410]84        }
[1339]85    }
[1310]86
[1410]87    void RadarOverlayElement::listObjects(){
88        int i = 0;
89        COUT(3) << "List of RadarObjects:\n";
90        // iterate through all Radar Objects
[1456]91        for(std::set<RadarObject*>::iterator it=HUD::getSingleton().roSet.begin(); it!=HUD::getSingleton().roSet.end(); it++){
92            COUT(3) << i++ << ": " << (*it)->getPosition() << std::endl;
[1410]93        }
94    }
[1339]95
[1410]96    float RadarOverlayElement::calcRadius(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
[1450]97        return(acos((dir.dotProduct(obj->getPosition() - pos))/
98        ((obj->getPosition() - pos).length()*dir.length())));
[1410]99    }
[1356]100
[1410]101    float RadarOverlayElement::calcPhi(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
102        // project difference vector on our plane...
[1450]103        Vector3 proj = Plane(dir, pos).projectVector(obj->getPosition() - pos);
[1410]104        // ...and find out the angle
105        return(acos((orth.dotProduct(proj))/
106              (orth.length()*proj.length())));
107    }
[1339]108
[1410]109    bool RadarOverlayElement::calcRight(Vector3 pos, Vector3 dir, Vector3 orth, RadarObject* obj){
[1450]110        if((dir.crossProduct(orth)).dotProduct(obj->getPosition() - pos) > 0)
[1410]111            return true;
[1339]112        else return false;
[1410]113    }
[1283]114}
Note: See TracBrowser for help on using the repository browser.