Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

edited radar to support multiple radar objects, wip though

File size: 4.6 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::init(Real leftRel, Real topRel, Real dimRel, Ogre::OverlayContainer* container){
56                om = &Ogre::OverlayManager::getSingleton();       
57        dimRel_ = dimRel;
58        leftRel_ = leftRel;
59        topRel_ = topRel;
60        container_ = container;
61
62        shipPos_ = Vector3(0.0, 0.0, 0.0);
63        initialDir_ = Vector3(1.0, 0.0, 0.0);
64        currentDir_ = initialDir_;
65        initialOrth_ = Vector3(0.0, 0.0, 1.0);
66        currentOrth_ = initialOrth_;
67
68        setMetricsMode(Ogre::GMM_PIXELS);
69        setMaterialName("Orxonox/Radar");
70        resize();
71       
72        container_->addChild(this);
73    }
74
75    void RadarOverlayElement::resize() {
76        // if window is resized, we must adapt these...
77        windowW_ = GraphicsEngine::getSingleton().getWindowWidth();
78        windowH_ = GraphicsEngine::getSingleton().getWindowHeight();
79        dim_ = dimRel_*windowH_;
80        left_ = leftRel_*windowW_-dim_/2;
81        top_ = topRel_*windowH_-dim_/2;
82        setPosition(left_, top_);
83        setDimensions(dim_,dim_);
84    }
85
86    void RadarOverlayElement::update() {
87        shipPos_ = SpaceShip::instance_s->getPosition();
88        currentDir_ = SpaceShip::instance_s->getOrientation()*initialDir_;              // according to beni....
89                currentOrth_ = SpaceShip::instance_s->getOrientation()*initialOrth_;
90
91                if(tomato_ == NULL) return;             
92               
93                tomato_->radius_ = acos((currentDir_.dotProduct(tomato_->pos_ - shipPos_))/
94                        ((tomato_->pos_ - shipPos_).length()*currentDir_.length()));
95        tomato_->phi_ = acos((currentOrth_.dotProduct(tomato_->pos_ - shipPos_))/
96                ((tomato_->pos_ - shipPos_).length()*currentOrth_.length()));
97        if((currentDir_.crossProduct(currentOrth_)).dotProduct(tomato_->pos_ - shipPos_) > 0) 
98                tomato_->right_ = true;
99        else tomato_->right_=false;
100
101        if (tomato_->right_){
102            tomato_->panel_->setPosition(sin(tomato_->phi_)*tomato_->radius_/
103                3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
104        }
105        else {
106            tomato_->panel_->setPosition(-sin(tomato_->phi_)*tomato_->radius_/
107                3.5*dim_/2+dim_/2+left_-2,-cos(tomato_->phi_)*tomato_->radius_/3.5*dim_/2+dim_/2+top_-2);
108        }
109    }
110   
111    void RadarOverlayElement::addObject(Vector3 pos){
112                tomato_ = new RadarObject(container_);
113                tomato_->pos_ = pos;
114        }
115       
116        //// RadarObject ////
117       
118        int RadarObject::count = 0;
119       
120        RadarObject::RadarObject(Ogre::OverlayContainer* container){
121                container_ = container;
122                pos_ = Vector3(0.0, 0.0, 0.0);
123                init();
124        }
125       
126        RadarObject::RadarObject(Ogre::OverlayContainer* container, Vector3 pos){
127                container_ = container;
128                pos_ = pos;
129                init();
130        }
131       
132        RadarObject::~RadarObject(){}
133       
134        void RadarObject::init(){
135                om = &Ogre::OverlayManager::getSingleton();
136                panel_ = static_cast<PanelOverlayElement*>(om->createOverlayElement("Panel",
137                        "Object"+Ogre::StringConverter::toString(count++)));
138                panel_->setMaterialName("Orxonox/RedDot");
139                panel_->setDimensions(5,5);
140        panel_->setMetricsMode(Ogre::GMM_PIXELS);
141        panel_->show();
142        container_->addChild(panel_);
143        }
144}
145
146/* my local clipboard...
147COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
148COUT(3) << tomato_->radius_ << "  " << tomato_->phi_ << std::endl;
149COUT(3) << "WWWWWWWWWWWWWWWWWWWWWWWWWWWW\n";
150*/
Note: See TracBrowser for help on using the repository browser.