diff --git a/src/Application/Application.cpp b/src/Application/Application.cpp index b4a9ded..12569a1 100644 --- a/src/Application/Application.cpp +++ b/src/Application/Application.cpp @@ -356,13 +356,14 @@ void Application::selectPrevTexCoord(){ } } -void Application::moveSelection(Vec2 by){ +void Application::moveSelection(Vec3 by){ if(_state == ProjectionMappingMode::instance()){ getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by)); }else if(_state == TextureMappingMode::instance()){ + Vec2 tcBy(by.x, by.y); int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord(); if(selectedTexCoord >= 0){ - moveTexCoord(selectedTexCoord, by); + moveTexCoord(selectedTexCoord, tcBy); } } } diff --git a/src/Application/Application.h b/src/Application/Application.h index e6ad6d0..b3cfc0f 100644 --- a/src/Application/Application.h +++ b/src/Application/Application.h @@ -114,7 +114,7 @@ class Application { Moves vertex when in projection mapping mode. Moves texture coordinate when in texture mapping mode. */ - void moveSelection(Vec2 by); + void moveSelection(Vec3 by); void setPresentationMode(); void setTextureMode(); diff --git a/src/Application/Modes/ProjectionMappingMode.cpp b/src/Application/Modes/ProjectionMappingMode.cpp index 134dabc..2ca7b8d 100644 --- a/src/Application/Modes/ProjectionMappingMode.cpp +++ b/src/Application/Modes/ProjectionMappingMode.cpp @@ -114,33 +114,33 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg case OF_KEY_UP: if(app->isShiftKeyDown()){ - app->moveSelection(Vec2(0.0f, -10.0f)); + app->moveSelection(Vec3(0.0f, -10.0f, 0.0f)); }else{ - app->moveSelection(Vec2(0.0f, -1.0f)); + app->moveSelection(Vec3(0.0f, -1.0f, 0.0f)); } break; case OF_KEY_DOWN: if(app->isShiftKeyDown()){ - app->moveSelection(Vec2(0.0f, 10.0f)); + app->moveSelection(Vec3(0.0f, 10.0f, 0.0f)); }else{ - app->moveSelection(Vec2(0.0f, 1.0f)); + app->moveSelection(Vec3(0.0f, 1.0f, 0.0f)); } break; case OF_KEY_LEFT: if(app->isShiftKeyDown()){ - app->moveSelection(Vec2(-10.0f, 0.0f)); + app->moveSelection(Vec3(-10.0f, 0.0f, 0.0f)); }else{ - app->moveSelection(Vec2(-1.0f, 0.0f)); + app->moveSelection(Vec3(-1.0f, 0.0f, 0.0f)); } break; case OF_KEY_RIGHT: if(app->isShiftKeyDown()){ - app->moveSelection(Vec2(10.0f, 0.0f)); + app->moveSelection(Vec3(10.0f, 0.0f, 0.0f)); }else{ - app->moveSelection(Vec2(1.0f, 0.0f)); + app->moveSelection(Vec3(1.0f, 0.0f, 0.0f)); } break; @@ -242,7 +242,10 @@ void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & if(_bSurfaceDrag){ Vec2 mousePosition = Vec2(args.x, args.y); Vec2 distance = mousePosition - _clickPosition; - Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance); + Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(Vec3( + distance.x, + distance.y, + 0.0f)); _clickPosition = mousePosition; } } diff --git a/src/Application/Modes/ProjectionMappingMode.h b/src/Application/Modes/ProjectionMappingMode.h index ea0b000..6567061 100644 --- a/src/Application/Modes/ProjectionMappingMode.h +++ b/src/Application/Modes/ProjectionMappingMode.h @@ -10,6 +10,7 @@ #include "Gui.h" #include "ScaleWidget.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { diff --git a/src/Application/Modes/TextureMappingMode.cpp b/src/Application/Modes/TextureMappingMode.cpp index e79b80f..e7a15ec 100644 --- a/src/Application/Modes/TextureMappingMode.cpp +++ b/src/Application/Modes/TextureMappingMode.cpp @@ -264,7 +264,7 @@ void TextureMappingMode::drawTexture(Application * app){ ofEnableNormalizedTexCoords(); ofSetColor(255, 255, 255, 255); - app->getSurfaceManager()->getSelectedSurface()->drawTexture(Vec2(0, 0)); + app->getSurfaceManager()->getSelectedSurface()->drawTexture(Vec3(0.0f, 0.0f, 0.0f)); if(!normalizedTexCoords){ ofDisableNormalizedTexCoords(); diff --git a/src/Application/SettingsLoader.cpp b/src/Application/SettingsLoader.cpp index 0ea597c..c916555 100644 --- a/src/Application/SettingsLoader.cpp +++ b/src/Application/SettingsLoader.cpp @@ -178,11 +178,11 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){ xmlSettings->pushTag("surface", i); xmlSettings->addTag("vertices"); xmlSettings->pushTag("vertices"); - vector * vertices = &surface->getVertices(); - for(int j = 0; j < vertices->size(); j++){ + vector vertices = surface->getVertices(); + for(int j = 0; j < vertices.size(); j++){ xmlSettings->addTag("vertex"); xmlSettings->pushTag("vertex", j); - ofVec3f * vertex = &(*vertices)[j]; + Vec3 * vertex = &vertices[j]; xmlSettings->addValue("x", vertex->x); xmlSettings->addValue("y", vertex->y); @@ -194,11 +194,11 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){ xmlSettings->addTag("texCoords"); xmlSettings->pushTag("texCoords"); - vector * texCoords = &surface->getTexCoords(); - for(int j = 0; j < texCoords->size(); j++){ + vector texCoords = surface->getTexCoords(); + for(int j = 0; j < texCoords.size(); j++){ xmlSettings->addTag("texCoord"); xmlSettings->pushTag("texCoord", j); - Vec2 * texCoord = &(*texCoords)[j]; + Vec2 * texCoord = &texCoords[j]; xmlSettings->addValue("x", texCoord->x); xmlSettings->addValue("y", texCoord->y); xmlSettings->popTag(); // texCoord @@ -252,29 +252,35 @@ bool SettingsLoader::create(string fileName){ } BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ - vector vertices; + vector vertices; if(xmlSettings->tagExists("vertices")){ xmlSettings->pushTag("vertices"); if(xmlSettings->tagExists("vertex", 0)){ xmlSettings->pushTag("vertex", 0); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); } if(xmlSettings->tagExists("vertex", 1)){ xmlSettings->pushTag("vertex", 1); - vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 100.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); } if(xmlSettings->tagExists("vertex", 2)){ xmlSettings->pushTag("vertex", 2); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 100.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 100.0f), + 0.0f)); xmlSettings->popTag(); } @@ -321,36 +327,44 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ } BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){ - vector vertices; + vector vertices; if(xmlSettings->tagExists("vertices")){ xmlSettings->pushTag("vertices"); if(xmlSettings->tagExists("vertex", 0)){ xmlSettings->pushTag("vertex", 0); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); } if(xmlSettings->tagExists("vertex", 1)){ xmlSettings->pushTag("vertex", 1); - vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 100.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); } if(xmlSettings->tagExists("vertex", 2)){ xmlSettings->pushTag("vertex", 2); - vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f), - xmlSettings->getValue("y", 100.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 100.0f), + xmlSettings->getValue("y", 100.0f), + 0.0f)); xmlSettings->popTag(); } if(xmlSettings->tagExists("vertex", 3)){ xmlSettings->pushTag("vertex", 3); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 100.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 100.0f), + 0.0f)); xmlSettings->popTag(); } @@ -415,7 +429,7 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){ } BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ - vector vertices; + vector vertices; if(xmlSettings->tagExists("vertices")){ xmlSettings->pushTag("vertices"); @@ -424,8 +438,10 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ while(xmlSettings->tagExists("vertex", iv)){ xmlSettings->pushTag("vertex", iv); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); ++iv; } @@ -476,7 +492,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ } BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){ - vector vertices; + vector vertices; if(xmlSettings->tagExists("vertices")){ xmlSettings->pushTag("vertices"); @@ -484,8 +500,10 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){ unsigned int v = 0; while(xmlSettings->tagExists("vertex", v)){ xmlSettings->pushTag("vertex", v); - vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f), - xmlSettings->getValue("y", 0.0f))); + vertices.push_back(Vec3( + xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f), + 0.0f)); xmlSettings->popTag(); // vertex v += 1; } diff --git a/src/Application/SettingsLoader.h b/src/Application/SettingsLoader.h index 1b5ba9d..fab1626 100644 --- a/src/Application/SettingsLoader.h +++ b/src/Application/SettingsLoader.h @@ -9,6 +9,7 @@ #include "SurfaceType.h" #include "SourceTypeHelper.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { diff --git a/src/Commands/AddGridColCmd.cpp b/src/Commands/AddGridColCmd.cpp index 226da21..f6931d6 100644 --- a/src/Commands/AddGridColCmd.cpp +++ b/src/Commands/AddGridColCmd.cpp @@ -18,11 +18,7 @@ void AddGridColCmd::exec(){ void AddGridColCmd::undo(){ ofLogNotice("AddGridColCmd", "undo"); _surface->setGridCols(_surface->getGridCols() - 1); - vector v; - for(int i = 0; i < _vertices.size(); ++i){ - v.push_back( Vec2(_vertices[i].x, _vertices[i].y) ); - } - _surface->setVertices(v); + _surface->setVertices(_vertices); _surface->setTexCoords(_texCoords); } diff --git a/src/Commands/AddGridColCmd.h b/src/Commands/AddGridColCmd.h index 53575f4..0e37ad8 100644 --- a/src/Commands/AddGridColCmd.h +++ b/src/Commands/AddGridColCmd.h @@ -5,6 +5,7 @@ #include "GridWarpSurface.h" #include "ProjectionEditorWidget.h" #include "Vec2.h" +#include "Vec3.h" class ofxPiMapper; @@ -19,8 +20,8 @@ class AddGridColCmd : public BaseUndoCmd { void undo(); private: - vector _vertices; - vector _texCoords; + vector _vertices; + vector _texCoords; GridWarpSurface * _surface; }; diff --git a/src/Commands/AddGridRowCmd.cpp b/src/Commands/AddGridRowCmd.cpp index 46355f7..a54817a 100644 --- a/src/Commands/AddGridRowCmd.cpp +++ b/src/Commands/AddGridRowCmd.cpp @@ -18,11 +18,7 @@ void AddGridRowCmd::exec(){ void AddGridRowCmd::undo(){ ofLogNotice("AddGridRowCmd", "undo"); _surface->setGridRows(_surface->getGridRows() - 1); - vector v; - for(int i = 0; i < _vertices.size(); ++i){ - v.push_back( Vec2(_vertices[i].x, _vertices[i].y) ); - } - _surface->setVertices(v); + _surface->setVertices(_vertices); _surface->setTexCoords(_texCoords); } diff --git a/src/Commands/AddGridRowCmd.h b/src/Commands/AddGridRowCmd.h index cdb4e95..6b324ce 100644 --- a/src/Commands/AddGridRowCmd.h +++ b/src/Commands/AddGridRowCmd.h @@ -5,6 +5,7 @@ #include "GridWarpSurface.h" #include "ProjectionEditorWidget.h" #include "Vec2.h" +#include "Vec3.h" class ofxPiMapper; @@ -19,7 +20,7 @@ class AddGridRowCmd : public BaseUndoCmd { void undo(); private: - vector _vertices; + vector _vertices; vector _texCoords; GridWarpSurface * _surface; diff --git a/src/Commands/DuplicateSurfaceCmd.cpp b/src/Commands/DuplicateSurfaceCmd.cpp index f2c7157..5e050c7 100644 --- a/src/Commands/DuplicateSurfaceCmd.cpp +++ b/src/Commands/DuplicateSurfaceCmd.cpp @@ -12,7 +12,7 @@ void DuplicateSurfaceCmd::exec(){ ofLogNotice("DuplicateSurfaceCmd", "exec"); _duplicate = _surface->clone(); _surfaceManager->addSurface(_duplicate); - _duplicate->moveBy(Vec2(10.0f, 10.0f)); + _duplicate->moveBy(Vec3(10.0f, 10.0f, 0.0f)); _surfaceManager->selectSurface(_duplicate); } diff --git a/src/Commands/DuplicateSurfaceCmd.h b/src/Commands/DuplicateSurfaceCmd.h index 1809d92..801a1e1 100644 --- a/src/Commands/DuplicateSurfaceCmd.h +++ b/src/Commands/DuplicateSurfaceCmd.h @@ -7,7 +7,7 @@ #include "BaseCmd.h" #include "BaseSurface.h" #include "SurfaceManager.h" -#include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { diff --git a/src/Commands/MvSelectionCmd.cpp b/src/Commands/MvSelectionCmd.cpp index 299362a..ff346c8 100644 --- a/src/Commands/MvSelectionCmd.cpp +++ b/src/Commands/MvSelectionCmd.cpp @@ -3,7 +3,7 @@ namespace ofx { namespace piMapper { -MvSelectionCmd::MvSelectionCmd(SurfaceManager * sm, Vec2 moveBy){ +MvSelectionCmd::MvSelectionCmd(SurfaceManager * sm, Vec3 moveBy){ _surfaceManager = sm; _movedBy = moveBy; } diff --git a/src/Commands/MvSelectionCmd.h b/src/Commands/MvSelectionCmd.h index d72b1ab..0881429 100644 --- a/src/Commands/MvSelectionCmd.h +++ b/src/Commands/MvSelectionCmd.h @@ -2,7 +2,7 @@ #include "BaseCmd.h" #include "SurfaceManager.h" -#include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -10,13 +10,13 @@ namespace piMapper { class MvSelectionCmd : public BaseUndoCmd { public: - MvSelectionCmd(SurfaceManager * sm, Vec2 moveBy); + MvSelectionCmd(SurfaceManager * sm, Vec3 moveBy); void exec(); void undo(); private: SurfaceManager * _surfaceManager; - Vec2 _movedBy; + Vec3 _movedBy; }; diff --git a/src/Commands/MvSurfaceVertCmd.h b/src/Commands/MvSurfaceVertCmd.h index 903184f..c3abd9f 100644 --- a/src/Commands/MvSurfaceVertCmd.h +++ b/src/Commands/MvSurfaceVertCmd.h @@ -8,7 +8,7 @@ #include "BaseSurface.h" #include "ProjectionEditorWidget.h" #include "BaseJoint.h" -#include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -22,7 +22,7 @@ class MvSurfaceVertCmd : public BaseUndoCmd { private: int _vertIndex; - Vec2 _prevVertPos; + Vec3 _prevVertPos; BaseSurface * _surface; }; diff --git a/src/Commands/RmGridColCmd.cpp b/src/Commands/RmGridColCmd.cpp index a874067..6f2e567 100644 --- a/src/Commands/RmGridColCmd.cpp +++ b/src/Commands/RmGridColCmd.cpp @@ -30,13 +30,7 @@ void RmGridColCmd::undo(){ } _surface->setGridCols(_surface->getGridCols() + 1); - vector v; - - for(int i = 0; i < _vertices.size(); ++i){ - v.push_back( Vec2(_vertices[i].x, _vertices[i].y) ); - } - - _surface->setVertices(v); + _surface->setVertices(_vertices); _surface->setTexCoords(_texCoords); } diff --git a/src/Commands/RmGridColCmd.h b/src/Commands/RmGridColCmd.h index 6026224..f79a46b 100644 --- a/src/Commands/RmGridColCmd.h +++ b/src/Commands/RmGridColCmd.h @@ -5,6 +5,7 @@ #include "GridWarpSurface.h" #include "ProjectionEditorWidget.h" #include "Vec2.h" +#include "Vec3.h" class ofxPiMapper; @@ -19,7 +20,7 @@ class RmGridColCmd : public BaseUndoCmd { void undo(); private: - vector _vertices; + vector _vertices; vector _texCoords; GridWarpSurface * _surface; bool _doNotUndo; diff --git a/src/Commands/RmGridRowCmd.cpp b/src/Commands/RmGridRowCmd.cpp index fcd6ba5..36de4ee 100644 --- a/src/Commands/RmGridRowCmd.cpp +++ b/src/Commands/RmGridRowCmd.cpp @@ -30,13 +30,7 @@ void RmGridRowCmd::undo(){ } _surface->setGridRows(_surface->getGridRows() + 1); - vector v; - - for(int i = 0; i < _vertices.size(); ++i){ - v.push_back( Vec2(_vertices[i].x, _vertices[i].y) ); - } - - _surface->setVertices(v); + _surface->setVertices(_vertices); _surface->setTexCoords(_texCoords); } diff --git a/src/Commands/RmGridRowCmd.h b/src/Commands/RmGridRowCmd.h index 1fa9d0d..c1973e0 100644 --- a/src/Commands/RmGridRowCmd.h +++ b/src/Commands/RmGridRowCmd.h @@ -5,6 +5,7 @@ #include "GridWarpSurface.h" #include "ProjectionEditorWidget.h" #include "Vec2.h" +#include "Vec3.h" class ofxPiMapper; @@ -19,7 +20,7 @@ class RmGridRowCmd : public BaseUndoCmd { void undo(); private: - vector _vertices; + vector _vertices; vector _texCoords; GridWarpSurface * _surface; bool _doNotUndo; diff --git a/src/Commands/StartDragSurfaceCmd.cpp b/src/Commands/StartDragSurfaceCmd.cpp index 9ea7bff..2f133eb 100644 --- a/src/Commands/StartDragSurfaceCmd.cpp +++ b/src/Commands/StartDragSurfaceCmd.cpp @@ -15,8 +15,8 @@ void StartDragSurfaceCmd::exec(){ void StartDragSurfaceCmd::undo(){ ofLogNotice("StartDragSurfaceCmd", "undo"); - ofVec3f step = _previousVertices[0] - _surface->getVertices()[0]; - _surface->moveBy(Vec2(step)); + Vec3 step = _previousVertices[0] - _surface->getVertices()[0]; + _surface->moveBy(step); } } // namespace piMapper diff --git a/src/Commands/StartDragSurfaceCmd.h b/src/Commands/StartDragSurfaceCmd.h index d8d7757..e28b878 100644 --- a/src/Commands/StartDragSurfaceCmd.h +++ b/src/Commands/StartDragSurfaceCmd.h @@ -2,7 +2,7 @@ #include "BaseCmd.h" #include "BaseSurface.h" -#include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -16,7 +16,7 @@ class StartDragSurfaceCmd : public BaseUndoCmd { private: BaseSurface * _surface; - vector _previousVertices; + vector _previousVertices; }; diff --git a/src/Gui/Widgets/ProjectionEditorWidget.cpp b/src/Gui/Widgets/ProjectionEditorWidget.cpp index 91016de..8d860f7 100644 --- a/src/Gui/Widgets/ProjectionEditorWidget.cpp +++ b/src/Gui/Widgets/ProjectionEditorWidget.cpp @@ -15,7 +15,10 @@ void ProjectionEditorWidget::update(){ if(joints[i]->isDragged() || joints[i]->isSelected()){ if(surfaceManager->getSelectedSurface() != 0){ // update vertex to new location - surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); + surfaceManager->getSelectedSurface()->setVertex(i, Vec3( + joints[i]->position.x, + joints[i]->position.y, + 0.0f)); }else{ // clear joints if there is no surface selected // as the remove selected surface in the surface manager @@ -50,14 +53,16 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){ Vec2 mousePosition = Vec2(args.x, args.y); // Collect all vertices of the projection surfaces - vector allVertices; + vector allVertices; for(int i = 0; i < surfaceManager->size(); i++){ BaseSurface * surface = surfaceManager->getSurface(i); + if(surface == surfaceManager->getSelectedSurface()){ - continue; // Don't add vertices of selected surface + continue; // Don't add vertices of the selected surface } + for(int j = 0; j < surface->getVertices().size(); j++){ - allVertices.push_back(&surface->getVertices()[j]); + allVertices.push_back(surface->getVertices()[j]); } } @@ -65,13 +70,12 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){ for(int i = 0; i < joints.size(); i++){ if(joints[i]->isDragged()){ for(int j = 0; j < allVertices.size(); j++){ - Vec2 v(*allVertices[j]); + Vec2 v(allVertices[j].x, allVertices[j].y); float distance = mousePosition.distance(v); + if(distance < fSnapDistance){ - joints[i]->position = *allVertices[j]; - Vec2 jointPosition(joints[i]->position); - Vec2 clickPosition(args.x, args.y); - Vec2 clickDistance = jointPosition - clickPosition; + joints[i]->position = v; + Vec2 clickDistance = joints[i]->position - Vec2(args.x, args.y); joints[i]->setClickDistance(clickDistance); break; } @@ -133,8 +137,7 @@ void ProjectionEditorWidget::createJoints(){ return; } - vector & vertices = - surfaceManager->getSelectedSurface()->getVertices(); + vector vertices = surfaceManager->getSelectedSurface()->getVertices(); for(int i = 0; i < vertices.size(); i++){ joints.push_back(new CircleJoint()); @@ -144,8 +147,8 @@ void ProjectionEditorWidget::createJoints(){ void ProjectionEditorWidget::updateJoints(){ if(surfaceManager->getSelectedSurface()){ - vector & vertices = - surfaceManager->getSelectedSurface()->getVertices(); + vector vertices = surfaceManager->getSelectedSurface()->getVertices(); + for(int i = 0; i < vertices.size(); i++){ joints[i]->position = Vec2(vertices[i].x, vertices[i].y); } @@ -159,13 +162,15 @@ void ProjectionEditorWidget::unselectAllJoints(){ } } -void ProjectionEditorWidget::moveSelectedSurface(Vec2 by){ +void ProjectionEditorWidget::moveSelectedSurface(Vec3 by){ if(surfaceManager == 0){ return; } + if(surfaceManager->getSelectedSurface() == 0){ return; } + surfaceManager->getSelectedSurface()->moveBy(by); updateJoints(); } @@ -207,7 +212,7 @@ void ProjectionEditorWidget::onVertexChanged(int & i){ } } -void ProjectionEditorWidget::onVerticesChanged(vector & vertices){ +void ProjectionEditorWidget::onVerticesChanged(vector & vertices){ createJoints(); } diff --git a/src/Gui/Widgets/ProjectionEditorWidget.h b/src/Gui/Widgets/ProjectionEditorWidget.h index 23d6e10..032c642 100644 --- a/src/Gui/Widgets/ProjectionEditorWidget.h +++ b/src/Gui/Widgets/ProjectionEditorWidget.h @@ -3,6 +3,7 @@ #include "SurfaceManager.h" #include "CircleJoint.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -23,7 +24,7 @@ class ProjectionEditorWidget { void createJoints(); void updateJoints(); void unselectAllJoints(); - void moveSelectedSurface(Vec2 by); + void moveSelectedSurface(Vec3 by); void stopDragJoints(); void updateVertices(); void setSnapDistance(float newSnapDistance); @@ -31,7 +32,7 @@ class ProjectionEditorWidget { vector * getJoints(); void onVertexChanged(int & i); - void onVerticesChanged(vector & vertices); + void onVerticesChanged(vector & vertices); void onSurfaceSelected(int & surfaceIndex); void onVertexSelected(int & vertexIndex); void onVertexUnselected(int & vertexIndex); diff --git a/src/Gui/Widgets/TextureEditorWidget.cpp b/src/Gui/Widgets/TextureEditorWidget.cpp index da21b01..d4da08e 100644 --- a/src/Gui/Widgets/TextureEditorWidget.cpp +++ b/src/Gui/Widgets/TextureEditorWidget.cpp @@ -44,9 +44,10 @@ void TextureEditorWidget::update(){ if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){ GridWarpSurface * s = (GridWarpSurface *)surface; - vector & texCoords = surface->getTexCoords(); - Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(), - surface->getSource()->getTexture()->getHeight()); + vector texCoords = surface->getTexCoords(); + Vec2 textureSize = Vec2( + surface->getSource()->getTexture()->getWidth(), + surface->getSource()->getTexture()->getHeight()); int rows = s->getGridRows(); int cols = s->getGridCols(); @@ -131,8 +132,9 @@ void TextureEditorWidget::createJoints(){ if(surface == 0){ return; } + clearJoints(); - vector & texCoords = surface->getTexCoords(); + vector texCoords = surface->getTexCoords(); if(surface->getSource()->getTexture()->isAllocated()){ _pollCreateJoints = false; @@ -141,11 +143,12 @@ void TextureEditorWidget::createJoints(){ return; } - Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(), - surface->getSource()->getTexture()->getHeight()); + Vec2 textureSize = Vec2( + surface->getSource()->getTexture()->getWidth(), + surface->getSource()->getTexture()->getHeight()); // Select joints depending on the surface type - vector tc; + vector tc; if(surface->getType() == SurfaceType::TRIANGLE_SURFACE){ tc = texCoords; @@ -279,9 +282,10 @@ void TextureEditorWidget::moveTexCoords(Vec2 by){ return; } - vector & texCoords = surface->getTexCoords(); - Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(), - surface->getSource()->getTexture()->getHeight()); + vector texCoords = surface->getTexCoords(); + Vec2 textureSize = Vec2( + surface->getSource()->getTexture()->getWidth(), + surface->getSource()->getTexture()->getHeight()); for(int i = 0; i < joints.size(); i++){ joints[i]->position += by; @@ -408,4 +412,4 @@ vector & TextureEditorWidget::getJoints(){ } } // namespace piMapper -} // namespace ofx \ No newline at end of file +} // namespace ofx diff --git a/src/Surfaces/BaseSurface.cpp b/src/Surfaces/BaseSurface.cpp index 6675055..c309abd 100644 --- a/src/Surfaces/BaseSurface.cpp +++ b/src/Surfaces/BaseSurface.cpp @@ -21,7 +21,10 @@ void BaseSurface::createDefaultTexture(){ for(int i = 0; i < pixels.size(); i++){ pixels[i] = 255; } - int squareSize = 10; // size of each test pattern square + + // size of each test pattern square + int squareSize = 10; + bool sy = false; for(int y = 0; y < pixels.getWidth(); y += squareSize){ bool sx = false; @@ -46,53 +49,54 @@ void BaseSurface::createDefaultTexture(){ // load pixels into texture defaultTexture.loadData(pixels); + // Create new source to be the default defaultSource = new BaseSource(&defaultTexture); source = defaultSource; } -void BaseSurface::drawTexture(Vec2 position){ +void BaseSurface::drawTexture(Vec3 position){ if(source->getTexture() == 0){ ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; return; } + // TODO: Do not recreate this in each draw loop ofMesh texMesh; - texMesh.addVertex(position.toOf()); - Vec2 topRight(source->getTexture()->getWidth(), 0.0f); + // Add vertices to the mesh + texMesh.addVertex(position.toOf()); + Vec3 topRight(source->getTexture()->getWidth(), 0.0f, 0.0f); texMesh.addVertex((position + topRight).toOf()); - - Vec2 bottomRight(source->getTexture()->getWidth(), source->getTexture()->getHeight()); + Vec3 bottomRight(source->getTexture()->getWidth(), source->getTexture()->getHeight(), 0.0f); texMesh.addVertex((position + bottomRight).toOf()); - - Vec2 bottomLeft(0.0f, source->getTexture()->getHeight()); + Vec3 bottomLeft(0.0f, source->getTexture()->getHeight(), 0.0f); texMesh.addVertex((position + bottomLeft).toOf()); + // Make triangles out of added vertices texMesh.addTriangle(0, 2, 3); texMesh.addTriangle(0, 1, 2); + // Add texture coordinates for the added vertices texMesh.addTexCoord(Vec2(0.0f, 0.0f).toOf()); texMesh.addTexCoord(Vec2(1.0f, 0.0f).toOf()); texMesh.addTexCoord(Vec2(1.0f, 1.0f).toOf()); texMesh.addTexCoord(Vec2(0.0f, 1.0f).toOf()); + // Draw mesh source->getTexture()->bind(); texMesh.draw(); source->getTexture()->unbind(); } -//void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; } void BaseSurface::setSource(BaseSource * newSource){ source = newSource; } -//ofTexture* BaseSurface::getTexture() { return texture; } BaseSource * BaseSurface::getSource(){ return source; } -//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; } BaseSource * BaseSurface::getDefaultSource(){ return defaultSource; } @@ -102,16 +106,20 @@ void BaseSurface::setMoved(bool moved){ } void BaseSurface::scaleTo(float scale){ - ofPoint centroid = getBoundingBox().getCenter(); + Vec3 centroid( + getBoundingBox().getCenter().x, + getBoundingBox().getCenter().y, + getBoundingBox().getCenter().z); for(unsigned int i = 0; i < mesh.getVertices().size(); ++i){ - ofVec3f d = (mesh.getVertices()[i] - centroid) / _scale; + Vec3 d = (Vec3(mesh.getVertices()[i]) - centroid) / _scale; d *= scale; - mesh.getVertices()[i] = centroid + d; + mesh.getVertices()[i] = (centroid + d).toOf(); } _scale = scale; - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } bool BaseSurface::getMoved(){ diff --git a/src/Surfaces/BaseSurface.h b/src/Surfaces/BaseSurface.h index 1dfa6e9..5ab86e5 100644 --- a/src/Surfaces/BaseSurface.h +++ b/src/Surfaces/BaseSurface.h @@ -4,6 +4,7 @@ #include #include "BaseSource.h" #include "Vec2.h" +#include "Vec3.h" using namespace std; @@ -18,25 +19,20 @@ class BaseSurface { virtual void setup() = 0; virtual void draw() = 0; - virtual void setVertex(int index, Vec2 p) = 0; - virtual void setVertices(vector v) = 0; + virtual void setVertex(int index, Vec3 p) = 0; + virtual void setVertices(vector v) = 0; virtual void setTexCoord(int index, Vec2 t) = 0; virtual void setTexCoords(vector t) = 0; - virtual void moveBy(Vec2 v) = 0; - + virtual void moveBy(Vec3 v) = 0; virtual int getType() = 0; - virtual bool hitTest(Vec2 p) = 0; - virtual ofPolyline getHitArea() = 0; virtual ofPolyline getTextureHitArea() = 0; - - virtual vector & getVertices() = 0; - virtual vector & getTexCoords() = 0; - + virtual vector getVertices() = 0; + virtual vector getTexCoords() = 0; virtual BaseSurface * clone() = 0; - void drawTexture(Vec2 position); + void drawTexture(Vec3 position); void setSource(BaseSource * newSource); void setMoved(bool moved); void scaleTo(float scale); @@ -50,26 +46,19 @@ class BaseSurface { ofMesh & getMesh(); ofRectangle & getBoundingBox(); - ofEvent > verticesChangedEvent; - ofEvent vertexChangedEvent; + ofEvent> verticesChangedEvent; + ofEvent vertexChangedEvent; protected: ofMesh mesh; - ofRectangle _boundingBox; - ofTexture defaultTexture; - BaseSource * source; BaseSource * defaultSource; void createDefaultTexture(); - bool _moved; - float _scale; - - vector _texCoords; }; } // namespace piMapper diff --git a/src/Surfaces/CircleSurface.cpp b/src/Surfaces/CircleSurface.cpp index c2eda67..b0801fb 100644 --- a/src/Surfaces/CircleSurface.cpp +++ b/src/Surfaces/CircleSurface.cpp @@ -1,6 +1,7 @@ // // CircleSurface.cpp // Copyright (c) 2017 Cristobal Mendoza +// With modifications by Krisjanis Rijnieks (c) 2017 // http://cuppetellimendoza.com #include "CircleSurface.h" @@ -19,8 +20,6 @@ CircleSurface::CircleSurface(QuadSurface &surface) { setPerspectiveWarping(surface.getPerspectiveWarping()); } -CircleSurface::~CircleSurface() {} - void CircleSurface::setup() { QuadSurface::setup(); @@ -264,10 +263,10 @@ void CircleSurface::setupTextures() { // meshes are similar: // Create 4 points for the 2 triangles - Vec3 p1 = Vec3(0, 0, 0); - Vec3 p2 = Vec3(0, h, 0); - Vec3 p3 = Vec3(w, h, 0); - Vec3 p4 = Vec3(w, 0, 0); + Vec3 p1 = Vec3(0.0f, 0.0f, 0.0f); + Vec3 p2 = Vec3(0.0f, h, 0.0f); + Vec3 p3 = Vec3(w, h, 0.0f); + Vec3 p4 = Vec3(w, 0.0f, 0.0f); // Create 4 point for the texture coordinates Vec2 t1 = Vec2(Vec2(0.0f, 1.0f)); diff --git a/src/Surfaces/CircleSurface.h b/src/Surfaces/CircleSurface.h index b269adf..5f23395 100644 --- a/src/Surfaces/CircleSurface.h +++ b/src/Surfaces/CircleSurface.h @@ -1,6 +1,7 @@ // // CircleSurface.h // Copyright (c) 2017 Cristobal Mendoza +// With modifications by Krisjanis Rijnieks (c) 2017 // http://cuppetellimendoza.com #ifndef OFXPIMAPPER_CIRCLESURFACE_H @@ -20,7 +21,6 @@ class CircleSurface : public QuadSurface { CircleSurface(); CircleSurface(QuadSurface &surface); int getType() override; - ~CircleSurface(); void draw() override; void setup() override; diff --git a/src/Surfaces/GridWarpSurface.cpp b/src/Surfaces/GridWarpSurface.cpp index 6fd5927..b48ad2c 100644 --- a/src/Surfaces/GridWarpSurface.cpp +++ b/src/Surfaces/GridWarpSurface.cpp @@ -9,10 +9,6 @@ GridWarpSurface::GridWarpSurface(){ createGridMesh(); } -void GridWarpSurface::setup(){ - // Nothing here yet -} - void GridWarpSurface::draw(){ if(source->getTexture() == 0){ return; @@ -34,15 +30,14 @@ void GridWarpSurface::draw(){ } } -void GridWarpSurface::moveBy(Vec2 v){ - vector & vertices = getVertices(); - - for(int i = 0; i < vertices.size(); i++){ - vertices[i] += v.toOf(); +void GridWarpSurface::moveBy(Vec3 v){ + for(int i = 0; i < mesh.getVertices().size(); i++){ + mesh.getVertices()[i] += v.toOf(); } setMoved(true); - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } int GridWarpSurface::getType(){ @@ -146,17 +141,16 @@ ofPolyline GridWarpSurface::getTextureHitArea(){ return line; } -void GridWarpSurface::setVertex(int index, Vec2 p){ +void GridWarpSurface::setVertex(int index, Vec3 vert){ if(index >= mesh.getVertices().size()){ throw runtime_error("Vertex with provided index does not exist"); } - mesh.setVertex(index, p.toOf()); - ofVec3f v = mesh.getVertex(index); + mesh.setVertex(index, vert.toOf()); ofNotifyEvent(vertexChangedEvent, index, this); } -void GridWarpSurface::setVertices(vector v){ +void GridWarpSurface::setVertices(vector v){ if(v.size() != mesh.getVertices().size()){ throw runtime_error("Wrong number of vertices"); } @@ -165,19 +159,8 @@ void GridWarpSurface::setVertices(vector v){ mesh.setVertex(i, v[i].toOf()); } - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); -} - -void GridWarpSurface::setVertices(vector v){ - if(v.size() != mesh.getVertices().size()){ - throw runtime_error("Wrong number of vertices"); - } - - for(int i = 0; i < v.size(); ++i){ - mesh.setVertex(i, v[i]); - } - - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } void GridWarpSurface::setTexCoord(int index, Vec2 t){ @@ -197,16 +180,12 @@ void GridWarpSurface::setTexCoords(vector t){ } -vector & GridWarpSurface::getVertices(){ - return mesh.getVertices(); +vector GridWarpSurface::getVertices(){ + return Vec3::fromOf(mesh.getVertices()); } -vector & GridWarpSurface::getTexCoords(){ - _texCoords.clear(); - for(auto c : mesh.getTexCoords()){ - _texCoords.push_back(Vec2(c)); - } - return _texCoords; +vector GridWarpSurface::getTexCoords(){ + return Vec2::fromOf(mesh.getTexCoords()); } void GridWarpSurface::createGridMesh(){ @@ -251,7 +230,8 @@ void GridWarpSurface::createGridMesh(){ } } - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } BaseSurface * GridWarpSurface::clone(){ diff --git a/src/Surfaces/GridWarpSurface.h b/src/Surfaces/GridWarpSurface.h index 370e618..9f997f6 100644 --- a/src/Surfaces/GridWarpSurface.h +++ b/src/Surfaces/GridWarpSurface.h @@ -5,6 +5,7 @@ #include "SurfaceType.h" #include "HomographyHelper.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -13,9 +14,9 @@ class GridWarpSurface : public BaseSurface { public: GridWarpSurface(); - void setup(); + void setup(){}; void draw(); - void moveBy(Vec2 v); + void moveBy(Vec3 v); int getType(); int getGridRows(); @@ -28,13 +29,12 @@ class GridWarpSurface : public BaseSurface { ofPolyline getHitArea(); ofPolyline getTextureHitArea(); - void setVertex(int index, Vec2 p); - void setVertices(vector v); - void setVertices(vector v); + void setVertex(int index, Vec3 p); + void setVertices(vector v); void setTexCoord(int index, Vec2 t); void setTexCoords(vector t); - vector & getVertices(); - vector & getTexCoords(); + vector getVertices(); + vector getTexCoords(); void createGridMesh(); @@ -43,8 +43,6 @@ class GridWarpSurface : public BaseSurface { private: int _gridCols; int _gridRows; - - vector _texCoords; }; } // namespace piMapper diff --git a/src/Surfaces/HexagonSurface.cpp b/src/Surfaces/HexagonSurface.cpp index 5fa16a2..99df1d2 100644 --- a/src/Surfaces/HexagonSurface.cpp +++ b/src/Surfaces/HexagonSurface.cpp @@ -11,19 +11,19 @@ void HexagonSurface::setup(){ // Create 6 + 1 points for the hexagon surface. - vector verts; + vector verts; verts.resize(7); // Start with the center. - verts[0] = Vec2((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f); + verts[0] = Vec3((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f, 0.0f); // Then from top left clockwise. - verts[1] = Vec2((float)ofGetWidth() / 3.0f, 0); - verts[2] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, 0); - verts[3] = Vec2(ofGetWidth(), (float)ofGetHeight() / 2.0f); - verts[4] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight()); - verts[5] = Vec2((float)ofGetWidth() / 3.0f, ofGetHeight()); - verts[6] = Vec2(0, (float)ofGetHeight() / 2.0f); + verts[1] = Vec3((float)ofGetWidth() / 3.0f, 0.0f, 0.0f); + verts[2] = Vec3((float)ofGetWidth() / 3.0f * 2.0f, 0.0f, 0.0f); + verts[3] = Vec3(ofGetWidth(), (float)ofGetHeight() / 2.0f, 0.0f); + verts[4] = Vec3((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight(), 0.0f); + verts[5] = Vec3((float)ofGetWidth() / 3.0f, ofGetHeight(), 0.0f); + verts[6] = Vec3(0, (float)ofGetHeight() / 2.0f, 0.0f); // No create the texture coordinates. vector coords; @@ -45,7 +45,7 @@ void HexagonSurface::setup(){ } void HexagonSurface::setup( - vector & verts, + vector & verts, vector & coords, BaseSource * newSource){ @@ -103,18 +103,17 @@ void HexagonSurface::draw(){ } } -void HexagonSurface::setVertex(int index, Vec2 p){ +void HexagonSurface::setVertex(int index, Vec3 p){ if(index >= mesh.getVertices().size()){ ofLog() << "Vertex with this index does not exist: " << index << endl; return; } mesh.setVertex(index, p.toOf()); - ofVec3f v = mesh.getVertex(index); ofNotifyEvent(vertexChangedEvent, index, this); } -void HexagonSurface::setVertices(vector v){ +void HexagonSurface::setVertices(vector v){ if(v.size() != mesh.getVertices().size()){ throw runtime_error("Wrong number of vertices"); } @@ -123,19 +122,8 @@ void HexagonSurface::setVertices(vector v){ mesh.setVertex(i, v[i].toOf()); } - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); -} - -void HexagonSurface::setVertices(vector v){ - if(v.size() != mesh.getVertices().size()){ - throw runtime_error("Wrong number of vertices"); - } - - for(int i = 0; i < v.size(); ++i){ - mesh.setVertex(i, v[i]); - } - - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } void HexagonSurface::setTexCoord(int index, Vec2 t){ @@ -152,20 +140,20 @@ void HexagonSurface::setTexCoords(vector t){ if(t.size() != mesh.getTexCoords().size()){ throw runtime_error("Wrong number of texture coordinates"); } + for(int i = 0; i < t.size(); ++i){ mesh.setTexCoord(i, t[i].toOf()); } } -void HexagonSurface::moveBy(Vec2 v){ - vector & vertices = getVertices(); - - for(int i = 0; i < vertices.size(); i++){ - vertices[i] += v.toOf(); +void HexagonSurface::moveBy(Vec3 v){ + for(int i = 0; i < mesh.getVertices().size(); i++){ + mesh.getVertices()[i] += v.toOf(); } setMoved(true); - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } int HexagonSurface::getType(){ @@ -173,7 +161,6 @@ int HexagonSurface::getType(){ } bool HexagonSurface::hitTest(Vec2 p){ - // Construct ofPolyline from vertices ofPolyline line = getHitArea(); if(line.inside(p.x, p.y)){ @@ -183,18 +170,20 @@ bool HexagonSurface::hitTest(Vec2 p){ } } -Vec2 HexagonSurface::getVertex(int index){ +Vec3 HexagonSurface::getVertex(int index){ if(index > 2){ ofLog() << "Vertex with this index does not exist: " << index << endl; throw runtime_error("Vertex index out of bounds."); } - ofVec3f vert = mesh.getVertex(index); - return Vec2(vert.x, vert.y); + return Vec3( + mesh.getVertex(index).x, + mesh.getVertex(index).y, + mesh.getVertex(index).z); } Vec2 HexagonSurface::getTexCoord(int index){ - if(index > 2){ + if(index > 1){ throw runtime_error("Texture coordinate index out of bounds."); } @@ -211,7 +200,6 @@ ofPolyline HexagonSurface::getHitArea(){ } line.close(); - return line; } @@ -229,17 +217,12 @@ ofPolyline HexagonSurface::getTextureHitArea(){ return line; } -vector & HexagonSurface::getVertices(){ - // return only joint vertices - return mesh.getVertices(); +vector HexagonSurface::getVertices(){ + return Vec3::fromOf(mesh.getVertices()); } -vector & HexagonSurface::getTexCoords(){ - _texCoords.clear(); - for(auto tc : mesh.getTexCoords()){ - _texCoords.push_back(tc); - } - return _texCoords; +vector HexagonSurface::getTexCoords(){ + return Vec2::fromOf(mesh.getTexCoords()); } BaseSurface * HexagonSurface::clone(){ diff --git a/src/Surfaces/HexagonSurface.h b/src/Surfaces/HexagonSurface.h index 051bdd6..11277ec 100644 --- a/src/Surfaces/HexagonSurface.h +++ b/src/Surfaces/HexagonSurface.h @@ -4,6 +4,7 @@ #include "BaseSurface.h" #include "SurfaceType.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -16,28 +17,24 @@ class HexagonSurface : public BaseSurface { void setup(); void setup( - vector & verts, + vector & verts, vector & coords, BaseSource * newSource); void draw(); - - void setVertex(int index, Vec2 p); - void setVertices(vector v); - void setVertices(vector v); - + void setVertex(int index, Vec3 p); + void setVertices(vector v); void setTexCoord(int index, Vec2 t); void setTexCoords(vector t); - - void moveBy(Vec2 v); + void moveBy(Vec3 v); int getType(); bool hitTest(Vec2 p); - Vec2 getVertex(int index); + Vec3 getVertex(int index); Vec2 getTexCoord(int index); ofPolyline getHitArea(); ofPolyline getTextureHitArea(); - vector & getVertices(); - vector & getTexCoords(); + vector getVertices(); + vector getTexCoords(); BaseSurface * clone(); }; diff --git a/src/Surfaces/QuadSurface.cpp b/src/Surfaces/QuadSurface.cpp index 7b83c3e..74c6c8a 100644 --- a/src/Surfaces/QuadSurface.cpp +++ b/src/Surfaces/QuadSurface.cpp @@ -14,21 +14,21 @@ QuadSurface::~QuadSurface(){ void QuadSurface::setup(){ // Create 4 points for the 2 triangles - Vec2 p1 = Vec2(0, 0); - Vec2 p2 = Vec2(0, ofGetHeight()); - Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight()); - Vec2 p4 = Vec2(ofGetWidth(), 0); + Vec3 p1 = Vec3(0.0f, 0.0f, 0.0f); + Vec3 p2 = Vec3(0.0f, ofGetHeight(), 0.0f); + Vec3 p3 = Vec3(ofGetWidth(), ofGetHeight(), 0.0f); + Vec3 p4 = Vec3(ofGetWidth(), 0.0f, 0.0f); // Create 4 point for the texture coordinates - Vec2 t1 = Vec2(Vec2(0.0f, 0.0f)); - Vec2 t2 = Vec2(Vec2(1.0f, 0.0f)); - Vec2 t3 = Vec2(Vec2(1.0f, 1.0f)); - Vec2 t4 = Vec2(Vec2(0.0f, 1.0f)); + Vec2 t1 = Vec2(0.0f, 0.0f); + Vec2 t2 = Vec2(1.0f, 0.0f); + Vec2 t3 = Vec2(1.0f, 1.0f); + Vec2 t4 = Vec2(0.0f, 1.0f); setup(p1, p2, p3, p4, t1, t2, t3, t4, source); } -void QuadSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, +void QuadSurface::setup(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, Vec2 t1, Vec2 t2, Vec2 t3, Vec2 t4, BaseSource * newSource){ // Assign texture @@ -71,10 +71,10 @@ void QuadSurface::draw(){ ofRectangle box = getMeshBoundingBox(); ofMesh m = mesh; - m.setVertex(0, ofVec3f(0, 0, 0)); - m.setVertex(1, ofVec3f(box.width, 0, 0)); - m.setVertex(2, ofVec3f(box.width, box.height, 0)); - m.setVertex(3, ofVec3f(0, box.height, 0)); + m.setVertex(0, Vec3(0, 0, 0).toOf()); + m.setVertex(1, Vec3(box.width, 0, 0).toOf()); + m.setVertex(2, Vec3(box.width, box.height, 0).toOf()); + m.setVertex(3, Vec3(0, box.height, 0).toOf()); ofPushMatrix(); if(true){ @@ -110,18 +110,17 @@ void QuadSurface::draw(){ } } -void QuadSurface::setVertex(int index, Vec2 p){ +void QuadSurface::setVertex(int index, Vec3 p){ if(index > 3){ ofLog() << "Vertex with this index does not exist: " << index << endl; return; } mesh.setVertex(index, p.toOf()); - ofVec3f v = mesh.getVertex(index); ofNotifyEvent(vertexChangedEvent, index, this); } -void QuadSurface::setVertices(vector v){ +void QuadSurface::setVertices(vector v){ if(v.size() != 4){ throw runtime_error("Wrong number of vertices"); } @@ -130,19 +129,8 @@ void QuadSurface::setVertices(vector v){ mesh.setVertex(i, v[i].toOf()); } - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); -} - -void QuadSurface::setVertices(vector v){ - if(v.size() != 4){ - throw runtime_error("Wrong number of vertices"); - } - - for(int i = 0; i < 4; ++i){ - mesh.setVertex(i, v[i]); - } - - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } void QuadSurface::setTexCoord(int index, Vec2 t){ @@ -164,15 +152,14 @@ void QuadSurface::setTexCoords(vector t){ } } -void QuadSurface::moveBy(Vec2 v){ - vector & vertices = getVertices(); - - for(int i = 0; i < vertices.size(); i++){ - vertices[i] += v.toOf(); +void QuadSurface::moveBy(Vec3 v){ + for(int i = 0; i < mesh.getVertices().size(); i++){ + mesh.getVertices()[i] += v.toOf(); } setMoved(true); - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } int QuadSurface::getType(){ @@ -180,7 +167,6 @@ int QuadSurface::getType(){ } bool QuadSurface::hitTest(Vec2 p){ - // Construct ofPolyline from vertices ofPolyline line = getHitArea(); if(line.inside(p.x, p.y)){ @@ -190,14 +176,16 @@ bool QuadSurface::hitTest(Vec2 p){ } } -Vec2 QuadSurface::getVertex(int index){ +Vec3 QuadSurface::getVertex(int index){ if(index > 3){ ofLog() << "Vertex with this index does not exist: " << index << endl; throw runtime_error("Vertex index out of bounds."); } - - ofVec3f vert = mesh.getVertex(index); - return Vec2(vert.x, vert.y); + + return Vec3( + mesh.getVertex(index).x, + mesh.getVertex(index).y, + mesh.getVertex(index).z); } Vec2 QuadSurface::getTexCoord(int index){ @@ -212,6 +200,7 @@ Vec2 QuadSurface::getTexCoord(int index){ ofPolyline QuadSurface::getHitArea(){ ofPolyline line; + line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); @@ -234,17 +223,12 @@ ofPolyline QuadSurface::getTextureHitArea(){ return line; } -vector & QuadSurface::getVertices(){ - // return only joint vertices - return mesh.getVertices(); +vector QuadSurface::getVertices(){ + return Vec3::fromOf(mesh.getVertices()); } -vector & QuadSurface::getTexCoords(){ - _texCoords.clear(); - for(auto tc : mesh.getTexCoords()){ - _texCoords.push_back(tc); - } - return _texCoords; +vector QuadSurface::getTexCoords(){ + return Vec2::fromOf(mesh.getTexCoords()); } void QuadSurface::calculateHomography(){ @@ -262,10 +246,10 @@ void QuadSurface::calculateHomography(){ src[3][0] = 0; src[3][1] = box.height; - ofVec3f p0 = mesh.getVertex(0); - ofVec3f p1 = mesh.getVertex(1); - ofVec3f p2 = mesh.getVertex(2); - ofVec3f p3 = mesh.getVertex(3); + Vec3 p0(mesh.getVertex(0).x, mesh.getVertex(0).y, mesh.getVertex(0).z); + Vec3 p1(mesh.getVertex(1).x, mesh.getVertex(1).y, mesh.getVertex(1).z); + Vec3 p2(mesh.getVertex(2).x, mesh.getVertex(2).y, mesh.getVertex(2).z); + Vec3 p3(mesh.getVertex(3).x, mesh.getVertex(3).y, mesh.getVertex(3).z); dst[0][0] = p0.x; dst[0][1] = p0.y; diff --git a/src/Surfaces/QuadSurface.h b/src/Surfaces/QuadSurface.h index a0c3bc2..8a48b56 100644 --- a/src/Surfaces/QuadSurface.h +++ b/src/Surfaces/QuadSurface.h @@ -5,6 +5,7 @@ #include "SurfaceType.h" #include "HomographyHelper.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -15,39 +16,34 @@ class QuadSurface : public BaseSurface { ~QuadSurface(); void setup(); - void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, Vec2 t1, - Vec2 t2, Vec2 t3, Vec2 t4, BaseSource * newSource); - + void setup( + Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, + Vec2 t1, Vec2 t2, Vec2 t3, Vec2 t4, + BaseSource * newSource); void draw(); - - void setVertex(int index, Vec2 p); - void setVertices(vector v); - void setVertices(vector v); - + void setVertex(int index, Vec3 p); + void setVertices(vector v); void setTexCoord(int index, Vec2 t); void setTexCoords(vector t); - - void moveBy(Vec2 v); + void moveBy(Vec3 v); int getType(); bool hitTest(Vec2 p); - Vec2 getVertex(int index); + Vec3 getVertex(int index); Vec2 getTexCoord(int index); ofPolyline getHitArea(); ofPolyline getTextureHitArea(); - vector & getVertices(); - vector & getTexCoords(); + vector getVertices(); + vector getTexCoords(); void setPerspectiveWarping(bool b); bool getPerspectiveWarping(); ofRectangle getMeshBoundingBox(); - BaseSurface * clone(); private: void calculateHomography(); - float _matrix[16]; bool _perspectiveWarping; }; diff --git a/src/Surfaces/SurfaceFactory.cpp b/src/Surfaces/SurfaceFactory.cpp index 9544e53..c6d02ed 100644 --- a/src/Surfaces/SurfaceFactory.cpp +++ b/src/Surfaces/SurfaceFactory.cpp @@ -29,11 +29,11 @@ BaseSurface * SurfaceFactory::createSurface(SurfaceType type){ } TriangleSurface * SurfaceFactory::createTriangleSurface(){ - vector vertices; + vector vertices; float margin = 50.0f; - vertices.push_back(Vec2((float)ofGetWidth() / 2.0f, margin)); - vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); - vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin)); + vertices.push_back(Vec3((float)ofGetWidth() / 2.0f, margin, 0.0f)); + vertices.push_back(Vec3((float)ofGetWidth() - margin, (float)ofGetHeight() - margin, 0.0f)); + vertices.push_back(Vec3(margin, (float)ofGetHeight() - margin, 0.0f)); vector texCoords; texCoords.push_back(Vec2(0.5f, 0.0f)); @@ -51,12 +51,12 @@ TriangleSurface * SurfaceFactory::createTriangleSurface(){ } QuadSurface * SurfaceFactory::createQuadSurface(){ - vector vertices; + vector vertices; float margin = 50.0f; - vertices.push_back(Vec2(margin, margin)); - vertices.push_back(Vec2((float)ofGetWidth() - margin, margin)); - vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); - vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin)); + vertices.push_back(Vec3(margin, margin, 0.0f)); + vertices.push_back(Vec3((float)ofGetWidth() - margin, margin, 0.0f)); + vertices.push_back(Vec3((float)ofGetWidth() - margin, (float)ofGetHeight() - margin, 0.0f)); + vertices.push_back(Vec3(margin, (float)ofGetHeight() - margin, 0.0f)); vector texCoords; texCoords.push_back(Vec2(Vec2(0.0f, 0.0f))); diff --git a/src/Surfaces/SurfaceManager.cpp b/src/Surfaces/SurfaceManager.cpp index 399a914..e991efb 100644 --- a/src/Surfaces/SurfaceManager.cpp +++ b/src/Surfaces/SurfaceManager.cpp @@ -303,14 +303,14 @@ void SurfaceManager::selectVertex(int i){ ofNotifyEvent(vertexSelectedEvent, _selectedVertexIndex, this); } -void SurfaceManager::moveSelectionBy(Vec2 v){ +void SurfaceManager::moveSelectionBy(Vec3 v){ if(selectedSurface == 0){ moveAllSurfacesBy(v); return; } if(_selectedVertexIndex != -1){ - selectedSurface->getVertices()[_selectedVertexIndex] += v.toOf(); + selectedSurface->getMesh().getVertices()[_selectedVertexIndex] += v.toOf(); ofNotifyEvent(vertexChangedEvent, _selectedVertexIndex, this); }else{ selectedSurface->moveBy(v); @@ -321,7 +321,7 @@ void SurfaceManager::moveSelectionBy(Vec2 v){ // it could be implemented as vector here. } -void SurfaceManager::moveAllSurfacesBy(Vec2 v){ +void SurfaceManager::moveAllSurfacesBy(Vec3 v){ if(_activePresetIndex < 0){ ofLogWarning( "SurfaceManager::moveAllSurfacesBy", @@ -393,7 +393,7 @@ void SurfaceManager::onVertexChanged(int & i){ ofNotifyEvent(vertexChangedEvent, i, this); } -void SurfaceManager::onVerticesChanged(vector & vertices){ +void SurfaceManager::onVerticesChanged(vector & vertices){ ofNotifyEvent(verticesChangedEvent, vertices, this); } diff --git a/src/Surfaces/SurfaceManager.h b/src/Surfaces/SurfaceManager.h index fe39001..b33cd07 100644 --- a/src/Surfaces/SurfaceManager.h +++ b/src/Surfaces/SurfaceManager.h @@ -51,8 +51,8 @@ class SurfaceManager { void selectPrevVertex(); void selectVertex(int i); - void moveSelectionBy(Vec2 v); - void moveAllSurfacesBy(Vec2 v); + void moveSelectionBy(Vec3 v); + void moveAllSurfacesBy(Vec3 v); int size(); int getSelectedVertexIndex(); @@ -61,13 +61,13 @@ class SurfaceManager { unsigned int getNumPresets(); ofEvent vertexChangedEvent; - ofEvent > verticesChangedEvent; + ofEvent > verticesChangedEvent; ofEvent surfaceSelectedEvent; ofEvent vertexSelectedEvent; ofEvent vertexUnselectedEvent; void onVertexChanged(int & i); - void onVerticesChanged(vector & vertices); + void onVerticesChanged(vector & vertices); SurfaceStack * getActivePreset(); SurfaceStack * createPreset(); diff --git a/src/Surfaces/SurfaceStack.cpp b/src/Surfaces/SurfaceStack.cpp index 89651a6..22605be 100644 --- a/src/Surfaces/SurfaceStack.cpp +++ b/src/Surfaces/SurfaceStack.cpp @@ -65,7 +65,7 @@ BaseSurface * SurfaceStack::back(){ return _surfaces.back(); } -void SurfaceStack::onVerticesChanged(vector & vertices){ +void SurfaceStack::onVerticesChanged(vector & vertices){ ofNotifyEvent(verticesChangedEvent, vertices, this); } diff --git a/src/Surfaces/SurfaceStack.h b/src/Surfaces/SurfaceStack.h index 843dbcc..7607167 100644 --- a/src/Surfaces/SurfaceStack.h +++ b/src/Surfaces/SurfaceStack.h @@ -21,10 +21,10 @@ class SurfaceStack { BaseSurface * at(int i); BaseSurface * back(); - ofEvent > verticesChangedEvent; + ofEvent > verticesChangedEvent; ofEvent vertexChangedEvent; - void onVerticesChanged(vector & vertices); + void onVerticesChanged(vector & vertices); void onVertexChanged(int & i); vector & getSurfaces(){ return _surfaces; }; diff --git a/src/Surfaces/TriangleSurface.cpp b/src/Surfaces/TriangleSurface.cpp index eb7afe2..bf1c0a1 100644 --- a/src/Surfaces/TriangleSurface.cpp +++ b/src/Surfaces/TriangleSurface.cpp @@ -7,23 +7,22 @@ TriangleSurface::TriangleSurface(){ setup(); } -TriangleSurface::~TriangleSurface(){} - void TriangleSurface::setup(){ + // Create 3 points for the triangle - Vec2 p1 = Vec2(ofGetWidth() / 2.0f, 0); - Vec2 p2 = Vec2(Vec2(0, ofGetHeight())); - Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight()); + Vec3 p1 = Vec3((float)ofGetWidth() / 2.0f, 0.0f, 0.0f); + Vec3 p2 = Vec3(0.0f, (float)ofGetHeight(), 0.0f); + Vec3 p3 = Vec3((float)ofGetWidth(), (float)ofGetHeight(), 0.0f); // Create 3 point for the texture coordinates - Vec2 t1 = Vec2(0.5f, 0); - Vec2 t2 = Vec2(0, 1.0f); - Vec2 t3 = Vec2(1, 1.0f); + Vec2 t1 = Vec2(0.5f, 0.0f); + Vec2 t2 = Vec2(0.0f, 1.0f); + Vec2 t3 = Vec2(1.0f, 1.0f); setup(p1, p2, p3, t1, t2, t3, source); } -void TriangleSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1, +void TriangleSurface::setup(Vec3 p1, Vec3 p2, Vec3 p3, Vec2 t1, Vec2 t2, Vec2 t3, BaseSource * newSource){ // Assign texture source = newSource; @@ -63,18 +62,17 @@ void TriangleSurface::draw(){ } } -void TriangleSurface::setVertex(int index, Vec2 p){ +void TriangleSurface::setVertex(int index, Vec3 p){ if(index > 2){ ofLog() << "Vertex with this index does not exist: " << index << endl; return; } mesh.setVertex(index, p.toOf()); - ofVec3f v = mesh.getVertex(index); ofNotifyEvent(vertexChangedEvent, index, this); } -void TriangleSurface::setVertices(vector v){ +void TriangleSurface::setVertices(vector v){ if(v.size() != 3){ throw runtime_error("Wrong number of vertices"); } @@ -83,19 +81,8 @@ void TriangleSurface::setVertices(vector v){ mesh.setVertex(i, v[i].toOf()); } - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); -} - -void TriangleSurface::setVertices(vector v){ - if(v.size() != 3){ - throw runtime_error("Wrong number of vertices"); - } - - for(int i = 0; i < 3; ++i){ - mesh.setVertex(i, v[i]); - } - - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } void TriangleSurface::setTexCoord(int index, Vec2 t){ @@ -112,20 +99,20 @@ void TriangleSurface::setTexCoords(vector t){ if(t.size() != 3){ throw runtime_error("Wrong number of texture coordinates"); } + for(int i = 0; i < 3; ++i){ mesh.setTexCoord(i, t[i].toOf()); } } -void TriangleSurface::moveBy(Vec2 v){ - vector & vertices = getVertices(); - - for(int i = 0; i < vertices.size(); i++){ - vertices[i] += v.toOf(); +void TriangleSurface::moveBy(Vec3 v){ + for(auto i = 0; i < mesh.getVertices().size(); ++i){ + mesh.getVertices()[i] += v.toOf(); } setMoved(true); - ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); + vector vertices = Vec3::fromOf(mesh.getVertices()); + ofNotifyEvent(verticesChangedEvent, vertices, this); } int TriangleSurface::getType(){ @@ -133,9 +120,8 @@ int TriangleSurface::getType(){ } bool TriangleSurface::hitTest(Vec2 p){ - // Construct ofPolyline from vertices ofPolyline line = getHitArea(); - + if(line.inside(p.x, p.y)){ return true; }else{ @@ -149,12 +135,14 @@ Vec2 TriangleSurface::getVertex(int index){ throw runtime_error("Vertex index out of bounds."); } - ofVec3f vert = mesh.getVertex(index); - return Vec2(vert.x, vert.y); + return Vec2( + mesh.getVertex(index).x, + mesh.getVertex(index).y); } Vec2 TriangleSurface::getTexCoord(int index){ if(index > 2){ + ofLog() << "Texture coordinate with this index does not exist: " << index << endl; throw runtime_error("Texture coordinate index out of bounds."); } @@ -165,6 +153,7 @@ Vec2 TriangleSurface::getTexCoord(int index){ ofPolyline TriangleSurface::getHitArea(){ ofPolyline line; + line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); @@ -175,26 +164,25 @@ ofPolyline TriangleSurface::getHitArea(){ ofPolyline TriangleSurface::getTextureHitArea(){ ofPolyline line; - Vec2 textureSize = Vec2(source->getTexture()->getWidth(), source->getTexture()->getHeight()); + + Vec2 textureSize = Vec2( + source->getTexture()->getWidth(), + source->getTexture()->getHeight()); + for(int i = 0; i < mesh.getTexCoords().size(); i++){ line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf())); } + line.close(); - return line; } -vector & TriangleSurface::getVertices(){ - // return only joint vertices - return mesh.getVertices(); +vector TriangleSurface::getVertices(){ + return Vec3::fromOf(mesh.getVertices()); } -vector & TriangleSurface::getTexCoords(){ - _texCoords.clear(); - for(auto tc : mesh.getTexCoords()){ - _texCoords.push_back(tc); - } - return _texCoords; +vector TriangleSurface::getTexCoords(){ + return Vec2::fromOf(mesh.getTexCoords()); } BaseSurface * TriangleSurface::clone(){ diff --git a/src/Surfaces/TriangleSurface.h b/src/Surfaces/TriangleSurface.h index a358b66..9546e08 100644 --- a/src/Surfaces/TriangleSurface.h +++ b/src/Surfaces/TriangleSurface.h @@ -4,6 +4,7 @@ #include "BaseSurface.h" #include "SurfaceType.h" #include "Vec2.h" +#include "Vec3.h" namespace ofx { namespace piMapper { @@ -11,21 +12,18 @@ namespace piMapper { class TriangleSurface : public BaseSurface { public: TriangleSurface(); - ~TriangleSurface(); void setup(); - void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1, Vec2 t2, - Vec2 t3, BaseSource * newSource); + void setup( + Vec3 p1, Vec3 p2, Vec3 p3, + Vec2 t1, Vec2 t2, Vec2 t3, + BaseSource * newSource); void draw(); - - void setVertex(int index, Vec2 p); - void setVertices(vector v); - void setVertices(vector v); - + void setVertex(int index, Vec3 p); + void setVertices(vector v); void setTexCoord(int index, Vec2 t); void setTexCoords(vector t); - - void moveBy(Vec2 v); + void moveBy(Vec3 v); int getType(); bool hitTest(Vec2 p); @@ -33,8 +31,8 @@ class TriangleSurface : public BaseSurface { Vec2 getTexCoord(int index); ofPolyline getHitArea(); ofPolyline getTextureHitArea(); - vector & getVertices(); - vector & getTexCoords(); + vector getVertices(); + vector getTexCoords(); BaseSurface * clone(); }; diff --git a/src/Types/Vec2.cpp b/src/Types/Vec2.cpp index ee22e0c..35fb3da 100644 --- a/src/Types/Vec2.cpp +++ b/src/Types/Vec2.cpp @@ -4,13 +4,12 @@ namespace ofx { namespace piMapper { Vec2::Vec2(){ - x = 0.0f; - y = 0.0f; + Vec2(0.0f, 0.0f); } -Vec2::Vec2(float $x, float $y){ - x = $x; - y = $y; +Vec2::Vec2(float ix, float iy){ + x = ix; + y = iy; } #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 @@ -19,28 +18,27 @@ Vec2::Vec2(float $x, float $y){ y = src.y; } - Vec2::Vec2(ofVec3f & src){ - x = src.x; - y = src.y; - } - ofVec2f Vec2::toOf(){ return ofVec2f(x, y); } - - ofVec2f Vec2::toOf(Vec2 & src){ - return ofVec2f(src.x, src.y); - } vector Vec2::toOf(vector & src){ - vector dst; - for(auto v : src){ - dst.push_back(ofVec2f(v.x, v.y)); + vector retVal; + for(auto itm : src){ + retVal.push_back(itm.toOf()); } - return dst; + return retVal; } - float Vec2::distance(Vec2 & other){ + vector Vec2::fromOf(vector & src){ + vector retVal; + for(auto itm : src){ + retVal.push_back(Vec2(itm)); + } + return retVal; + } + + float Vec2::distance(const Vec2 & other){ ofVec2f v1(x, y); ofVec2f v2(other.x, other.y); return v1.distance(v2); @@ -54,41 +52,43 @@ void Vec2::operator=(const Vec2 & other){ y = other.y; } -void Vec2::operator=(const ofVec3f & other){ - x = other.x; - y = other.y; -} - -void Vec2::operator+=(Vec2 & other){ +void Vec2::operator+=(const Vec2 & other){ x += other.x; y += other.y; } -Vec2 Vec2::operator+(Vec2 & other){ +Vec2 Vec2::operator+(const Vec2 & other){ return Vec2(x + other.x, y + other.y); } -Vec2 Vec2::operator/(Vec2 & other){ - return Vec2(x / other.x, y / other.y); +Vec2 Vec2::operator-(){ + return Vec2(-x, -y); } -Vec2 Vec2::operator*(Vec2 & other){ - return Vec2(x * other.x, y * other.y); +Vec2 Vec2::operator-(const Vec2 & other){ + return Vec2(x - other.x, y - other.y); } -Vec2 Vec2::operator-(){ - return Vec2(-x, -y); +Vec2 Vec2::operator*(const Vec2 & other){ + return Vec2(x * other.x, y * other.y); } -Vec2 Vec2::operator-(Vec2 & other){ - return Vec2(x - other.x, y - other.y); +Vec2 Vec2::operator/(const Vec2 & other){ + return Vec2(x / other.x, y / other.y); } -bool Vec2::operator!=(Vec2 & other){ +bool Vec2::operator==(const Vec2 & other){ if(x == other.x && y == other.y){ - return false; + return true; + } + return false; +} + +bool Vec2::operator!=(const Vec2 & other){ + if(x != other.x && y != other.y){ + return true; } - return true; + return false; } } // namespace piMapper diff --git a/src/Types/Vec2.h b/src/Types/Vec2.h index e5c732c..e0414f6 100644 --- a/src/Types/Vec2.h +++ b/src/Types/Vec2.h @@ -1,45 +1,40 @@ #pragma once -#include "ofMain.h" - #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 -// ... + #include "ofVec2f.h" #else -// TODO: include glm + // TODO: include glm #endif namespace ofx { namespace piMapper { -//#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 class Vec2{ public: Vec2(); - Vec2(float $x, float $y); + Vec2(float ix, float iy); + // TODO: Achieve this with templates #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 Vec2(ofVec2f & src); - Vec2(ofVec3f & src); ofVec2f toOf(); - static ofVec2f toOf(Vec2 & src); static vector toOf(vector & src); - float distance(Vec2 & other); + static vector fromOf(vector & src); #else - // TODO: The same for glm::vec2 - // static vector toOf(vector & src); + // TODO: glm #endif - void operator=(const Vec2 & other); - void operator=(const ofVec3f & other); - void operator+=(Vec2 & other); + float distance(const Vec2 & other); - Vec2 operator+(Vec2 & other); - Vec2 operator/(Vec2 & other); - Vec2 operator*(Vec2 & other); + void operator=(const Vec2 & other); + void operator+=(const Vec2 & other); + Vec2 operator+(const Vec2 & other); Vec2 operator-(); - Vec2 operator-(Vec2 & other); - - bool operator!=(Vec2 & other); + Vec2 operator-(const Vec2 & other); + Vec2 operator*(const Vec2 & other); + Vec2 operator/(const Vec2 & other); + bool operator==(const Vec2 & other); + bool operator!=(const Vec2 & other); float x; float y; diff --git a/src/Types/Vec3.cpp b/src/Types/Vec3.cpp index 400b918..e3304b7 100644 --- a/src/Types/Vec3.cpp +++ b/src/Types/Vec3.cpp @@ -4,15 +4,13 @@ namespace ofx { namespace piMapper { Vec3::Vec3(){ - x = 0.0f; - y = 0.0f; - z = 0.0f; + Vec3(0.0f, 0.0f, 0.0f); } -Vec3::Vec3(float $x, float $y, float $z){ - x = $x; - y = $y; - z = $z; +Vec3::Vec3(float ix, float iy, float iz){ + x = ix; + y = iy; + z = iz; } #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 @@ -23,22 +21,26 @@ Vec3::Vec3(float $x, float $y, float $z){ } ofVec3f Vec3::toOf(){ - ofVec3f(x, y, z); + return ofVec3f(x, y, z); } - ofVec3f toOf(Vec3 & src){ - return ofVec3f(src.x, src.y, src.z); + vector Vec3::toOf(vector & src){ + vector retVal; + for(auto itm : src){ + retVal.push_back(itm.toOf()); + } + return retVal; } - - vector toOf(vector & src){ - vector dst; - for(auto v : src){ - dst.push_back(ofVec3f(v.x, v.y, v.z)); + + vector Vec3::fromOf(vector & src){ + vector retVal; + for(auto itm : src){ + retVal.push_back(Vec3(itm)); } - return dst; + return retVal; } #else - // TODO: The same for glm::vec2 + // TODO: Vec3::Vec3(glm::vec3 & src){...} #endif void Vec3::operator=(const Vec3 & other){ @@ -47,35 +49,76 @@ void Vec3::operator=(const Vec3 & other){ z = other.z; } -void Vec3::operator=(const ofVec3f & other){ - x = other.x; - y = other.y; - z = other.z; +void Vec3::operator+=(const Vec3 & other){ + x += other.x; + y += other.y; + z += other.z; } -Vec3 Vec3::operator+(Vec3 & other){ - return Vec3( - x + other.x, - y + other.y, - z + other.z); +void Vec3::operator*=(const Vec3 & other){ + x *= other.x; + y *= other.y; + z *= other.z; +} + +void Vec3::operator*=(float n){ + x *= n; + y *= n; + z *= n; +} + +void Vec3::operator/=(const Vec3 & other){ + x /= other.x; + y /= other.y; + z /= other.z; +} + +void Vec3::operator/=(float n){ + x /= n; + y /= n; + z /= n; +} + +Vec3 Vec3::operator+(const Vec3 & other){ + return Vec3(x + other.x, y + other.y, z + other.z); } Vec3 Vec3::operator-(){ return Vec3(-x, -y, -z); } -Vec3 Vec3::operator-(Vec3 & other){ - return Vec3( - x - other.x, - y - other.y, - z - other.z); +Vec3 Vec3::operator-(const Vec3 & other){ + return Vec3(x - other.x, y - other.y, z - other.z); +} + +Vec3 Vec3::operator*(const Vec3 & other){ + return Vec3(x * other.x, y * other.y, z * other.z); +} + +Vec3 Vec3::operator*(float n){ + return Vec3(x * n, y * n, z * n); +} + +Vec3 Vec3::operator/(const Vec3 & other){ + return Vec3(x / other.x, y / other.y, z / other.z); +} + +Vec3 Vec3::operator/(float n){ + return Vec3(x / n, y / n, z / n); } -bool Vec3::operator!=(Vec3 & other){ +bool Vec3::operator==(const Vec3 & other){ if(x == other.x && y == other.y && z == other.z){ - return false; + return true; + } + return false; +} + +bool Vec3::operator!=(const Vec3 & other){ + if(x != other.x && y != other.y && z != other.z){ + return true; } - return true; + return false; } } // namespace piMapper diff --git a/src/Types/Vec3.h b/src/Types/Vec3.h index f9fcda6..c9df2d7 100644 --- a/src/Types/Vec3.h +++ b/src/Types/Vec3.h @@ -1,9 +1,9 @@ #pragma once #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 -#include "ofMain.h" + #include "ofVec3f.h" #else -// TODO: include glm + // TODO: include glm #endif namespace ofx { @@ -12,27 +12,33 @@ namespace piMapper { class Vec3{ public: Vec3(); - Vec3(float $x, float $y, float $z); - + Vec3(float ix, float iy, float iz); + + // TODO: achieve this with templates #if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 Vec3(ofVec3f & src); ofVec3f toOf(); - static ofVec3f toOf(Vec3 & src); static vector toOf(vector & src); + static vector fromOf(vector & src); #else - // TODO: The same for glm::vec2 - // static vector toOf(vector & src); + // TODO: Vec3(glm::vec3 & src); #endif void operator=(const Vec3 & other); - void operator=(const ofVec3f & other); - - Vec3 operator+(Vec3 & other); - + void operator+=(const Vec3 & other); + void operator*=(const Vec3 & other); + void operator*=(float n); + void operator/=(const Vec3 & other); + void operator/=(float n); + Vec3 operator+(const Vec3 & other); Vec3 operator-(); - Vec3 operator-(Vec3 & other); - - bool operator!=(Vec3 & other); + Vec3 operator-(const Vec3 & other); + Vec3 operator*(const Vec3 & other); + Vec3 operator*(float n); + Vec3 operator/(const Vec3 & other); + Vec3 operator/(float n); + bool operator==(const Vec3 & other); + bool operator!=(const Vec3 & other); float x; float y; diff --git a/src/ofxPiMapper.cpp b/src/ofxPiMapper.cpp index fa0dba1..dfe47dc 100644 --- a/src/ofxPiMapper.cpp +++ b/src/ofxPiMapper.cpp @@ -147,7 +147,7 @@ void ofxPiMapper::togglePause(){ _application.togglePause(); } -void ofxPiMapper::moveSelection(ofx::piMapper::Vec2 by){ +void ofxPiMapper::moveSelection(ofx::piMapper::Vec3 by){ _application.moveSelection(by); } diff --git a/src/ofxPiMapper.h b/src/ofxPiMapper.h index dd5ec43..1b036d1 100644 --- a/src/ofxPiMapper.h +++ b/src/ofxPiMapper.h @@ -7,6 +7,7 @@ #include "SurfaceType.h" #include "Mode.h" #include "Vec2.h" +#include "Vec3.h" class ofxPiMapper { public: @@ -67,7 +68,7 @@ class ofxPiMapper { void scaleDown(); void togglePauseForSurface(unsigned int i); void togglePause(); - void moveSelection(ofx::piMapper::Vec2 by); + void moveSelection(ofx::piMapper::Vec3 by); void createSurface(ofx::piMapper::SurfaceType type); void eraseSurface(int i);