Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

svn save

File size: 3.2 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#include <OgreOverlayManager.h>
29#include <OgreOverlayElement.h>
30#include <OgrePanelOverlayElement.h>
31
32#include <OgreStringConverter.h>
33#include <math.h>
34#include <string.h>
35
36#include "RadarOverlayElement.h"
37
38
39namespace orxonox
40{
41  using namespace Ogre;
42
43  RadarOverlayElement::RadarOverlayElement(const String& name):Ogre::PanelOverlayElement(name){}
44
45  RadarOverlayElement::~RadarOverlayElement(){}
46
47  void RadarOverlayElement::initialise(){
48    PanelOverlayElement::initialise();
49  }
50 
51  void RadarOverlayElement::initRadarOverlayElement(Real left, Real top, int dim, Ogre::OverlayContainer* container){
52
53
54   
55    dirX_ = 1;
56    dirY_ = 0;
57    dirZ_ = 0;
58   
59    ortX_ = 0;
60    ortY_ = 0;
61    ortZ_ = 1;
62   
63    dX_ = 0;
64    dY_ = 0;
65    dZ_ = -1;
66   
67    alpha_ = acos((dirX_*dX_+dirY_*dY_+dirZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(dirX_,2)+pow(dirY_,2)+pow(dirZ_,2))));
68    beta_ = acos((ortX_*dX_+ortY_*dY_+ortZ_*dZ_)/(sqrt(pow(dX_,2)+pow(dY_,2)+pow(dZ_,2))*sqrt(pow(ortX_,2)+pow(ortY_,2)+pow(ortZ_,2))));
69    vecX_ = dirY_*ortZ_ - dirZ_*ortY_;
70    vecY_ = dirZ_*ortX_ - dirX_*ortZ_;
71    vecZ_ = dirX_*ortY_ - dirY_*ortX_;
72   
73    if((vecX_*dX_+vecY_*dY_+vecZ_*dZ_)>0){right_=true;}
74    else right_=false;
75   
76    setMetricsMode(Ogre::GMM_PIXELS);
77    setPosition(left,top);
78    setDimensions(dim,dim);
79    setMaterialName("Orxonox/Radar");
80   
81    Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton();
82
83    PanelOverlayElement* point = static_cast<PanelOverlayElement*>(overlayManager.createOverlayElement("Panel", "point"));
84    point->show();
85   
86    container->addChild(point);
87   
88    if (right_){
89      point->setPosition(sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2);
90      point->setMaterialName("Orxonox/RedPoint");
91      point->setDimensions(5,5);
92      point->setMetricsMode(Ogre::GMM_PIXELS);
93    }
94 
95    else {
96      point->setPosition(-sin(beta_)*alpha_/3.5*dim/2+dim/2+left-2,-cos(beta_)*alpha_/3.5*dim/2+dim/2+top-2);
97      point->setMaterialName("Orxonox/RedPoint");
98      point->setDimensions(5,5);
99      point->setMetricsMode(Ogre::GMM_PIXELS);
100    }
101  }
102   
103  void RadarOverlayElement::setMainShipPosition(int dirX, int dirY, int dirZ, int ortX, int ortY, int ortZ){
104    dirX_=dirX;
105    dirY_=dirY;
106    dirZ_=dirZ;
107    ortX_=ortX;
108    ortY_=ortY;
109    ortZ_=ortZ;
110  }
111 
112 
113 
114}
115
116
117
Note: See TracBrowser for help on using the repository browser.