xoreos  0.0.5
minimap.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 "glm/mat4x4.hpp"
26 #include "glm/gtc/type_ptr.hpp"
27 #include "glm/gtc/matrix_transform.hpp"
28 
29 #include "src/common/util.h"
30 
32 
33 namespace Engines {
34 
35 namespace KotOR {
36 
37 Minimap::Minimap(const Common::UString &map, int northAxis,
38  float mapPt1X, float mapPt1Y, float mapPt2X, float mapPt2Y,
39  float worldPt1X, float worldPt1Y, float worldPt2X, float worldPt2Y) :
40  _mapQuad("lbl_map" + map, 0, 0, 512, 256), _northAxis(northAxis),
41  _mapPt1X(mapPt1X), _mapPt1Y(mapPt1Y), _mapPt2X(mapPt2X), _mapPt2Y(mapPt2Y),
42  _worldPt1X(worldPt1X), _worldPt1Y(worldPt1Y), _worldPt2X(worldPt2X), _worldPt2Y(worldPt2Y) {
43 
44  add(&_mapQuad);
45 
46  glm::mat4 projection(glm::ortho(0.0f, 120.0f, 0.0f, 120.0f, -1.0f, 1.0f));
47 
48  setProjectionMatrix(projection);
49 }
50 
51 void Minimap::setPosition(float x, float y) {
52  glm::mat4 transformation;
53 
54  float scaleX, scaleY, relX, relY;
55  switch (_northAxis) {
56  case 0:
57  scaleY = (_mapPt1Y - _mapPt2Y) / (_worldPt1Y - _worldPt2Y);
58  scaleX = (_mapPt1X - _mapPt2X) / (_worldPt1X - _worldPt2X);
59  relX = (x - _worldPt1X) * scaleX + _mapPt1X;
60  relY = (y - _worldPt1Y) * scaleY + _mapPt1Y;
61  transformation = glm::translate(transformation, glm::vec3(-(relX * 435) + 60, -(256 - relY * 256) + 60, 0));
62  break;
63 
64  case 3:
65  scaleX = (_mapPt1Y - _mapPt2Y) / (_worldPt1X - _worldPt2X);
66  scaleY = (_mapPt1X - _mapPt2X) / (_worldPt1Y - _worldPt2Y);
67  relX = (y - _worldPt1Y) * scaleY + _mapPt1X;
68  relY = (x - _worldPt1X) * scaleX + _mapPt1Y;
69  transformation = glm::translate(transformation, glm::vec3(-(relX * 435) + 60, -(256 - relY * 256) + 60, 0));
70  break;
71 
72  default:
73  warning("Unknown north axis");
74  }
75 
76  setGlobalTransformationMatrix(transformation);
77 }
78 
80  return _northAxis;
81 }
82 
83 } // End of namespace KotOR
84 
85 } // End of namespace Engines
A class holding an UTF-8 string.
Definition: ustring.h:48
void add(Renderable *renderable)
Add a renderable to the sub scene.
void setProjectionMatrix(const glm::mat4 &projection)
Utility templates and functions.
The ingame minimap.
void warning(const char *s,...)
Definition: util.cpp:33
void setGlobalTransformationMatrix(const glm::mat4 &transformation)
Minimap(const Common::UString &map, int northAxis, float mapPt1X, float mapPt1Y, float mapPt2X, float mapPt2Y, float worldPt1X, float worldPt1Y, float worldPt2X, float worldPt2Y)
Definition: minimap.cpp:37
Graphics::Aurora::GUIQuad _mapQuad
Definition: minimap.h:45
void setPosition(float x, float y)
Definition: minimap.cpp:51