xoreos  0.0.5
compass.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos 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 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 
27 #include "src/graphics/graphics.h"
28 #include "src/graphics/camera.h"
29 
32 
34 
36 
37 namespace Engines {
38 
39 namespace NWN {
40 
41 // TODO: The compass "needle" is hidden by directions disk.
42 // This seems to be a Z-order problem, should be fixed
43 // alongside the transparency problem once I've revamped models...
45  ModelWidget(gui, tag, "ctl_compass") {
46 }
47 
49 }
50 
51 // TODO: The disk rotation should feel more "natural", i.e. it should
52 // be more sluggish.
53 void CompassWidget::setRotation(float x, float UNUSED(y), float z) {
54  _model->setOrientation(1.0f, 0.0f, 0.0f, -x);
55  Graphics::Aurora::ModelNode *pointer = _model->getNode("cmp_pointer");
56  if (pointer)
57  pointer->setRotation(0.0f, 0.0f, z);
58 }
59 
60 
61 Compass::Compass(float position) {
62  // Panel
63 
64  WidgetPanel *panel = new WidgetPanel(*this, "CompassPanel", "pnl_compass");
65 
66  float panelWidth = panel->getWidth ();
67  float panelHeight = panel->getHeight();
68 
69  panel->setPosition(- panelWidth, position, 0.0f);
70 
71  addWidget(panel);
72 
73 
74  // Compass
75 
76  _compass = new CompassWidget(*this, "Compass");
77 
78  _compass->setPosition(- (panelWidth / 2.0f), position + (panelHeight / 2.0f), -100.0f);
79 
81 
82 
83  notifyResized(0, 0, WindowMan.getWindowWidth(), WindowMan.getWindowHeight());
84 }
85 
87 }
88 
90 }
91 
92 void Compass::notifyResized(int UNUSED(oldWidth), int UNUSED(oldHeight),
93  int newWidth, int newHeight) {
94 
95  setPosition(newWidth / 2.0f, - (newHeight / 2.0f), -10.0f);
96 }
97 
99  const float *orientation = CameraMan.getOrientation();
100 
101  _compass->setRotation(orientation[0] - 90.0f, orientation[1], orientation[2]);
102 }
103 
104 } // End of namespace NWN
105 
106 } // End of namespace Engines
void notifyResized(int oldWidth, int oldHeight, int newWidth, int newHeight)
Definition: compass.cpp:92
A NWN panel widget.
Definition: panel.h:41
The global graphics manager.
void notifyCameraMoved()
Definition: compass.cpp:98
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPosition(float x, float y, float z)
Set the GUI&#39;s position.
Definition: gui.cpp:394
float getHeight() const
Get the widget&#39;s height.
Definition: modelwidget.cpp:82
Camera management.
void setRotation(float x, float y, float z)
Definition: compass.cpp:53
A GUI.
Definition: gui.h:43
void setOrientation(float x, float y, float z, float angle)
Set the current orientation of the model.
Definition: model.cpp:234
#define UNUSED(x)
Definition: system.h:170
Utility templates and functions.
void setRotation(float x, float y, float z)
Set the rotation of the node.
Definition: modelnode.cpp:230
CompassWidget(::Engines::GUI &gui, const Common::UString &tag)
Definition: compass.cpp:44
A node within a 3D model.
A 3D model of an object.
CompassWidget * _compass
Definition: compass.h:57
The NWN ingame compass.
Graphics::Aurora::Model * _model
Definition: modelwidget.h:64
Compass(float position)
Definition: compass.cpp:61
#define WindowMan
Shortcut for accessing the window manager.
Definition: windowman.h:137
A widget in a GUI.
Definition: widget.h:40
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
A NWN model widget.
Definition: modelwidget.h:45
The NWN compass widget.
Definition: compass.h:39
float getWidth() const
Get the widget&#39;s width.
Definition: modelwidget.cpp:78
#define CameraMan
Shortcut for accessing the camera manager.
Definition: camera.h:83
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
ModelNode * getNode(const Common::UString &node)
Get the specified node, from the current state.
Definition: model.cpp:379
A NWN panel widget.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: compass.cpp:89