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 | |
---|
29 | #include "OrxonoxStableHeaders.h" |
---|
30 | #include <OgreOverlay.h> |
---|
31 | #include <OgreOverlayContainer.h> |
---|
32 | #include <OgreOverlayManager.h>ma |
---|
33 | #include <OgreSceneNode.h> |
---|
34 | #include <OgreEntity.h> |
---|
35 | #include "core/Debug.h" |
---|
36 | |
---|
37 | #include "HUD.h" |
---|
38 | #include "BarOverlayElement.h" |
---|
39 | #include "RadarOverlayElement.h" |
---|
40 | #include "OverlayElementFactories.h" |
---|
41 | // ugly hack |
---|
42 | #include "Orxonox.h" |
---|
43 | |
---|
44 | |
---|
45 | namespace orxonox |
---|
46 | { |
---|
47 | using namespace Ogre; |
---|
48 | |
---|
49 | HUD::HUD(int zoom){ |
---|
50 | |
---|
51 | Ogre::OverlayManager& overlayManager = Ogre::OverlayManager::getSingleton(); |
---|
52 | |
---|
53 | BarOverlayElementFactory *barOverlayElementFactory = new BarOverlayElementFactory(); |
---|
54 | overlayManager.addOverlayElementFactory(barOverlayElementFactory); |
---|
55 | |
---|
56 | SmartBarOverlayElementFactory *smartBarOverlayElementFactory = new SmartBarOverlayElementFactory(); |
---|
57 | overlayManager.addOverlayElementFactory(smartBarOverlayElementFactory); |
---|
58 | |
---|
59 | RadarOverlayElementFactory *radarOverlayElementFactory = new RadarOverlayElementFactory(); |
---|
60 | overlayManager.addOverlayElementFactory(radarOverlayElementFactory); |
---|
61 | |
---|
62 | Ogre::Overlay* orxonoxOverlay = overlayManager.create("Orxonox/HUD"); |
---|
63 | |
---|
64 | Ogre::OverlayContainer* energyCounterPanel = static_cast<Ogre::OverlayContainer*>(overlayManager.createOverlayElement("Panel", "Orxonox/HUD/energyCounterPanel")); |
---|
65 | |
---|
66 | energyCounter = static_cast<SmartBarOverlayElement*>(overlayManager.createOverlayElement("SmartBar", "energyCounter")); |
---|
67 | energyCounter->show(); |
---|
68 | |
---|
69 | |
---|
70 | radar = static_cast<RadarOverlayElement*>(overlayManager.createOverlayElement("Radar", "radar")); |
---|
71 | radar->show(); |
---|
72 | |
---|
73 | |
---|
74 | /* TextAreaOverlayElement* test = static_cast<TextAreaOverlayElement*>(overlayManager.createOverlayElement("TextArea", "test")); |
---|
75 | |
---|
76 | int dirX, dirY, dirZ; //flying direction |
---|
77 | int ortX, ortY, ortZ; //orthogonal direction |
---|
78 | int dX, dY, dZ; //distance between main ship and the object |
---|
79 | int vecX, vecY, vecZ; //vector product dir X ort |
---|
80 | double alpha; //defines the radius in the radar |
---|
81 | double beta; //defines the angle in the radar |
---|
82 | bool right; //checks whether the object is on the right side (since cos is not bijective) |
---|
83 | |
---|
84 | dirX = 1; |
---|
85 | dirY = 0; |
---|
86 | dirZ = 0; |
---|
87 | |
---|
88 | ortX = 0; |
---|
89 | ortY = 0; |
---|
90 | ortZ = 1; |
---|
91 | |
---|
92 | dX = -2; |
---|
93 | dY = 2; |
---|
94 | dZ = 0; |
---|
95 | |
---|
96 | 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)))); |
---|
97 | 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)))); |
---|
98 | vecX = dirY*ortZ - dirZ*ortY; |
---|
99 | vecY = dirZ*ortX - dirX*ortZ; |
---|
100 | vecZ = dirX*ortY - dirY*ortX; |
---|
101 | |
---|
102 | if((vecX*dX+vecY*dY+vecZ*dZ)>0){right=true;} |
---|
103 | else right=false; |
---|
104 | |
---|
105 | test->setCaption("hell"); |
---|
106 | test->setPosition(10,10); |
---|
107 | test->setDimensions(20,20); |
---|
108 | test->show(); |
---|
109 | test->setMetricsMode(Ogre::GMM_PIXELS); |
---|
110 | energyCounterPanel->addChild(test); |
---|
111 | |
---|
112 | COUT(0)<<alpha<<" "<<beta<<" "<<right<<std::endl; |
---|
113 | */ |
---|
114 | |
---|
115 | energyCounterPanel->addChild(energyCounter); |
---|
116 | energyCounterPanel->addChild(radar); |
---|
117 | energyCounterPanel->show(); |
---|
118 | |
---|
119 | orxonoxOverlay->add2D(energyCounterPanel); |
---|
120 | orxonoxOverlay->show(); |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | // important: don't use SceneManager to create the node! but register the creator scene manager. |
---|
125 | /* ogreNode_ = new Ogre::SceneNode(Orxonox::getSingleton()->getSceneManager(), "hudNoedely"); |
---|
126 | |
---|
127 | ogreNode_->setPosition(80,-60,-200); |
---|
128 | ogreNode_->setScale(0.4,0.4,0.4); |
---|
129 | // ugly hack, but I haven't figured out yet how we could change this, since we really need the |
---|
130 | // scene manager.. |
---|
131 | ogreNode_->attachObject(Orxonox::getSingleton()->getSceneManager()->createEntity("head", "ogrehead.mesh")); |
---|
132 | // orxonoxOverlay->add3D(ogreNode_); |
---|
133 | */ |
---|
134 | |
---|
135 | energyCounterPanel->setLeft(-50); |
---|
136 | energyCounterPanel->setTop(10); |
---|
137 | energyCounterPanel->setWidth(100); |
---|
138 | energyCounterPanel->setHeight(20); |
---|
139 | energyCounterPanel->setHorizontalAlignment(Ogre::GHA_CENTER); |
---|
140 | energyCounterPanel->setMetricsMode(Ogre::GMM_PIXELS); |
---|
141 | |
---|
142 | energyCounter->initSmartBarOverlayElement(-100,0,200,20,BarOverlayElement::LEFT); |
---|
143 | energyCounter->reset(80); |
---|
144 | |
---|
145 | radar->initRadarOverlayElement(10,10,200,energyCounterPanel); |
---|
146 | |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | /* void HUD::tick(float dt) |
---|
151 | { |
---|
152 | if (this->ogreNode_) |
---|
153 | { |
---|
154 | this->ogreNode_->roll(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
155 | this->ogreNode_->yaw(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
156 | this->ogreNode_->pitch(Ogre::Degree(dt*200),Ogre::Node::TS_LOCAL); |
---|
157 | } |
---|
158 | } |
---|
159 | */ |
---|
160 | HUD::~HUD(void){} |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|