xoreos  0.0.5
room.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/error.h"
26 #include "src/common/ustring.h"
27 #include "src/common/maths.h"
28 
30 
32 
34 
35 namespace Engines {
36 
37 namespace KotOR2 {
38 
39 Room::Room(const Common::UString &resRef, float x, float y, float z)
40  : _resRef(resRef.toLower()) {
41  load(resRef, x, y, z);
42 }
43 
45 }
46 
47 void Room::load(const Common::UString &resRef, float x, float y, float z) {
48  if (resRef == "****")
49  return;
50 
51  _model.reset(loadModelObject(resRef));
52  if (!_model)
53  throw Common::Exception("Can't load room model \"%s\"", resRef.c_str());
54 
55  _model->setPosition(x, y, z);
56 
57  _walkmesh.load(resRef);
58 }
59 
61  return _resRef;
62 }
63 
64 float Room::evaluateElevation(float x, float y, bool highlight) {
65  uint32 faceIndex;
66  float z = _walkmesh.getElevationAt(x, y, faceIndex);
67 
68  if (highlight)
69  _walkmesh.highlightFace(z == FLT_MIN ? -1 : faceIndex);
70 
71  return z;
72 }
73 
76 }
77 
78 void Room::setWalkmeshInvisible(bool invisible) {
79  _walkmesh.setInvisible(invisible);
80 }
81 
82 void Room::show() {
83  if (_model)
84  _model->show();
85  _walkmesh.show();
86 }
87 
88 void Room::hide() {
89  if (_model)
90  _model->hide();
91  _walkmesh.hide();
92 }
93 
94 bool Room::isVisible() const {
95  return _model && _model->isVisible();
96 }
97 
98 } // End of namespace KotOR2
99 
100 } // End of namespace Engines
virtual void show()
Show the object.
Definition: renderable.cpp:114
A room within a Star Wars: Knights of the Old Republic II - The Sith Lords area.
void disableWalkmeshHighlight()
Definition: room.cpp:74
virtual void hide()
Hide the object.
Definition: renderable.cpp:123
A class holding an UTF-8 string.
Definition: ustring.h:48
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Mathematical helpers.
Engines::KotOR::Walkmesh _walkmesh
Definition: room.h:61
void setWalkmeshInvisible(bool invisible)
Definition: room.cpp:78
void setInvisible(bool invisible)
Definition: walkmesh.cpp:110
Basic exceptions to throw.
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
float evaluateElevation(float x, float y, bool highlight=false)
Definition: room.cpp:64
A 3D model of an object.
StackException Exception
Definition: error.h:59
void highlightFace(uint32 index)
Highlight face with specified index.
Definition: walkmesh.cpp:106
Unicode string handling.
void load(const Common::UString &resRef, float x, float y, float z)
Definition: room.cpp:47
Common::UString _resRef
Definition: room.h:59
Common::UString getResRef() const
Definition: room.cpp:60
uint32_t uint32
Definition: types.h:204
Common::ScopedPtr< Graphics::Aurora::Model > _model
Definition: room.h:60
#define FLT_MIN
Definition: maths.h:43
bool isVisible() const
Definition: room.cpp:94
Graphics::Aurora::Model * loadModelObject(const Common::UString &resref, const Common::UString &texture)
Definition: model.cpp:47
float getElevationAt(float x, float y, uint32 &faceIndex) const
Return elevation at given coordinates or FLT_MIN if can&#39;t walk there.
Definition: walkmesh.cpp:43
Room(const Common::UString &resRef, float x, float y, float z)
Definition: room.cpp:39
void load(const Common::UString &resRef, ::Aurora::FileType type=::Aurora::kFileTypeWOK, const glm::mat4 &transform=glm::mat4())
Definition: walkmesh.cpp:35
Generic Aurora engines model functions.