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