Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hud3/src/orxonox/hud/RadarOverlayElement.cc @ 1331

Last change on this file since 1331 was 1329, checked in by FelixSchulthess, 17 years ago

progress bars now resize automatically and have a new look

File size: 3.8 KB
RevLine 
[1283]1/*
2*   ORXONOX - the hottest 3D action shooter ever to exist
3*
4*
5*   License notice:
6*
7*   This program is free software; you can redistribute it and/or
8*   modify it under the terms of the GNU General Public License
9*   as published by the Free Software Foundation; either version 2
10*   of the License, or (at your option) any later version.
11*
12*   This program is distributed in the hope that it will be useful,
13*   but WITHOUT ANY WARRANTY; without even the implied warranty of
14*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*   GNU General Public License for more details.
16*
17*   You should have received a copy of the GNU General Public License
18*   along with this program; if not, write to the Free Software
19*   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20*
21*   Author:
22*      Yuning Chai
23*   Co-authors:
24*      ...
25*
26*/
27
[1302]28/*      local coordinate system of space ship at the beginning:
[1292]29
30                        y
31                        +   z
32                        |  +
33                        | /
34                        |/
[1302]35   x +------O
[1292]36*/
37
[1283]38#include <OgreOverlayManager.h>
39#include <OgreOverlayElement.h>
40#include <OgrePanelOverlayElement.h>
41#include <OgreStringConverter.h>
42#include "RadarOverlayElement.h"
[1310]43#include "GraphicsEngine.h"
[1283]44
45namespace orxonox
46{
[1302]47    using namespace Ogre;
[1283]48
[1302]49    RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
50    }
[1283]51
[1302]52    RadarOverlayElement::~RadarOverlayElement(){
53    }
[1283]54
[1302]55    void RadarOverlayElement::initialise(){
56        PanelOverlayElement::initialise();
57    }
[1286]58
[1328]59    void RadarOverlayElement::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
[1310]60        count_ = 0;
[1314]61        dimRel_ = dimRel;
62        leftRel_ = leftRel;
63        topRel_ = topRel;
[1302]64        container_ = container;
[1283]65
[1302]66        shipPos_ = Vector3(0.0, 0.0, 0.0);
[1311]67        targetPos_ = Vector3(1337.0, 0.0, 0.0);
[1308]68        initialDir_ = Vector3(1.0, 0.0, 0.0);
[1302]69        currentDir_ = initialDir_;
[1308]70        initialOrth_ = Vector3(0.0, 0.0, 1.0);
[1302]71        currentOrth_ = initialOrth_;
[1310]72
[1302]73        setMetricsMode(Ogre::GMM_PIXELS);
[1310]74        setMaterialName("Orxonox/Radar");
[1314]75        resize();
[1302]76
77        om = &Ogre::OverlayManager::getSingleton();
78        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
79        point->show();
[1329]80        container->addChild(this);
[1302]81        container->addChild(point);
[1328]82        point->setMaterialName("Orxonox/RedDot");
[1308]83        point->setDimensions(5,5);
84        point->setMetricsMode(Ogre::GMM_PIXELS);
[1302]85
[1283]86    }
[1302]87
[1314]88    void RadarOverlayElement::resize() {
89        // if window is resized, we must adapt these...
90        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
91        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
92        dim_ = dimRel_*windowH_;
93        left_ = leftRel_*windowW_-dim_/2;
94        top_ = topRel_*windowH_-dim_/2;
95        setPosition(left_, top_);
96        setDimensions(dim_,dim_);
97    }
98
[1302]99    void RadarOverlayElement::update() {
100        shipPos_ = SpaceShip::instance_s->getPosition();
[1308]101        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
102                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
[1310]103
[1308]104                radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
105        phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
[1310]106        if((currentDir_.crossProduct(currentOrth_)).dotProduct(targetPos_ - shipPos_) > 0) right_ = true;
[1308]107        else right_=false;
[1310]108
[1308]109        if (right_){
[1310]110            point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
[1308]111        }
112        else {
113            point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
114        }
[1283]115    }
[1302]116
[1283]117}
118
119
120
Note: See TracBrowser for help on using the repository browser.