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