From 29bc46732e2cafcd0ff3c51d47f17ea4165dd5bf Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Tue, 2 Feb 2016 19:42:22 +0100 Subject: [PATCH] Fix saving and loading `GridWarpSurface`s Had to add rows and cols parameters in xml --- src/Application/SettingsLoader.cpp | 23 +++++++++++++++++++++++ src/Surfaces/GridWarpSurface.h | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Application/SettingsLoader.cpp b/src/Application/SettingsLoader.cpp index 223c4d5..5e67d69 100644 --- a/src/Application/SettingsLoader.cpp +++ b/src/Application/SettingsLoader.cpp @@ -167,6 +167,15 @@ bool SettingsLoader::save(SurfaceStack & surfaces, string fileName){ xmlSettings->pushTag("properties"); xmlSettings->addValue("perspectiveWarping", qs->getPerspectiveWarping()); xmlSettings->popTag(); // properties + }else if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){ + GridWarpSurface * gws = (GridWarpSurface *)surface; + if(!xmlSettings->tagExists("properties")){ + xmlSettings->addTag("properties"); + } + xmlSettings->pushTag("properties"); + xmlSettings->addValue("gridCols", gws->getGridCols()); + xmlSettings->addValue("gridRows", gws->getGridRows()); + xmlSettings->popTag(); } xmlSettings->popTag(); // surface @@ -375,10 +384,24 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ xmlSettings->popTag(); // texCoords } + // Read properties + // Only perspective warping for now + int gridCols = 0; + int gridRows = 0; + if(xmlSettings->tagExists("properties")){ + xmlSettings->pushTag("properties"); + gridCols = xmlSettings->getValue("gridCols", 0); + gridRows = xmlSettings->getValue("gridRows", 0); + xmlSettings->popTag(); // properties + } + // Create and add quad surface BaseSurface * gridWarpSurface = SurfaceFactory::instance()->createSurface( SurfaceType::GRID_WARP_SURFACE); + ((GridWarpSurface *)gridWarpSurface)->setGridCols(gridCols); + ((GridWarpSurface *)gridWarpSurface)->setGridRows(gridRows); + ((GridWarpSurface *)gridWarpSurface)->createGridMesh(); gridWarpSurface->setVertices(vertices); gridWarpSurface->setTexCoords(texCoords); diff --git a/src/Surfaces/GridWarpSurface.h b/src/Surfaces/GridWarpSurface.h index d80f2ec..14a047b 100644 --- a/src/Surfaces/GridWarpSurface.h +++ b/src/Surfaces/GridWarpSurface.h @@ -32,12 +32,12 @@ class GridWarpSurface : public BaseSurface { void setTexCoords(vector t); vector & getVertices(); vector & getTexCoords(); + + void createGridMesh(); private: int _gridCols; int _gridRows; - - void createGridMesh(); }; } // namespace piMapper