Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1314 was 1314, checked in by FelixSchulthess, 16 years ago

added speedometer.

File size: 4.0 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
[1314]59    void RadarOverlayElement::initRadarOverlayElement(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();
80        container->addChild(point);
[1308]81        point->setMaterialName("Orxonox/RedPoint");
82        point->setDimensions(5,5);
83        point->setMetricsMode(Ogre::GMM_PIXELS);
[1302]84
[1283]85    }
[1302]86
[1314]87    void RadarOverlayElement::resize() {
88        // if window is resized, we must adapt these...
89        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
90        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
91        dim_ = dimRel_*windowH_;
92        left_ = leftRel_*windowW_-dim_/2;
93        top_ = topRel_*windowH_-dim_/2;
94        setPosition(left_, top_);
95        setDimensions(dim_,dim_);
96    }
97
[1302]98//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
99//        dirX_=dirX;
100//        dirY_=dirY;
101//        dirZ_=dirZ;
102//        ortX_=ortX;
103//        ortY_=ortY;
104//        ortZ_=ortZ;
105//    }
106
107    void RadarOverlayElement::update() {
[1314]108        resize();
[1302]109        shipPos_ = SpaceShip::instance_s->getPosition();
[1308]110        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
111                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
[1310]112
[1308]113                radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
114        phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
[1310]115        if((currentDir_.crossProduct(currentOrth_)).dotProduct(targetPos_ - shipPos_) > 0) right_ = true;
[1308]116        else right_=false;
[1310]117
[1308]118        if (right_){
[1310]119            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]120        }
121        else {
122            point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
123        }
[1283]124    }
[1302]125
[1283]126}
127
128
129
Note: See TracBrowser for help on using the repository browser.