xoreos  0.0.5
areabackground.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/scopedptr.h"
26 #include "src/common/util.h"
27 #include "src/common/ustring.h"
28 #include "src/common/error.h"
29 #include "src/common/readstream.h"
30 #include "src/common/maths.h"
31 
32 #include "src/aurora/resman.h"
33 
34 #include "src/graphics/camera.h"
35 
37 
40 
43 
44 namespace Engines {
45 
46 namespace Sonic {
47 
48 static const float kVertexX1 = kBottomScreenX;
49 static const float kVertexY1 = kBottomScreenY;
50 static const float kVertexX2 = kVertexX1 + kScreenWidth;
51 static const float kVertexY2 = kVertexY1 + kScreenHeight;
52 
54  Graphics::GUIElement(Graphics::GUIElement::kGUIElementBack) {
56 
57  loadTexture(name);
58 
59  setPosition(0.0f, 0.0f);
60 }
61 
63  hide();
64 }
65 
67  return _texture.getTexture().getWidth();
68 }
69 
71  return _texture.getTexture().getHeight();
72 }
73 
75 }
76 
79  return;
80 
81  TextureMan.set(_texture);
82 
83  glBegin(GL_QUADS);
84  glTexCoord2f(_textureX1, _textureY1);
85  glVertex2f(kVertexX1, kVertexY1);
86  glTexCoord2f(_textureX2, _textureY1);
87  glVertex2f(kVertexX2, kVertexY1);
88  glTexCoord2f(_textureX2, _textureY2);
89  glVertex2f(kVertexX2, kVertexY2);
90  glTexCoord2f(_textureX1, _textureY2);
91  glVertex2f(kVertexX1, kVertexY2);
92  glEnd();
93 }
94 
96  try {
98  if (!cbgt)
99  throw Common::Exception("No such CBGT");
100 
102  if (!pal)
103  throw Common::Exception("No such PAL");
104 
106  if (!twoda)
107  throw Common::Exception("No such 2DA");
108 
109  Common::ScopedPtr<Graphics::CBGT> image(new Graphics::CBGT(*cbgt, *pal, *twoda));
110 
112  image.release();
113 
114  } catch (Common::Exception &e) {
115  e.add("Failed loading area background \"%s\"", name.c_str());
116  throw;
117  }
118 }
119 
120 void AreaBackground::setPosition(float x, float y) {
121  const float textureWidth = _texture.getTexture().getWidth();
122  const float textureHeight = _texture.getTexture().getHeight();
123 
124  y = floor(y * sin(Common::deg2rad(kCameraAngle)));
125 
126  x = CLIP<float>(x - kScreenWidth / 2.0f, 0.0f, textureWidth - kScreenWidth);
127  y = CLIP<float>(y - kScreenHeight / 2.0f, 0.0f, textureHeight - kScreenHeight);
128 
129  _textureX1 = x / textureWidth;
130  _textureY1 = (y + kScreenHeight) / textureHeight;
131  _textureX2 = (x + kScreenWidth ) / textureWidth;
132  _textureY2 = y / textureHeight;
133 }
134 
136  const float *pos = CameraMan.getPosition();
137 
138  setPosition(pos[0], pos[2]);
139 }
140 
141 } // End of namespace Sonic
142 
143 } // End of namespace Engines
static const float kScreenHeight
Definition: types.h:35
#define ResMan
Shortcut for accessing the sound manager.
Definition: resman.h:557
Table data, 2-dimensional text array.
Definition: types.h:86
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
Only render transparent parts.
Definition: types.h:99
virtual void hide()
Hide the object.
Definition: renderable.cpp:123
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
double _distance
The distance of the object from the viewer.
Definition: renderable.h:101
static const float kVertexX2
PointerType release()
Returns the plain pointer value and releases ScopedPtr.
Definition: scopedptr.h:103
void setPosition(float x, float y)
static Texture * create(const Common::UString &name, bool deswizzle=false)
Create a texture from this image resource.
Definition: texture.cpp:323
The Aurora texture manager.
static const float kVertexX1
Mathematical helpers.
Camera management.
uint32 getHeight() const
Definition: texture.cpp:80
static const float kVertexY1
static const float kCameraAngle
Definition: types.h:44
Exception that provides a stack of explanations.
Definition: error.h:36
Basic Sonic Chronicles: The Dark Brotherhood types and defines.
A simple scoped smart pointer template.
static const float kBottomScreenX
Definition: types.h:40
Basic exceptions to throw.
AreaBackground(const Common::UString &name)
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
RenderPass
Definition: types.h:97
Utility templates and functions.
static const float kScreenWidth
Definition: types.h:34
The scrolling background image panel in Sonic Chronicles: The Dark Brotherhood.
static const float kBottomScreenY
Definition: types.h:41
StackException Exception
Definition: error.h:59
static const float kVertexY2
Basic reading stream interfaces.
uint32 getWidth() const
Definition: texture.cpp:76
Unicode string handling.
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
A texture as used in the Aurora engines.
Graphics::Aurora::TextureHandle _texture
uint32_t uint32
Definition: types.h:204
void loadTexture(const Common::UString &name)
void calculateDistance()
Calculate the object&#39;s distance.
#define CameraMan
Shortcut for accessing the camera manager.
Definition: camera.h:83
void render(Graphics::RenderPass pass)
Render the object.
#define pass
Definition: fft.cpp:257
Loader for CBGT, BioWare&#39;s Compressed BackGround Tiles, an image format found in Sonic, used as area background images.
Definition: cbgt.h:57
Compressed BackGround Tiles, a BioWare image format found in Sonic.
static float deg2rad(float deg)
Definition: maths.h:97
Palette.
Definition: types.h:274
#define FLT_MAX
Definition: maths.h:47
The global resource manager for Aurora resources.