Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

repositioned hud layout

File size: 3.9 KB
Line 
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
28/*      local coordinate system of space ship at the beginning:
29
30                        y
31                        +   z
32                        |  +
33                        | /
34                        |/
35   x +------O
36*/
37
38#include <OgreOverlayManager.h>
39#include <OgreOverlayElement.h>
40#include <OgrePanelOverlayElement.h>
41#include <OgreStringConverter.h>
42#include "RadarOverlayElement.h"
43#include "GraphicsEngine.h"
44
45namespace orxonox
46{
47    using namespace Ogre;
48
49    RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){
50    }
51
52    RadarOverlayElement::~RadarOverlayElement(){
53    }
54
55    void RadarOverlayElement::initialise(){
56        PanelOverlayElement::initialise();
57    }
58
59    void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, Real dim, Ogre::OverlayContainer* container){
60
61        windowW = GraphicsEngine::getSingleton().getWindowWidth();
62        windowH = GraphicsEngine::getSingleton().getWindowHeight();
63        dim_ = dim*windowH;                         //convert relative data to absolute
64        left_ = left*windowW-dim_/2;                // ...
65        top_ = top*windowH-dim_/2;                  // ...
66        count_ = 0;
67        container_ = container;
68
69        shipPos_ = Vector3(0.0, 0.0, 0.0);
70        targetPos_ = Vector3(1337.0, 0.0, 0.0);
71        initialDir_ = Vector3(1.0, 0.0, 0.0);
72        currentDir_ = initialDir_;
73        initialOrth_ = Vector3(0.0, 0.0, 1.0);
74        currentOrth_ = initialOrth_;
75
76        setMetricsMode(Ogre::GMM_PIXELS);
77        setMaterialName("Orxonox/Radar");
78        setPosition(left_, top_);
79        setDimensions(dim_,dim_);
80
81        om = &Ogre::OverlayManager::getSingleton();
82        point = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel", "point"));
83        point->show();
84        container->addChild(point);
85        point->setMaterialName("Orxonox/RedPoint");
86        point->setDimensions(5,5);
87        point->setMetricsMode(Ogre::GMM_PIXELS);
88
89    }
90
91//    void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
92//        dirX_=dirX;
93//        dirY_=dirY;
94//        dirZ_=dirZ;
95//        ortX_=ortX;
96//        ortY_=ortY;
97//        ortZ_=ortZ;
98//    }
99
100    void RadarOverlayElement::update() {
101        shipPos_ = SpaceShip::instance_s->getPosition();
102        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
103                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
104
105                radius_ = acos((currentDir_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentDir_.length()));
106        phi_ = acos((currentOrth_.dotProduct(targetPos_ - shipPos_))/((targetPos_ - shipPos_).length()*currentOrth_.length()));
107        if((currentDir_.crossProduct(currentOrth_)).dotProduct(targetPos_ - shipPos_) > 0) right_ = true;
108        else right_=false;
109
110        if (right_){
111            point->setPosition(sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
112        }
113        else {
114            point->setPosition(-sin(phi_)*radius_/3.5*dim_/2+dim_/2+left_-2,-cos(phi_)*radius_/3.5*dim_/2+dim_/2+top_-2);
115        }
116    }
117
118}
119
120
121
Note: See TracBrowser for help on using the repository browser.