From a3315037ffde458ff8356c5e7ef9913c4f7b245c Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 11 Aug 2013 13:44:23 -0500 Subject: [PATCH] ZVISION: Create methods for converting screen coords to image coords --- engines/zvision/render_manager.cpp | 12 ++++++++++++ engines/zvision/render_manager.h | 4 +++- engines/zvision/render_table.cpp | 17 +++++++++++++++++ engines/zvision/render_table.h | 3 +++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/engines/zvision/render_manager.cpp b/engines/zvision/render_manager.cpp index 132c5971409..2d45ad835d1 100644 --- a/engines/zvision/render_manager.cpp +++ b/engines/zvision/render_manager.cpp @@ -80,6 +80,8 @@ void RenderManager::renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uin destRect.moveTo((_width - subRectangle.width()) / 2, (_height - subRectangle.height()) / 2); } + _backgroundOffset = Common::Point(destRect.left, destRect.top); + if (_renderTable.getRenderState() == RenderTable::FLAT) { _system->copyRectToScreen(buffer + subRectangle.top * horizontalPitch + subRectangle.left, horizontalPitch, destRect.left, destRect.top, destRect.width(), destRect.height()); } else { @@ -139,7 +141,17 @@ void RenderManager::renderImageToScreen(Common::SeekableReadStream &stream, uint tga.destroy(); } +} +const Common::Point RenderManager::convertToImageCoords(const Common::Point &point) { + Common::Point newPoint(point); + + if (_renderTable.getRenderState() == RenderTable::PANORAMA || _renderTable.getRenderState() == RenderTable::TILT) { + newPoint = _renderTable.convertWarpedPointToFlatCoords(newPoint); + } + + newPoint -= _backgroundOffset; + return newPoint; } RenderTable *RenderManager::getRenderTable() { diff --git a/engines/zvision/render_manager.h b/engines/zvision/render_manager.h index 6e267eb3953..aea24505a9d 100644 --- a/engines/zvision/render_manager.h +++ b/engines/zvision/render_manager.h @@ -53,6 +53,7 @@ private: RenderTable _renderTable; Common::SeekableReadStream *_currentBackground; + Common::Point _backgroundOffset; Video::VideoDecoder *_currentVideo; byte *_scaledVideoFrameBuffer; @@ -90,8 +91,9 @@ public: */ void setBackgroundImage(const Common::String &fileName); - RenderTable *getRenderTable(); + const Common::Point convertToImageCoords(const Common::Point &point); + RenderTable *getRenderTable(); private: void renderSubRectToScreen(uint16 *buffer, uint32 imageWidth, uint32 imageHeight, uint32 horizontalPitch, uint32 destinationX, uint32 destinationY, Common::Rect subRectangle, bool autoCenter); diff --git a/engines/zvision/render_table.cpp b/engines/zvision/render_table.cpp index b6598c12b2f..2a111ce6591 100644 --- a/engines/zvision/render_table.cpp +++ b/engines/zvision/render_table.cpp @@ -60,6 +60,16 @@ void RenderTable::setRenderState(RenderState newState) { } } +const Common::Point RenderTable::convertWarpedPointToFlatCoords(const Common::Point &point) { + uint32 index = point.y * _numColumns + point.x; + + Common::Point newPoint(point); + newPoint.x += _internalBuffer[index].x; + newPoint.y += _internalBuffer[index].y; + + return newPoint; +} + uint16 mixTwoRGB(uint16 colorOne, uint16 colorTwo, float percentColorOne) { assert(percentColorOne < 1.0f); @@ -157,7 +167,14 @@ void RenderTable::generatePanoramaLookupTable() { } void RenderTable::generateTiltLookupTable() { + for (uint x = 0; x < _numColumns; x++) { + for (uint y = 0; y < _numRows; y++) { + uint32 index = y * _numColumns + x; + _internalBuffer[index].x = 0; + _internalBuffer[index].y = 0; + } + } } void RenderTable::setPanoramaFoV(float fov) { diff --git a/engines/zvision/render_table.h b/engines/zvision/render_table.h index 82bea62769f..5cef0620452 100644 --- a/engines/zvision/render_table.h +++ b/engines/zvision/render_table.h @@ -63,6 +63,9 @@ private: public: RenderState getRenderState() { return _renderState; } void setRenderState(RenderState newState); + + const Common::Point convertWarpedPointToFlatCoords(const Common::Point &point); + void mutateImage(uint16 *sourceBuffer, uint16* destBuffer, uint32 imageWidth, uint32 imageHeight, Common::Rect subRectangle, Common::Rect destRectangle); void generateRenderTable();