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