Browse Source

Add Vec2 adapter class, Vec3 still to finish

master
Krisjanis Rijnieks 8 years ago
parent
commit
5e23b21eb2
  1. 4
      src/Application/Application.cpp
  2. 5
      src/Application/Application.h
  3. 26
      src/Application/Modes/ProjectionMappingMode.cpp
  4. 3
      src/Application/Modes/ProjectionMappingMode.h
  5. 19
      src/Application/Modes/TextureMappingMode.cpp
  6. 5
      src/Application/Modes/TextureMappingMode.h
  7. 56
      src/Application/SettingsLoader.cpp
  8. 1
      src/Application/SettingsLoader.h
  9. 4
      src/Commands/AddGridColCmd.cpp
  10. 3
      src/Commands/AddGridColCmd.h
  11. 4
      src/Commands/AddGridRowCmd.cpp
  12. 3
      src/Commands/AddGridRowCmd.h
  13. 2
      src/Commands/DuplicateSurfaceCmd.cpp
  14. 1
      src/Commands/DuplicateSurfaceCmd.h
  15. 2
      src/Commands/MvAllTexCoordsCmd.cpp
  16. 3
      src/Commands/MvAllTexCoordsCmd.h
  17. 2
      src/Commands/MvSelectionCmd.cpp
  18. 5
      src/Commands/MvSelectionCmd.h
  19. 3
      src/Commands/MvSurfaceVertCmd.h
  20. 2
      src/Commands/MvTexCoordCmd.cpp
  21. 7
      src/Commands/MvTexCoordCmd.h
  22. 4
      src/Commands/RmGridColCmd.cpp
  23. 3
      src/Commands/RmGridColCmd.h
  24. 4
      src/Commands/RmGridRowCmd.cpp
  25. 3
      src/Commands/RmGridRowCmd.h
  26. 2
      src/Commands/SaveTexCoordPosCmd.cpp
  27. 5
      src/Commands/SaveTexCoordPosCmd.h
  28. 3
      src/Commands/StartDragSurfaceCmd.cpp
  29. 1
      src/Commands/StartDragSurfaceCmd.h
  30. 19
      src/Gui/Widgets/ProjectionEditorWidget.cpp
  31. 7
      src/Gui/Widgets/ProjectionEditorWidget.h
  32. 54
      src/Gui/Widgets/TextureEditorWidget.cpp
  33. 11
      src/Gui/Widgets/TextureEditorWidget.h
  34. 30
      src/Surfaces/BaseSurface.cpp
  35. 21
      src/Surfaces/BaseSurface.h
  36. 44
      src/Surfaces/CircleSurface.cpp
  37. 4
      src/Surfaces/CircleSurface.h
  38. 54
      src/Surfaces/GridWarpSurface.cpp
  39. 19
      src/Surfaces/GridWarpSurface.h
  40. 92
      src/Surfaces/HexagonSurface.cpp
  41. 25
      src/Surfaces/HexagonSurface.h
  42. 653
      src/Surfaces/QuadSurface.cpp
  43. 111
      src/Surfaces/QuadSurface.h
  44. 36
      src/Surfaces/SurfaceFactory.cpp
  45. 6
      src/Surfaces/SurfaceManager.cpp
  46. 7
      src/Surfaces/SurfaceManager.h
  47. 77
      src/Surfaces/TriangleSurface.cpp
  48. 25
      src/Surfaces/TriangleSurface.h
  49. 95
      src/Types/Vec2.cpp
  50. 49
      src/Types/Vec2.h
  51. 82
      src/Types/Vec3.cpp
  52. 43
      src/Types/Vec3.h
  53. 15
      src/UserInterface/BaseJoint.cpp
  54. 9
      src/UserInterface/BaseJoint.h
  55. 2
      src/UserInterface/CircleJoint.cpp
  56. 5
      src/UserInterface/CircleJoint.h
  57. 2
      src/ofxPiMapper.cpp
  58. 3
      src/ofxPiMapper.h

4
src/Application/Application.cpp

@ -356,7 +356,7 @@ void Application::selectPrevTexCoord(){
} }
} }
void Application::moveSelection(ofVec2f by){ void Application::moveSelection(Vec2 by){
if(_state == ProjectionMappingMode::instance()){ if(_state == ProjectionMappingMode::instance()){
getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by)); getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by));
}else if(_state == TextureMappingMode::instance()){ }else if(_state == TextureMappingMode::instance()){
@ -541,7 +541,7 @@ void Application::togglePause(){
} }
} }
void Application::moveTexCoord(int texCoordIndex, ofVec2f by){ void Application::moveTexCoord(int texCoordIndex, Vec2 by){
if(texCoordIndex >= 0){ if(texCoordIndex >= 0){
getCmdManager()->exec(new MvTexCoordCmd(texCoordIndex, by)); getCmdManager()->exec(new MvTexCoordCmd(texCoordIndex, by));
}else{ }else{

5
src/Application/Application.h

@ -9,6 +9,7 @@
#include "Info.h" #include "Info.h"
#include "SurfaceStack.h" #include "SurfaceStack.h"
#include "Gui.h" #include "Gui.h"
#include "Vec2.h"
// Commands // Commands
#include "SetApplicationModeCmd.h" #include "SetApplicationModeCmd.h"
@ -113,7 +114,7 @@ class Application {
Moves vertex when in projection mapping mode. Moves vertex when in projection mapping mode.
Moves texture coordinate when in texture mapping mode. Moves texture coordinate when in texture mapping mode.
*/ */
void moveSelection(ofVec2f by); void moveSelection(Vec2 by);
void setPresentationMode(); void setPresentationMode();
void setTextureMode(); void setTextureMode();
@ -131,7 +132,7 @@ class Application {
void removeGridRow(); void removeGridRow();
void removeGridColumn(); void removeGridColumn();
void togglePause(); void togglePause();
void moveTexCoord(int texCoordIndex, ofVec2f by); void moveTexCoord(int texCoordIndex, Vec2 by);
// TODO: Add moveVertex. // TODO: Add moveVertex.
// Make it so that other parts of the application react to the change. // Make it so that other parts of the application react to the change.
void undo(); void undo();

26
src/Application/Modes/ProjectionMappingMode.cpp

@ -114,33 +114,33 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg
case OF_KEY_UP: case OF_KEY_UP:
if(app->isShiftKeyDown()){ if(app->isShiftKeyDown()){
app->moveSelection(ofVec2f(0.0f, -10.0f)); app->moveSelection(Vec2(0.0f, -10.0f));
}else{ }else{
app->moveSelection(ofVec2f(0.0f, -1.0f)); app->moveSelection(Vec2(0.0f, -1.0f));
} }
break; break;
case OF_KEY_DOWN: case OF_KEY_DOWN:
if(app->isShiftKeyDown()){ if(app->isShiftKeyDown()){
app->moveSelection(ofVec2f(0.0f, 10.0f)); app->moveSelection(Vec2(0.0f, 10.0f));
}else{ }else{
app->moveSelection(ofVec2f(0.0f, 1.0f)); app->moveSelection(Vec2(0.0f, 1.0f));
} }
break; break;
case OF_KEY_LEFT: case OF_KEY_LEFT:
if(app->isShiftKeyDown()){ if(app->isShiftKeyDown()){
app->moveSelection(ofVec2f(-10.0f, 0.0f)); app->moveSelection(Vec2(-10.0f, 0.0f));
}else{ }else{
app->moveSelection(ofVec2f(-1.0f, 0.0f)); app->moveSelection(Vec2(-1.0f, 0.0f));
} }
break; break;
case OF_KEY_RIGHT: case OF_KEY_RIGHT:
if(app->isShiftKeyDown()){ if(app->isShiftKeyDown()){
app->moveSelection(ofVec2f(10.0f, 0.0f)); app->moveSelection(Vec2(10.0f, 0.0f));
}else{ }else{
app->moveSelection(ofVec2f(1.0f, 0.0f)); app->moveSelection(Vec2(1.0f, 0.0f));
} }
break; break;
@ -194,7 +194,7 @@ void ProjectionMappingMode::onMousePressed(Application * app, ofMouseEventArgs &
int hitJointIndex = -1; int hitJointIndex = -1;
BaseSurface * hitSurface = 0; BaseSurface * hitSurface = 0;
hitJoint = Gui::instance()->getProjectionEditorWidget().hitTestJoints(ofVec2f(args.x, args.y)); hitJoint = Gui::instance()->getProjectionEditorWidget().hitTestJoints(Vec2(args.x, args.y));
if(hitJoint){ if(hitJoint){
for(int i = Gui::instance()->getProjectionEditorWidget().getJoints()->size() - 1; i >= 0 ; --i){ for(int i = Gui::instance()->getProjectionEditorWidget().getJoints()->size() - 1; i >= 0 ; --i){
@ -205,7 +205,7 @@ void ProjectionMappingMode::onMousePressed(Application * app, ofMouseEventArgs &
} }
}else{ }else{
for(int i = app->getSurfaceManager()->size() - 1; i >= 0; --i){ for(int i = app->getSurfaceManager()->size() - 1; i >= 0; --i){
if(app->getSurfaceManager()->getSurface(i)->hitTest(ofVec2f(args.x, args.y))){ if(app->getSurfaceManager()->getSurface(i)->hitTest(Vec2(args.x, args.y))){
hitSurface = app->getSurfaceManager()->getSurface(i); hitSurface = app->getSurfaceManager()->getSurface(i);
break; break;
} }
@ -219,7 +219,7 @@ void ProjectionMappingMode::onMousePressed(Application * app, ofMouseEventArgs &
hitJoint->startDrag(); hitJoint->startDrag();
Gui::instance()->notifyJointPressed(args, hitJointIndex); Gui::instance()->notifyJointPressed(args, hitJointIndex);
}else if(hitSurface){ }else if(hitSurface){
_clickPosition = ofVec2f(args.x, args.y); // TODO: redesign this so we can use a kind of _clickPosition = Vec2(args.x, args.y); // TODO: redesign this so we can use a kind of
// display stack. // display stack.
_bSurfaceDrag = true; // TODO: Should be something like `hitSurface->startDrag()` _bSurfaceDrag = true; // TODO: Should be something like `hitSurface->startDrag()`
Gui::instance()->notifySurfacePressed(args, hitSurface); Gui::instance()->notifySurfacePressed(args, hitSurface);
@ -240,8 +240,8 @@ void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs &
// TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally. // TODO: Handle app->getGui()->clickPosition and app->getGui()->bDrag locally.
if(_bSurfaceDrag){ if(_bSurfaceDrag){
ofVec2f mousePosition = ofVec2f(args.x, args.y); Vec2 mousePosition = Vec2(args.x, args.y);
ofVec2f distance = mousePosition - _clickPosition; Vec2 distance = mousePosition - _clickPosition;
Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance); Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance);
_clickPosition = mousePosition; _clickPosition = mousePosition;
} }

3
src/Application/Modes/ProjectionMappingMode.h

@ -9,6 +9,7 @@
#include "SurfaceType.h" #include "SurfaceType.h"
#include "Gui.h" #include "Gui.h"
#include "ScaleWidget.h" #include "ScaleWidget.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -38,7 +39,7 @@ class ProjectionMappingMode : public ApplicationBaseMode {
float _surfaceScaleBeforeTransform; float _surfaceScaleBeforeTransform;
ofVec2f _clickPosition; Vec2 _clickPosition;
bool _bSurfaceDrag; bool _bSurfaceDrag;
bool _bDrawLayerPanel; bool _bDrawLayerPanel;

19
src/Application/Modes/TextureMappingMode.cpp

@ -85,19 +85,19 @@ void TextureMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & args){
switch(args.key){ switch(args.key){
case OF_KEY_LEFT: case OF_KEY_LEFT:
moveSelectedTexCoord(app, ofVec2f(-moveStep, 0.0f)); moveSelectedTexCoord(app, Vec2(-moveStep, 0.0f));
break; break;
case OF_KEY_RIGHT: case OF_KEY_RIGHT:
moveSelectedTexCoord(app, ofVec2f(moveStep, 0.0f)); moveSelectedTexCoord(app, Vec2(moveStep, 0.0f));
break; break;
case OF_KEY_UP: case OF_KEY_UP:
moveSelectedTexCoord(app, ofVec2f(0.0f, -moveStep)); moveSelectedTexCoord(app, Vec2(0.0f, -moveStep));
break; break;
case OF_KEY_DOWN: case OF_KEY_DOWN:
moveSelectedTexCoord(app, ofVec2f(0.0f, moveStep)); moveSelectedTexCoord(app, Vec2(0.0f, moveStep));
break; break;
case '>': case '>':
@ -159,7 +159,7 @@ void TextureMappingMode::onMousePressed(Application * app, ofMouseEventArgs & ar
CircleJoint * hitJoint = CircleJoint * hitJoint =
Gui::instance()->getTextureEditorWidget().hitTestJoints( Gui::instance()->getTextureEditorWidget().hitTestJoints(
ofVec2f(args.x, args.y)); Vec2(args.x, args.y));
if(hitJoint != 0){ if(hitJoint != 0){
hitJoint->mousePressed(args); hitJoint->mousePressed(args);
@ -220,7 +220,7 @@ void TextureMappingMode::onMouseReleased(Application * app, ofMouseEventArgs & a
// create an undoable move tex coord command. // create an undoable move tex coord command.
int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord(); int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord();
if(selectedTexCoord >= 0){ if(selectedTexCoord >= 0){
ofVec2f texCoordCurrent = Vec2 texCoordCurrent =
app->getSurfaceManager()->getSelectedSurface()->getTexCoords()[selectedTexCoord]; app->getSurfaceManager()->getSelectedSurface()->getTexCoords()[selectedTexCoord];
if(texCoordCurrent != _texCoordOnClick){ if(texCoordCurrent != _texCoordOnClick){
@ -247,7 +247,8 @@ void TextureMappingMode::onMouseDragged(Application * app, ofMouseEventArgs & ar
if(_bCropAreaDrag){ if(_bCropAreaDrag){
ofPoint mousePosition = ofPoint(args.x, args.y); ofPoint mousePosition = ofPoint(args.x, args.y);
ofPoint distance = mousePosition - _clickPosition; ofPoint distance = mousePosition - _clickPosition;
Gui::instance()->getTextureEditorWidget().moveTexCoords(distance); Vec2 d = Vec2(distance.x, distance.y);
Gui::instance()->getTextureEditorWidget().moveTexCoords(d);
_clickPosition = mousePosition; _clickPosition = mousePosition;
} }
}else{ }else{
@ -263,7 +264,7 @@ void TextureMappingMode::drawTexture(Application * app){
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); app->getSurfaceManager()->getSelectedSurface()->drawTexture(Vec2(0, 0));
if(!normalizedTexCoords){ if(!normalizedTexCoords){
ofDisableNormalizedTexCoords(); ofDisableNormalizedTexCoords();
@ -271,7 +272,7 @@ void TextureMappingMode::drawTexture(Application * app){
} }
} }
void TextureMappingMode::moveSelectedTexCoord(Application * app, ofVec2f by){ void TextureMappingMode::moveSelectedTexCoord(Application * app, Vec2 by){
if(app->getSurfaceManager()->getSelectedSurface() != 0){ if(app->getSurfaceManager()->getSelectedSurface() != 0){
int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord(); int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord();
app->moveTexCoord(selectedTexCoord, by); app->moveTexCoord(selectedTexCoord, by);

5
src/Application/Modes/TextureMappingMode.h

@ -13,6 +13,7 @@
#include "SaveTexCoordPosCmd.h" #include "SaveTexCoordPosCmd.h"
#include "SelTexCoordCmd.h" #include "SelTexCoordCmd.h"
#include "Gui.h" #include "Gui.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -34,7 +35,7 @@ class TextureMappingMode : public ApplicationBaseMode {
void onGuiEvent(Application * app, GuiEvent & e){} void onGuiEvent(Application * app, GuiEvent & e){}
void drawTexture(Application * app); void drawTexture(Application * app);
void moveSelectedTexCoord(Application * app, ofVec2f by); void moveSelectedTexCoord(Application * app, Vec2 by);
void selectNextVertex(Application * app); void selectNextVertex(Application * app);
void selectPrevVertex(Application * app); void selectPrevVertex(Application * app);
@ -62,7 +63,7 @@ class TextureMappingMode : public ApplicationBaseMode {
ofPoint _prevCanvasTranslate; ofPoint _prevCanvasTranslate;
ofPoint _clickCanvasTranslate; ofPoint _clickCanvasTranslate;
ofVec2f _texCoordOnClick; Vec2 _texCoordOnClick;
}; };

56
src/Application/SettingsLoader.cpp

@ -194,11 +194,11 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->addTag("texCoords"); xmlSettings->addTag("texCoords");
xmlSettings->pushTag("texCoords"); xmlSettings->pushTag("texCoords");
vector <ofVec2f> * texCoords = &surface->getTexCoords(); vector <Vec2> * texCoords = &surface->getTexCoords();
for(int j = 0; j < texCoords->size(); j++){ for(int j = 0; j < texCoords->size(); j++){
xmlSettings->addTag("texCoord"); xmlSettings->addTag("texCoord");
xmlSettings->pushTag("texCoord", j); xmlSettings->pushTag("texCoord", j);
ofVec2f * texCoord = &(*texCoords)[j]; Vec2 * texCoord = &(*texCoords)[j];
xmlSettings->addValue("x", texCoord->x); xmlSettings->addValue("x", texCoord->x);
xmlSettings->addValue("y", texCoord->y); xmlSettings->addValue("y", texCoord->y);
xmlSettings->popTag(); // texCoord xmlSettings->popTag(); // texCoord
@ -252,28 +252,28 @@ bool SettingsLoader::create(string fileName){
} }
BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices; vector <Vec2> vertices;
if(xmlSettings->tagExists("vertices")){ if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices"); xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){ if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0); xmlSettings->pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("vertex", 1)){ if(xmlSettings->tagExists("vertex", 1)){
xmlSettings->pushTag("vertex", 1); xmlSettings->pushTag("vertex", 1);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("vertex", 2)){ if(xmlSettings->tagExists("vertex", 2)){
xmlSettings->pushTag("vertex", 2); xmlSettings->pushTag("vertex", 2);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f))); xmlSettings->getValue("y", 100.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
@ -281,28 +281,28 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices xmlSettings->popTag(); // vertices
} }
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
if(xmlSettings->tagExists("texCoords")){ if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords"); xmlSettings->pushTag("texCoords");
if(xmlSettings->tagExists("texCoord", 0)){ if(xmlSettings->tagExists("texCoord", 0)){
xmlSettings->pushTag("texCoord", 0); xmlSettings->pushTag("texCoord", 0);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("texCoord", 1)){ if(xmlSettings->tagExists("texCoord", 1)){
xmlSettings->pushTag("texCoord", 1); xmlSettings->pushTag("texCoord", 1);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 1.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("texCoord", 2)){ if(xmlSettings->tagExists("texCoord", 2)){
xmlSettings->pushTag("texCoord", 2); xmlSettings->pushTag("texCoord", 2);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 1.0f))); xmlSettings->getValue("y", 1.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
@ -321,35 +321,35 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
} }
BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices; vector <Vec2> vertices;
if(xmlSettings->tagExists("vertices")){ if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices"); xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){ if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0); xmlSettings->pushTag("vertex", 0);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("vertex", 1)){ if(xmlSettings->tagExists("vertex", 1)){
xmlSettings->pushTag("vertex", 1); xmlSettings->pushTag("vertex", 1);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("vertex", 2)){ if(xmlSettings->tagExists("vertex", 2)){
xmlSettings->pushTag("vertex", 2); xmlSettings->pushTag("vertex", 2);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 100.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 100.0f))); xmlSettings->getValue("y", 100.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("vertex", 3)){ if(xmlSettings->tagExists("vertex", 3)){
xmlSettings->pushTag("vertex", 3); xmlSettings->pushTag("vertex", 3);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f))); xmlSettings->getValue("y", 100.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
@ -357,35 +357,35 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices xmlSettings->popTag(); // vertices
} }
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
if(xmlSettings->tagExists("texCoords")){ if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords"); xmlSettings->pushTag("texCoords");
if(xmlSettings->tagExists("texCoord", 0)){ if(xmlSettings->tagExists("texCoord", 0)){
xmlSettings->pushTag("texCoord", 0); xmlSettings->pushTag("texCoord", 0);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("texCoord", 1)){ if(xmlSettings->tagExists("texCoord", 1)){
xmlSettings->pushTag("texCoord", 1); xmlSettings->pushTag("texCoord", 1);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 1.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("texCoord", 2)){ if(xmlSettings->tagExists("texCoord", 2)){
xmlSettings->pushTag("texCoord", 2); xmlSettings->pushTag("texCoord", 2);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 1.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 1.0f),
xmlSettings->getValue("y", 1.0f))); xmlSettings->getValue("y", 1.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
if(xmlSettings->tagExists("texCoord", 3)){ if(xmlSettings->tagExists("texCoord", 3)){
xmlSettings->pushTag("texCoord", 3); xmlSettings->pushTag("texCoord", 3);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 1.0f))); xmlSettings->getValue("y", 1.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
} }
@ -415,7 +415,7 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
} }
BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices; vector <Vec2> vertices;
if(xmlSettings->tagExists("vertices")){ if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices"); xmlSettings->pushTag("vertices");
@ -424,7 +424,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
while(xmlSettings->tagExists("vertex", iv)){ while(xmlSettings->tagExists("vertex", iv)){
xmlSettings->pushTag("vertex", iv); xmlSettings->pushTag("vertex", iv);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
++iv; ++iv;
@ -433,7 +433,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices xmlSettings->popTag(); // vertices
} }
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
if(xmlSettings->tagExists("texCoords")){ if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords"); xmlSettings->pushTag("texCoords");
@ -442,7 +442,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
while(xmlSettings->tagExists("texCoord", it)){ while(xmlSettings->tagExists("texCoord", it)){
xmlSettings->pushTag("texCoord", it); xmlSettings->pushTag("texCoord", it);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); xmlSettings->popTag();
++it; ++it;
@ -476,7 +476,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
} }
BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
vector <ofVec2f> vertices; vector <Vec2> vertices;
if(xmlSettings->tagExists("vertices")){ if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices"); xmlSettings->pushTag("vertices");
@ -484,7 +484,7 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
unsigned int v = 0; unsigned int v = 0;
while(xmlSettings->tagExists("vertex", v)){ while(xmlSettings->tagExists("vertex", v)){
xmlSettings->pushTag("vertex", v); xmlSettings->pushTag("vertex", v);
vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); // vertex xmlSettings->popTag(); // vertex
v += 1; v += 1;
@ -493,7 +493,7 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
xmlSettings->popTag(); // vertices xmlSettings->popTag(); // vertices
} }
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
if(xmlSettings->tagExists("texCoords")){ if(xmlSettings->tagExists("texCoords")){
xmlSettings->pushTag("texCoords"); xmlSettings->pushTag("texCoords");
@ -501,7 +501,7 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
unsigned int t = 0; unsigned int t = 0;
while(xmlSettings->tagExists("texCoord", t)){ while(xmlSettings->tagExists("texCoord", t)){
xmlSettings->pushTag("texCoord", t); xmlSettings->pushTag("texCoord", t);
texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), texCoords.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f))); xmlSettings->getValue("y", 0.0f)));
xmlSettings->popTag(); // texCoord xmlSettings->popTag(); // texCoord
t += 1; t += 1;

1
src/Application/SettingsLoader.h

@ -8,6 +8,7 @@
#include "SurfaceFactory.h" #include "SurfaceFactory.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "SourceTypeHelper.h" #include "SourceTypeHelper.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {

4
src/Commands/AddGridColCmd.cpp

@ -18,9 +18,9 @@ void AddGridColCmd::exec(){
void AddGridColCmd::undo(){ void AddGridColCmd::undo(){
ofLogNotice("AddGridColCmd", "undo"); ofLogNotice("AddGridColCmd", "undo");
_surface->setGridCols(_surface->getGridCols() - 1); _surface->setGridCols(_surface->getGridCols() - 1);
vector <ofVec2f> v; vector <Vec2> v;
for(int i = 0; i < _vertices.size(); ++i){ for(int i = 0; i < _vertices.size(); ++i){
v.push_back( ofVec2f(_vertices[i].x, _vertices[i].y) ); v.push_back( Vec2(_vertices[i].x, _vertices[i].y) );
} }
_surface->setVertices(v); _surface->setVertices(v);
_surface->setTexCoords(_texCoords); _surface->setTexCoords(_texCoords);

3
src/Commands/AddGridColCmd.h

@ -4,6 +4,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "GridWarpSurface.h" #include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h" #include "ProjectionEditorWidget.h"
#include "Vec2.h"
class ofxPiMapper; class ofxPiMapper;
@ -19,7 +20,7 @@ class AddGridColCmd : public BaseUndoCmd {
private: private:
vector <ofVec3f> _vertices; vector <ofVec3f> _vertices;
vector <ofVec2f> _texCoords; vector <Vec2> _texCoords;
GridWarpSurface * _surface; GridWarpSurface * _surface;
}; };

4
src/Commands/AddGridRowCmd.cpp

@ -18,9 +18,9 @@ void AddGridRowCmd::exec(){
void AddGridRowCmd::undo(){ void AddGridRowCmd::undo(){
ofLogNotice("AddGridRowCmd", "undo"); ofLogNotice("AddGridRowCmd", "undo");
_surface->setGridRows(_surface->getGridRows() - 1); _surface->setGridRows(_surface->getGridRows() - 1);
vector <ofVec2f> v; vector <Vec2> v;
for(int i = 0; i < _vertices.size(); ++i){ for(int i = 0; i < _vertices.size(); ++i){
v.push_back( ofVec2f(_vertices[i].x, _vertices[i].y) ); v.push_back( Vec2(_vertices[i].x, _vertices[i].y) );
} }
_surface->setVertices(v); _surface->setVertices(v);
_surface->setTexCoords(_texCoords); _surface->setTexCoords(_texCoords);

3
src/Commands/AddGridRowCmd.h

@ -4,6 +4,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "GridWarpSurface.h" #include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h" #include "ProjectionEditorWidget.h"
#include "Vec2.h"
class ofxPiMapper; class ofxPiMapper;
@ -19,7 +20,7 @@ class AddGridRowCmd : public BaseUndoCmd {
private: private:
vector <ofVec3f> _vertices; vector <ofVec3f> _vertices;
vector <ofVec2f> _texCoords; vector <Vec2> _texCoords;
GridWarpSurface * _surface; GridWarpSurface * _surface;
}; };

2
src/Commands/DuplicateSurfaceCmd.cpp

@ -12,7 +12,7 @@ void DuplicateSurfaceCmd::exec(){
ofLogNotice("DuplicateSurfaceCmd", "exec"); ofLogNotice("DuplicateSurfaceCmd", "exec");
_duplicate = _surface->clone(); _duplicate = _surface->clone();
_surfaceManager->addSurface(_duplicate); _surfaceManager->addSurface(_duplicate);
_duplicate->moveBy(ofVec2f(10.0f, 10.0f)); _duplicate->moveBy(Vec2(10.0f, 10.0f));
_surfaceManager->selectSurface(_duplicate); _surfaceManager->selectSurface(_duplicate);
} }

1
src/Commands/DuplicateSurfaceCmd.h

@ -7,6 +7,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {

2
src/Commands/MvAllTexCoordsCmd.cpp

@ -15,7 +15,7 @@ void MvAllTexCoordsCmd::exec(){
void MvAllTexCoordsCmd::undo(){ void MvAllTexCoordsCmd::undo(){
ofLogNotice("MvAllTexCoordsCmd", "undo"); ofLogNotice("MvAllTexCoordsCmd", "undo");
ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0]; Vec2 dist = _texCoords[0] - _surface->getTexCoords()[0];
dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x; dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x;
dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y; dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y;
_texEditor->moveTexCoords(dist); _texEditor->moveTexCoords(dist);

3
src/Commands/MvAllTexCoordsCmd.h

@ -7,6 +7,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "TextureEditorWidget.h" #include "TextureEditorWidget.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -19,7 +20,7 @@ class MvAllTexCoordsCmd : public BaseUndoCmd {
void undo(); void undo();
private: private:
vector <ofVec2f> _texCoords; vector <Vec2> _texCoords;
BaseSurface * _surface; BaseSurface * _surface;
TextureEditorWidget * _texEditor; TextureEditorWidget * _texEditor;

2
src/Commands/MvSelectionCmd.cpp

@ -3,7 +3,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
MvSelectionCmd::MvSelectionCmd(SurfaceManager * sm, ofVec2f moveBy){ MvSelectionCmd::MvSelectionCmd(SurfaceManager * sm, Vec2 moveBy){
_surfaceManager = sm; _surfaceManager = sm;
_movedBy = moveBy; _movedBy = moveBy;
} }

5
src/Commands/MvSelectionCmd.h

@ -2,6 +2,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -9,13 +10,13 @@ namespace piMapper {
class MvSelectionCmd : public BaseUndoCmd { class MvSelectionCmd : public BaseUndoCmd {
public: public:
MvSelectionCmd(SurfaceManager * sm, ofVec2f moveBy); MvSelectionCmd(SurfaceManager * sm, Vec2 moveBy);
void exec(); void exec();
void undo(); void undo();
private: private:
SurfaceManager * _surfaceManager; SurfaceManager * _surfaceManager;
ofVec2f _movedBy; Vec2 _movedBy;
}; };

3
src/Commands/MvSurfaceVertCmd.h

@ -8,6 +8,7 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "ProjectionEditorWidget.h" #include "ProjectionEditorWidget.h"
#include "BaseJoint.h" #include "BaseJoint.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -21,7 +22,7 @@ class MvSurfaceVertCmd : public BaseUndoCmd {
private: private:
int _vertIndex; int _vertIndex;
ofVec2f _prevVertPos; Vec2 _prevVertPos;
BaseSurface * _surface; BaseSurface * _surface;
}; };

2
src/Commands/MvTexCoordCmd.cpp

@ -3,7 +3,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
MvTexCoordCmd::MvTexCoordCmd(int texCoordIndex, ofVec2f by){ MvTexCoordCmd::MvTexCoordCmd(int texCoordIndex, Vec2 by){
_texCoordIndex = texCoordIndex; _texCoordIndex = texCoordIndex;
_moveBy = by; _moveBy = by;
} }

7
src/Commands/MvTexCoordCmd.h

@ -7,6 +7,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "CircleJoint.h" #include "CircleJoint.h"
#include "Gui.h" #include "Gui.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -14,14 +15,14 @@ namespace piMapper {
class MvTexCoordCmd : public BaseUndoCmd { class MvTexCoordCmd : public BaseUndoCmd {
public: public:
MvTexCoordCmd(int texCoordIndex, ofVec2f by); MvTexCoordCmd(int texCoordIndex, Vec2 by);
void exec(); void exec();
void undo(); void undo();
private: private:
int _texCoordIndex; int _texCoordIndex;
ofVec2f _moveBy; Vec2 _moveBy;
ofVec2f _positionBefore; Vec2 _positionBefore;
}; };

4
src/Commands/RmGridColCmd.cpp

@ -30,10 +30,10 @@ void RmGridColCmd::undo(){
} }
_surface->setGridCols(_surface->getGridCols() + 1); _surface->setGridCols(_surface->getGridCols() + 1);
vector <ofVec2f> v; vector <Vec2> v;
for(int i = 0; i < _vertices.size(); ++i){ for(int i = 0; i < _vertices.size(); ++i){
v.push_back( ofVec2f(_vertices[i].x, _vertices[i].y) ); v.push_back( Vec2(_vertices[i].x, _vertices[i].y) );
} }
_surface->setVertices(v); _surface->setVertices(v);

3
src/Commands/RmGridColCmd.h

@ -4,6 +4,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "GridWarpSurface.h" #include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h" #include "ProjectionEditorWidget.h"
#include "Vec2.h"
class ofxPiMapper; class ofxPiMapper;
@ -19,7 +20,7 @@ class RmGridColCmd : public BaseUndoCmd {
private: private:
vector <ofVec3f> _vertices; vector <ofVec3f> _vertices;
vector <ofVec2f> _texCoords; vector <Vec2> _texCoords;
GridWarpSurface * _surface; GridWarpSurface * _surface;
bool _doNotUndo; bool _doNotUndo;

4
src/Commands/RmGridRowCmd.cpp

@ -30,10 +30,10 @@ void RmGridRowCmd::undo(){
} }
_surface->setGridRows(_surface->getGridRows() + 1); _surface->setGridRows(_surface->getGridRows() + 1);
vector <ofVec2f> v; vector <Vec2> v;
for(int i = 0; i < _vertices.size(); ++i){ for(int i = 0; i < _vertices.size(); ++i){
v.push_back( ofVec2f(_vertices[i].x, _vertices[i].y) ); v.push_back( Vec2(_vertices[i].x, _vertices[i].y) );
} }
_surface->setVertices(v); _surface->setVertices(v);

3
src/Commands/RmGridRowCmd.h

@ -4,6 +4,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "GridWarpSurface.h" #include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h" #include "ProjectionEditorWidget.h"
#include "Vec2.h"
class ofxPiMapper; class ofxPiMapper;
@ -19,7 +20,7 @@ class RmGridRowCmd : public BaseUndoCmd {
private: private:
vector <ofVec3f> _vertices; vector <ofVec3f> _vertices;
vector <ofVec2f> _texCoords; vector <Vec2> _texCoords;
GridWarpSurface * _surface; GridWarpSurface * _surface;
bool _doNotUndo; bool _doNotUndo;

2
src/Commands/SaveTexCoordPosCmd.cpp

@ -3,7 +3,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SaveTexCoordPosCmd::SaveTexCoordPosCmd(int texCoordIndex, ofVec2f position){ SaveTexCoordPosCmd::SaveTexCoordPosCmd(int texCoordIndex, Vec2 position){
_texCoordIndex = texCoordIndex; _texCoordIndex = texCoordIndex;
_position = position; _position = position;
} }

5
src/Commands/SaveTexCoordPosCmd.h

@ -7,6 +7,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "CircleJoint.h" #include "CircleJoint.h"
#include "Gui.h" #include "Gui.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -14,13 +15,13 @@ namespace piMapper {
class SaveTexCoordPosCmd : public BaseUndoCmd { class SaveTexCoordPosCmd : public BaseUndoCmd {
public: public:
SaveTexCoordPosCmd(int texCoordIndex, ofVec2f position); SaveTexCoordPosCmd(int texCoordIndex, Vec2 position);
void exec(); void exec();
void undo(); void undo();
private: private:
int _texCoordIndex; int _texCoordIndex;
ofVec2f _position; Vec2 _position;
}; };

3
src/Commands/StartDragSurfaceCmd.cpp

@ -15,7 +15,8 @@ void StartDragSurfaceCmd::exec(){
void StartDragSurfaceCmd::undo(){ void StartDragSurfaceCmd::undo(){
ofLogNotice("StartDragSurfaceCmd", "undo"); ofLogNotice("StartDragSurfaceCmd", "undo");
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]); ofVec3f step = _previousVertices[0] - _surface->getVertices()[0];
_surface->moveBy(Vec2(step));
} }
} // namespace piMapper } // namespace piMapper

1
src/Commands/StartDragSurfaceCmd.h

@ -2,6 +2,7 @@
#include "BaseCmd.h" #include "BaseCmd.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {

19
src/Gui/Widgets/ProjectionEditorWidget.cpp

@ -47,7 +47,7 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){
joints[i]->mouseDragged(args); joints[i]->mouseDragged(args);
} }
ofVec2f mousePosition = ofVec2f(args.x, args.y); Vec2 mousePosition = Vec2(args.x, args.y);
// Collect all vertices of the projection surfaces // Collect all vertices of the projection surfaces
vector <ofVec3f *> allVertices; vector <ofVec3f *> allVertices;
@ -65,10 +65,13 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){
for(int i = 0; i < joints.size(); i++){ for(int i = 0; i < joints.size(); i++){
if(joints[i]->isDragged()){ if(joints[i]->isDragged()){
for(int j = 0; j < allVertices.size(); j++){ for(int j = 0; j < allVertices.size(); j++){
float distance = mousePosition.distance(*allVertices[j]); Vec2 v(*allVertices[j]);
float distance = mousePosition.distance(v);
if(distance < fSnapDistance){ if(distance < fSnapDistance){
joints[i]->position = *allVertices[j]; joints[i]->position = *allVertices[j];
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); Vec2 jointPosition(joints[i]->position);
Vec2 clickPosition(args.x, args.y);
Vec2 clickDistance = jointPosition - clickPosition;
joints[i]->setClickDistance(clickDistance); joints[i]->setClickDistance(clickDistance);
break; break;
} }
@ -135,7 +138,7 @@ void ProjectionEditorWidget::createJoints(){
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
joints.push_back(new CircleJoint()); joints.push_back(new CircleJoint());
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); joints.back()->position = Vec2(vertices[i].x, vertices[i].y);
} }
} }
@ -144,7 +147,7 @@ void ProjectionEditorWidget::updateJoints(){
vector <ofVec3f> & vertices = vector <ofVec3f> & vertices =
surfaceManager->getSelectedSurface()->getVertices(); surfaceManager->getSelectedSurface()->getVertices();
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); joints[i]->position = Vec2(vertices[i].x, vertices[i].y);
} }
} }
@ -156,7 +159,7 @@ void ProjectionEditorWidget::unselectAllJoints(){
} }
} }
void ProjectionEditorWidget::moveSelectedSurface(ofVec2f by){ void ProjectionEditorWidget::moveSelectedSurface(Vec2 by){
if(surfaceManager == 0){ if(surfaceManager == 0){
return; return;
} }
@ -177,7 +180,7 @@ void ProjectionEditorWidget::setSnapDistance(float newSnapDistance){
fSnapDistance = newSnapDistance; fSnapDistance = newSnapDistance;
} }
CircleJoint * ProjectionEditorWidget::hitTestJoints(ofVec2f pos){ CircleJoint * ProjectionEditorWidget::hitTestJoints(Vec2 pos){
if(surfaceManager->getSelectedSurface() == 0){ if(surfaceManager->getSelectedSurface() == 0){
return 0; return 0;
} }
@ -236,4 +239,4 @@ void ProjectionEditorWidget::drawJoints(){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

7
src/Gui/Widgets/ProjectionEditorWidget.h

@ -2,6 +2,7 @@
#include "SurfaceManager.h" #include "SurfaceManager.h"
#include "CircleJoint.h" #include "CircleJoint.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -22,11 +23,11 @@ class ProjectionEditorWidget {
void createJoints(); void createJoints();
void updateJoints(); void updateJoints();
void unselectAllJoints(); void unselectAllJoints();
void moveSelectedSurface(ofVec2f by); void moveSelectedSurface(Vec2 by);
void stopDragJoints(); void stopDragJoints();
void updateVertices(); void updateVertices();
void setSnapDistance(float newSnapDistance); void setSnapDistance(float newSnapDistance);
CircleJoint * hitTestJoints(ofVec2f pos); CircleJoint * hitTestJoints(Vec2 pos);
vector <CircleJoint *> * getJoints(); vector <CircleJoint *> * getJoints();
void onVertexChanged(int & i); void onVertexChanged(int & i);
@ -46,4 +47,4 @@ class ProjectionEditorWidget {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

54
src/Gui/Widgets/TextureEditorWidget.cpp

@ -23,7 +23,7 @@ void TextureEditorWidget::update(){
} }
// update surface if one of the joints is being dragged // update surface if one of the joints is being dragged
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
// Get selected joint index // Get selected joint index
@ -44,8 +44,8 @@ void TextureEditorWidget::update(){
if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){ if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){
GridWarpSurface * s = (GridWarpSurface *)surface; GridWarpSurface * s = (GridWarpSurface *)surface;
vector <ofVec2f> & texCoords = surface->getTexCoords(); vector <Vec2> & texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
int rows = s->getGridRows(); int rows = s->getGridRows();
@ -65,7 +65,7 @@ void TextureEditorWidget::update(){
int i = 0; int i = 0;
for(int iy = 0; iy <= rows; ++iy){ for(int iy = 0; iy <= rows; ++iy){
for(int ix = 0; ix <= cols; ++ix){ for(int ix = 0; ix <= cols; ++ix){
ofVec2f t; Vec2 t;
t.x = sx + dx * ix; t.x = sx + dx * ix;
t.y = sy + dy * iy; t.y = sy + dy * iy;
surface->setTexCoord(i, t); surface->setTexCoord(i, t);
@ -132,7 +132,7 @@ void TextureEditorWidget::createJoints(){
return; return;
} }
clearJoints(); clearJoints();
vector <ofVec2f> & texCoords = surface->getTexCoords(); vector <Vec2> & texCoords = surface->getTexCoords();
if(surface->getSource()->getTexture()->isAllocated()){ if(surface->getSource()->getTexture()->isAllocated()){
_pollCreateJoints = false; _pollCreateJoints = false;
@ -141,11 +141,11 @@ void TextureEditorWidget::createJoints(){
return; return;
} }
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
// Select joints depending on the surface type // Select joints depending on the surface type
vector <ofVec2f> tc; vector <Vec2> tc;
if(surface->getType() == SurfaceType::TRIANGLE_SURFACE){ if(surface->getType() == SurfaceType::TRIANGLE_SURFACE){
tc = texCoords; tc = texCoords;
@ -274,13 +274,13 @@ void TextureEditorWidget::selectPrevTexCoord(){
selectTexCoord(joints.size() - 1); selectTexCoord(joints.size() - 1);
} }
void TextureEditorWidget::moveTexCoords(ofVec2f by){ void TextureEditorWidget::moveTexCoords(Vec2 by){
if(surface == 0){ if(surface == 0){
return; return;
} }
vector <ofVec2f> & texCoords = surface->getTexCoords(); vector <Vec2> & texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(), Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
for(int i = 0; i < joints.size(); i++){ for(int i = 0; i < joints.size(); i++){
@ -313,7 +313,7 @@ void TextureEditorWidget::moveTexCoords(ofVec2f by){
int i = 0; int i = 0;
for(int iy = 0; iy <= rows; ++iy){ for(int iy = 0; iy <= rows; ++iy){
for(int ix = 0; ix <= cols; ++ix){ for(int ix = 0; ix <= cols; ++ix){
ofVec2f t; Vec2 t;
t.x = sx + dx * ix; t.x = sx + dx * ix;
t.y = sy + dy * iy; t.y = sy + dy * iy;
surface->setTexCoord(i, t); surface->setTexCoord(i, t);
@ -327,7 +327,7 @@ void TextureEditorWidget::moveTexCoords(ofVec2f by){
} }
} }
void TextureEditorWidget::moveTexCoordTo(int texCoordIndex, ofVec2f position){ void TextureEditorWidget::moveTexCoordTo(int texCoordIndex, Vec2 position){
if(surface == 0){ if(surface == 0){
return; return;
} }
@ -335,7 +335,7 @@ void TextureEditorWidget::moveTexCoordTo(int texCoordIndex, ofVec2f position){
ofLogNotice("TextureEditorWidget::moveTexCoordTo") << texCoordIndex << ", " << position.x << ", " << position.y; ofLogNotice("TextureEditorWidget::moveTexCoordTo") << texCoordIndex << ", " << position.x << ", " << position.y;
surface->setTexCoord(texCoordIndex, position); surface->setTexCoord(texCoordIndex, position);
ofVec2f textureSize = ofVec2f( Vec2 textureSize = Vec2(
surface->getSource()->getTexture()->getWidth(), surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight()); surface->getSource()->getTexture()->getHeight());
joints[texCoordIndex]->position = position * textureSize; joints[texCoordIndex]->position = position * textureSize;
@ -347,7 +347,7 @@ void TextureEditorWidget::stopDragJoints(){
} }
} }
void TextureEditorWidget::moveSelection(ofVec2f by){ void TextureEditorWidget::moveSelection(Vec2 by){
// check if joints selected // check if joints selected
bool bJointSelected = false; bool bJointSelected = false;
BaseJoint * selectedJoint; BaseJoint * selectedJoint;
@ -369,32 +369,32 @@ void TextureEditorWidget::moveSelection(ofVec2f by){
void TextureEditorWidget::constrainJointsToQuad(int selectedJointIndex){ void TextureEditorWidget::constrainJointsToQuad(int selectedJointIndex){
switch(selectedJointIndex){ switch(selectedJointIndex){
case 0: case 0:
joints[1]->position = ofVec2f(joints[1]->position.x, joints[0]->position.y); joints[1]->position = Vec2(joints[1]->position.x, joints[0]->position.y);
joints[2]->position = ofVec2f(joints[1]->position.x, joints[3]->position.y); joints[2]->position = Vec2(joints[1]->position.x, joints[3]->position.y);
joints[3]->position = ofVec2f(joints[0]->position.x, joints[3]->position.y); joints[3]->position = Vec2(joints[0]->position.x, joints[3]->position.y);
break; break;
case 1: case 1:
joints[0]->position = ofVec2f(joints[0]->position.x, joints[1]->position.y); joints[0]->position = Vec2(joints[0]->position.x, joints[1]->position.y);
joints[2]->position = ofVec2f(joints[1]->position.x, joints[2]->position.y); joints[2]->position = Vec2(joints[1]->position.x, joints[2]->position.y);
joints[3]->position = ofVec2f(joints[0]->position.x, joints[2]->position.y); joints[3]->position = Vec2(joints[0]->position.x, joints[2]->position.y);
break; break;
case 2: case 2:
joints[1]->position = ofVec2f(joints[2]->position.x, joints[1]->position.y); joints[1]->position = Vec2(joints[2]->position.x, joints[1]->position.y);
joints[3]->position = ofVec2f(joints[3]->position.x, joints[2]->position.y); joints[3]->position = Vec2(joints[3]->position.x, joints[2]->position.y);
joints[0]->position = ofVec2f(joints[3]->position.x, joints[1]->position.y); joints[0]->position = Vec2(joints[3]->position.x, joints[1]->position.y);
break; break;
case 3: case 3:
joints[0]->position = ofVec2f(joints[3]->position.x, joints[0]->position.y); joints[0]->position = Vec2(joints[3]->position.x, joints[0]->position.y);
joints[2]->position = ofVec2f(joints[2]->position.x, joints[3]->position.y); joints[2]->position = Vec2(joints[2]->position.x, joints[3]->position.y);
joints[1]->position = ofVec2f(joints[2]->position.x, joints[0]->position.y); joints[1]->position = Vec2(joints[2]->position.x, joints[0]->position.y);
break; break;
} // switch } // switch
} }
CircleJoint * TextureEditorWidget::hitTestJoints(ofVec2f pos){ CircleJoint * TextureEditorWidget::hitTestJoints(Vec2 pos){
for(int i = 0; i < joints.size(); i++){ for(int i = 0; i < joints.size(); i++){
if(joints[i]->hitTest(pos)){ if(joints[i]->hitTest(pos)){
return joints[i]; return joints[i];

11
src/Gui/Widgets/TextureEditorWidget.h

@ -7,6 +7,7 @@
#include "CircleJoint.h" #include "CircleJoint.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "GuiBaseWidget.h" #include "GuiBaseWidget.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -38,13 +39,13 @@ class TextureEditorWidget : public GuiBaseWidget {
void selectNextTexCoord(); void selectNextTexCoord();
void selectPrevTexCoord(); void selectPrevTexCoord();
void moveTexCoords(ofVec2f by); void moveTexCoords(Vec2 by);
void moveTexCoordTo(int texCoordIndex, ofVec2f position); void moveTexCoordTo(int texCoordIndex, Vec2 position);
void stopDragJoints(); void stopDragJoints();
void moveSelection(ofVec2f by); void moveSelection(Vec2 by);
void constrainJointsToQuad(int selectedJointIndex); void constrainJointsToQuad(int selectedJointIndex);
CircleJoint * hitTestJoints(ofVec2f pos); CircleJoint * hitTestJoints(Vec2 pos);
vector <CircleJoint *> & getJoints(); vector <CircleJoint *> & getJoints();
private: private:
@ -57,4 +58,4 @@ class TextureEditorWidget : public GuiBaseWidget {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

30
src/Surfaces/BaseSurface.cpp

@ -51,24 +51,32 @@ void BaseSurface::createDefaultTexture(){
source = defaultSource; source = defaultSource;
} }
void BaseSurface::drawTexture(ofVec2f position){ void BaseSurface::drawTexture(Vec2 position){
if(source->getTexture() == 0){ if(source->getTexture() == 0){
ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; ofLogWarning("BaseSurface") << "Source texture empty. Not drawing.";
return; return;
} }
ofMesh texMesh; ofMesh texMesh;
texMesh.addVertex(position); texMesh.addVertex(position.toOf());
texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f));
texMesh.addVertex(position Vec2 topRight(source->getTexture()->getWidth(), 0.0f);
+ ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); texMesh.addVertex((position + topRight).toOf());
texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight()));
Vec2 bottomRight(source->getTexture()->getWidth(), source->getTexture()->getHeight());
texMesh.addVertex((position + bottomRight).toOf());
Vec2 bottomLeft(0.0f, source->getTexture()->getHeight());
texMesh.addVertex((position + bottomLeft).toOf());
texMesh.addTriangle(0, 2, 3); texMesh.addTriangle(0, 2, 3);
texMesh.addTriangle(0, 1, 2); texMesh.addTriangle(0, 1, 2);
texMesh.addTexCoord(ofVec2f(0.0f, 0.0f));
texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); texMesh.addTexCoord(Vec2(0.0f, 0.0f).toOf());
texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); texMesh.addTexCoord(Vec2(1.0f, 0.0f).toOf());
texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); texMesh.addTexCoord(Vec2(1.0f, 1.0f).toOf());
texMesh.addTexCoord(Vec2(0.0f, 1.0f).toOf());
source->getTexture()->bind(); source->getTexture()->bind();
texMesh.draw(); texMesh.draw();
source->getTexture()->unbind(); source->getTexture()->unbind();
@ -150,4 +158,4 @@ ofRectangle & BaseSurface::getBoundingBox(){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

21
src/Surfaces/BaseSurface.h

@ -3,6 +3,7 @@
#include "ofMain.h" #include "ofMain.h"
#include <string> #include <string>
#include "BaseSource.h" #include "BaseSource.h"
#include "Vec2.h"
using namespace std; using namespace std;
@ -17,25 +18,25 @@ class BaseSurface {
virtual void setup() = 0; virtual void setup() = 0;
virtual void draw() = 0; virtual void draw() = 0;
virtual void setVertex(int index, ofVec2f p) = 0; virtual void setVertex(int index, Vec2 p) = 0;
virtual void setVertices(vector<ofVec2f> v) = 0; virtual void setVertices(vector<Vec2> v) = 0;
virtual void setTexCoord(int index, ofVec2f t) = 0; virtual void setTexCoord(int index, Vec2 t) = 0;
virtual void setTexCoords(vector<ofVec2f> t) = 0; virtual void setTexCoords(vector<Vec2> t) = 0;
virtual void moveBy(ofVec2f v) = 0; virtual void moveBy(Vec2 v) = 0;
virtual int getType() = 0; virtual int getType() = 0;
virtual bool hitTest(ofVec2f p) = 0; virtual bool hitTest(Vec2 p) = 0;
virtual ofPolyline getHitArea() = 0; virtual ofPolyline getHitArea() = 0;
virtual ofPolyline getTextureHitArea() = 0; virtual ofPolyline getTextureHitArea() = 0;
virtual vector <ofVec3f> & getVertices() = 0; virtual vector <ofVec3f> & getVertices() = 0;
virtual vector <ofVec2f> & getTexCoords() = 0; virtual vector <Vec2> & getTexCoords() = 0;
virtual BaseSurface * clone() = 0; virtual BaseSurface * clone() = 0;
void drawTexture(ofVec2f position); void drawTexture(Vec2 position);
void setSource(BaseSource * newSource); void setSource(BaseSource * newSource);
void setMoved(bool moved); void setMoved(bool moved);
void scaleTo(float scale); void scaleTo(float scale);
@ -67,7 +68,9 @@ class BaseSurface {
bool _moved; bool _moved;
float _scale; float _scale;
vector<Vec2> _texCoords;
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

44
src/Surfaces/CircleSurface.cpp

@ -104,10 +104,10 @@ void CircleSurface::setup() {
// } // }
//#endif //#endif
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); Vec2 t1 = Vec2(0.0f, 0.0f);
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); Vec2 t2 = Vec2(1.0f, 0.0f);
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); Vec2 t3 = Vec2(1.0f, 1.0f);
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); Vec2 t4 = Vec2(0.0f, 1.0f);
defaultTexCoords.push_back(t1); defaultTexCoords.push_back(t1);
defaultTexCoords.push_back(t2); defaultTexCoords.push_back(t2);
@ -162,7 +162,7 @@ void CircleSurface::draw() {
source->getTexture()->getTextureData().textureID = outputFbo.getTexture().getTextureData().textureID; source->getTexture()->getTextureData().textureID = outputFbo.getTexture().getTextureData().textureID;
auto texCoords = getMesh().getTexCoords(); auto texCoords = getMesh().getTexCoords();
getMesh().clearTexCoords(); getMesh().clearTexCoords();
getMesh().addTexCoords(defaultTexCoords); getMesh().addTexCoords(Vec2::toOf(defaultTexCoords));
// Draw the Quad: // Draw the Quad:
QuadSurface::draw(); QuadSurface::draw();
@ -264,35 +264,35 @@ void CircleSurface::setupTextures() {
// meshes are similar: // meshes are similar:
// Create 4 points for the 2 triangles // Create 4 points for the 2 triangles
ofVec2f p1 = ofVec2f(0, 0); Vec3 p1 = Vec3(0, 0, 0);
ofVec2f p2 = ofVec2f(0, h); Vec3 p2 = Vec3(0, h, 0);
ofVec2f p3 = ofVec2f(w, h); Vec3 p3 = Vec3(w, h, 0);
ofVec2f p4 = ofVec2f(w, 0); Vec3 p4 = Vec3(w, 0, 0);
// Create 4 point for the texture coordinates // Create 4 point for the texture coordinates
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 1.0f)); Vec2 t1 = Vec2(Vec2(0.0f, 1.0f));
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 1.0f)); Vec2 t2 = Vec2(Vec2(1.0f, 1.0f));
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 0.0f)); Vec2 t3 = Vec2(Vec2(1.0f, 0.0f));
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 0.0f)); Vec2 t4 = Vec2(Vec2(0.0f, 0.0f));
// Clear maskMesh // Clear maskMesh
maskMesh.clear(); maskMesh.clear();
// Create a surface with the points // Create a surface with the points
maskMesh.addVertex(p1); maskMesh.addVertex(p1.toOf());
maskMesh.addVertex(p2); maskMesh.addVertex(p2.toOf());
maskMesh.addVertex(p3); maskMesh.addVertex(p3.toOf());
maskMesh.addVertex(p4); maskMesh.addVertex(p4.toOf());
// Add 2 triangles // Add 2 triangles
maskMesh.addTriangle(0, 2, 3); maskMesh.addTriangle(0, 2, 3);
maskMesh.addTriangle(0, 1, 2); maskMesh.addTriangle(0, 1, 2);
// Add texture coordinates // Add texture coordinates
maskMesh.addTexCoord(t1); maskMesh.addTexCoord(t1.toOf());
maskMesh.addTexCoord(t2); maskMesh.addTexCoord(t2.toOf());
maskMesh.addTexCoord(t3); maskMesh.addTexCoord(t3.toOf());
maskMesh.addTexCoord(t4); maskMesh.addTexCoord(t4.toOf());
} }
@ -302,4 +302,4 @@ int CircleSurface::getType() {
} }
} }
} }

4
src/Surfaces/CircleSurface.h

@ -7,6 +7,8 @@
#define OFXPIMAPPER_CIRCLESURFACE_H #define OFXPIMAPPER_CIRCLESURFACE_H
#include "QuadSurface.h" #include "QuadSurface.h"
#include "Vec2.h"
#include "Vec3.h"
#define CIRCLE_SURFACE_STRINGIFY(A) #A #define CIRCLE_SURFACE_STRINGIFY(A) #A
@ -49,7 +51,7 @@ class CircleSurface : public QuadSurface {
// string gl3FragmentShader; // string gl3FragmentShader;
private: private:
std::vector<ofVec2f> defaultTexCoords; std::vector<Vec2> defaultTexCoords;
// We will use this pointer to determine if the source has changed. // We will use this pointer to determine if the source has changed.
// This is a total kludge, but it keeps me from messing with the // This is a total kludge, but it keeps me from messing with the
// upstream source. // upstream source.

54
src/Surfaces/GridWarpSurface.cpp

@ -34,11 +34,11 @@ void GridWarpSurface::draw(){
} }
} }
void GridWarpSurface::moveBy(ofVec2f v){ void GridWarpSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v.toOf();
} }
setMoved(true); setMoved(true);
@ -67,7 +67,7 @@ int GridWarpSurface::setGridCols(int c){
createGridMesh(); createGridMesh();
} }
bool GridWarpSurface::hitTest(ofVec2f p){ bool GridWarpSurface::hitTest(Vec2 p){
ofPolyline pl; ofPolyline pl;
int vertsPerRow = _gridCols + 1; int vertsPerRow = _gridCols + 1;
@ -85,7 +85,7 @@ bool GridWarpSurface::hitTest(ofVec2f p){
pl.addVertex(mesh.getVertex(d)); pl.addVertex(mesh.getVertex(d));
pl.close(); pl.close();
if(pl.inside(p)){ if(pl.inside(p.toOf())){
return true; return true;
} }
} }
@ -127,8 +127,7 @@ ofPolyline GridWarpSurface::getHitArea(){
ofPolyline GridWarpSurface::getTextureHitArea(){ ofPolyline GridWarpSurface::getTextureHitArea(){
ofPolyline line; ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords(); Vec2 textureSize = Vec2(source->getTexture()->getWidth(), source->getTexture()->getHeight());
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight());
int vertsPerRow = _gridCols + 1; int vertsPerRow = _gridCols + 1;
int vertsPerCol = _gridRows + 1; int vertsPerCol = _gridRows + 1;
@ -138,32 +137,32 @@ ofPolyline GridWarpSurface::getTextureHitArea(){
int c = (_gridRows * vertsPerRow) + (vertsPerRow - 1); int c = (_gridRows * vertsPerRow) + (vertsPerRow - 1);
int d = (_gridRows * vertsPerRow); int d = (_gridRows * vertsPerRow);
line.addVertex(ofPoint(texCoords[a] * textureSize)); line.addVertex(ofPoint(mesh.getTexCoords()[a] * textureSize.toOf()));
line.addVertex(ofPoint(texCoords[b] * textureSize)); line.addVertex(ofPoint(mesh.getTexCoords()[b] * textureSize.toOf()));
line.addVertex(ofPoint(texCoords[c] * textureSize)); line.addVertex(ofPoint(mesh.getTexCoords()[c] * textureSize.toOf()));
line.addVertex(ofPoint(texCoords[d] * textureSize)); line.addVertex(ofPoint(mesh.getTexCoords()[d] * textureSize.toOf()));
line.close(); line.close();
return line; return line;
} }
void GridWarpSurface::setVertex(int index, ofVec2f p){ void GridWarpSurface::setVertex(int index, Vec2 p){
if(index >= mesh.getVertices().size()){ if(index >= mesh.getVertices().size()){
throw runtime_error("Vertex with provided index does not exist"); throw runtime_error("Vertex with provided index does not exist");
} }
mesh.setVertex(index, p); mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index); ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this); ofNotifyEvent(vertexChangedEvent, index, this);
} }
void GridWarpSurface::setVertices(vector<ofVec2f> v){ void GridWarpSurface::setVertices(vector<Vec2> v){
if(v.size() != mesh.getVertices().size()){ if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < v.size(); ++i){ for(int i = 0; i < v.size(); ++i){
mesh.setVertex(i, v[i]); mesh.setVertex(i, v[i].toOf());
} }
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
@ -181,19 +180,19 @@ void GridWarpSurface::setVertices(vector<ofVec3f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
void GridWarpSurface::setTexCoord(int index, ofVec2f t){ void GridWarpSurface::setTexCoord(int index, Vec2 t){
if(index >= mesh.getVertices().size()){ if(index >= mesh.getVertices().size()){
throw runtime_error("Texture coordinate with provided index does not exist"); throw runtime_error("Texture coordinate with provided index does not exist");
} }
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t.toOf());
} }
void GridWarpSurface::setTexCoords(vector<ofVec2f> t){ void GridWarpSurface::setTexCoords(vector<Vec2> t){
if(t.size() != mesh.getVertices().size()){ if(t.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of texture coordinates"); throw runtime_error("Wrong number of texture coordinates");
} }
for(int i = 0; i < t.size(); ++i){ for(int i = 0; i < t.size(); ++i){
mesh.setTexCoord(i, t[i]); mesh.setTexCoord(i, t[i].toOf());
} }
} }
@ -202,8 +201,12 @@ vector <ofVec3f> & GridWarpSurface::getVertices(){
return mesh.getVertices(); return mesh.getVertices();
} }
vector <ofVec2f> & GridWarpSurface::getTexCoords(){ vector <Vec2> & GridWarpSurface::getTexCoords(){
return mesh.getTexCoords(); _texCoords.clear();
for(auto c : mesh.getTexCoords()){
_texCoords.push_back(Vec2(c));
}
return _texCoords;
} }
void GridWarpSurface::createGridMesh(){ void GridWarpSurface::createGridMesh(){
@ -218,10 +221,9 @@ void GridWarpSurface::createGridMesh(){
// Add vertices for each col and row // Add vertices for each col and row
for(int iy = 0; iy <= _gridRows; ++iy){ for(int iy = 0; iy <= _gridRows; ++iy){
for(int ix = 0; ix <= _gridCols; ++ix){ for(int ix = 0; ix <= _gridCols; ++ix){
mesh.addVertex( mesh.addVertex(Vec2(
ofVec2f( margin + (vertexDistanceX * (float)ix),
margin + (vertexDistanceX * (float)ix), margin + (vertexDistanceY * (float)iy)).toOf());
margin + (vertexDistanceY * (float)iy) ));
} }
} }
@ -245,7 +247,7 @@ void GridWarpSurface::createGridMesh(){
for(int ix = 0; ix <= _gridCols; ++ix){ for(int ix = 0; ix <= _gridCols; ++ix){
float xc = (ix == 0) ? 0.0f : (float)ix / (float)_gridCols; float xc = (ix == 0) ? 0.0f : (float)ix / (float)_gridCols;
float yc = (iy == 0) ? 0.0f : (float)iy / (float)_gridRows; float yc = (iy == 0) ? 0.0f : (float)iy / (float)_gridRows;
mesh.addTexCoord(ofVec2f(xc, yc)); mesh.addTexCoord(Vec2(xc, yc).toOf());
} }
} }
@ -263,4 +265,4 @@ BaseSurface * GridWarpSurface::clone(){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

19
src/Surfaces/GridWarpSurface.h

@ -4,6 +4,7 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "HomographyHelper.h" #include "HomographyHelper.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -14,7 +15,7 @@ class GridWarpSurface : public BaseSurface {
void setup(); void setup();
void draw(); void draw();
void moveBy(ofVec2f v); void moveBy(Vec2 v);
int getType(); int getType();
int getGridRows(); int getGridRows();
@ -22,18 +23,18 @@ class GridWarpSurface : public BaseSurface {
int setGridRows(int r); int setGridRows(int r);
int setGridCols(int c); int setGridCols(int c);
bool hitTest(ofVec2f p); bool hitTest(Vec2 p);
ofPolyline getHitArea(); ofPolyline getHitArea();
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
void setVertex(int index, ofVec2f p); void setVertex(int index, Vec2 p);
void setVertices(vector<ofVec2f> v); void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v); void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t); void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<ofVec2f> t); void setTexCoords(vector<Vec2> t);
vector <ofVec3f> & getVertices(); vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords(); vector <Vec2> & getTexCoords();
void createGridMesh(); void createGridMesh();
@ -42,7 +43,9 @@ class GridWarpSurface : public BaseSurface {
private: private:
int _gridCols; int _gridCols;
int _gridRows; int _gridRows;
vector<Vec2> _texCoords;
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

92
src/Surfaces/HexagonSurface.cpp

@ -11,42 +11,42 @@ void HexagonSurface::setup(){
// Create 6 + 1 points for the hexagon surface. // Create 6 + 1 points for the hexagon surface.
vector <ofVec2f> verts; vector <Vec2> verts;
verts.resize(7); verts.resize(7);
// Start with the center. // Start with the center.
verts[0] = ofVec2f((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f); verts[0] = Vec2((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f);
// Then from top left clockwise. // Then from top left clockwise.
verts[1] = ofVec2f((float)ofGetWidth() / 3.0f, 0); verts[1] = Vec2((float)ofGetWidth() / 3.0f, 0);
verts[2] = ofVec2f((float)ofGetWidth() / 3.0f * 2.0f, 0); verts[2] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, 0);
verts[3] = ofVec2f(ofGetWidth(), (float)ofGetHeight() / 2.0f); verts[3] = Vec2(ofGetWidth(), (float)ofGetHeight() / 2.0f);
verts[4] = ofVec2f((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight()); verts[4] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight());
verts[5] = ofVec2f((float)ofGetWidth() / 3.0f, ofGetHeight()); verts[5] = Vec2((float)ofGetWidth() / 3.0f, ofGetHeight());
verts[6] = ofVec2f(0, (float)ofGetHeight() / 2.0f); verts[6] = Vec2(0, (float)ofGetHeight() / 2.0f);
// No create the texture coordinates. // No create the texture coordinates.
vector <ofVec2f> coords; vector <Vec2> coords;
coords.resize(7); coords.resize(7);
// Start with center. // Start with center.
coords[0] = ofVec2f(0.5f, 0.5f); coords[0] = Vec2(0.5f, 0.5f);
// Then from top left and go clockwise. // Then from top left and go clockwise.
coords[1] = ofVec2f(1.0f / 3.0f, 0.0f); coords[1] = Vec2(1.0f / 3.0f, 0.0f);
coords[2] = ofVec2f(1.0f / 3.0f * 2.0f, 0.0f); coords[2] = Vec2(1.0f / 3.0f * 2.0f, 0.0f);
coords[3] = ofVec2f(1.0f, 0.5f); coords[3] = Vec2(1.0f, 0.5f);
coords[4] = ofVec2f(1.0f / 3.0f * 2.0f, 1.0f); coords[4] = Vec2(1.0f / 3.0f * 2.0f, 1.0f);
coords[5] = ofVec2f(1.0f / 3.0f, 1.0f); coords[5] = Vec2(1.0f / 3.0f, 1.0f);
coords[6] = ofVec2f(0.0f, 0.5f); coords[6] = Vec2(0.0f, 0.5f);
// And finally setup // And finally setup
setup(verts, coords, source); setup(verts, coords, source);
} }
void HexagonSurface::setup( void HexagonSurface::setup(
vector <ofVec2f> & verts, vector <Vec2> & verts,
vector <ofVec2f> & coords, vector <Vec2> & coords,
BaseSource * newSource){ BaseSource * newSource){
// Assign texture // Assign texture
@ -57,7 +57,7 @@ void HexagonSurface::setup(
// Add vertices to the mesh // Add vertices to the mesh
for(unsigned int i = 0; i < verts.size(); ++i){ for(unsigned int i = 0; i < verts.size(); ++i){
mesh.addVertex(verts[i]); mesh.addVertex(verts[i].toOf());
} }
// Form triangles // Form triangles
@ -78,7 +78,7 @@ void HexagonSurface::setup(
// Add texture coords // Add texture coords
for(unsigned int i = 0; i < coords.size(); ++i){ for(unsigned int i = 0; i < coords.size(); ++i){
mesh.addTexCoord(coords[i]); mesh.addTexCoord(coords[i].toOf());
} }
} }
@ -103,24 +103,24 @@ void HexagonSurface::draw(){
} }
} }
void HexagonSurface::setVertex(int index, ofVec2f p){ void HexagonSurface::setVertex(int index, Vec2 p){
if(index >= mesh.getVertices().size()){ if(index >= mesh.getVertices().size()){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
return; return;
} }
mesh.setVertex(index, p); mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index); ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this); ofNotifyEvent(vertexChangedEvent, index, this);
} }
void HexagonSurface::setVertices(vector<ofVec2f> v){ void HexagonSurface::setVertices(vector<Vec2> v){
if(v.size() != mesh.getVertices().size()){ if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < v.size(); ++i){ for(int i = 0; i < v.size(); ++i){
mesh.setVertex(i, v[i]); mesh.setVertex(i, v[i].toOf());
} }
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
@ -138,30 +138,30 @@ void HexagonSurface::setVertices(vector<ofVec3f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
void HexagonSurface::setTexCoord(int index, ofVec2f t){ void HexagonSurface::setTexCoord(int index, Vec2 t){
if(index >= mesh.getTexCoords().size()){ if(index >= mesh.getTexCoords().size()){
ofLog() << "Texture coordinate with this index does not exist: " << index ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl; << endl;
return; return;
} }
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t.toOf());
} }
void HexagonSurface::setTexCoords(vector<ofVec2f> t){ void HexagonSurface::setTexCoords(vector<Vec2> t){
if(t.size() != mesh.getTexCoords().size()){ if(t.size() != mesh.getTexCoords().size()){
throw runtime_error("Wrong number of texture coordinates"); throw runtime_error("Wrong number of texture coordinates");
} }
for(int i = 0; i < t.size(); ++i){ for(int i = 0; i < t.size(); ++i){
mesh.setTexCoord(i, t[i]); mesh.setTexCoord(i, t[i].toOf());
} }
} }
void HexagonSurface::moveBy(ofVec2f v){ void HexagonSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v.toOf();
} }
setMoved(true); setMoved(true);
@ -172,7 +172,7 @@ int HexagonSurface::getType(){
return SurfaceType::HEXAGON_SURFACE; return SurfaceType::HEXAGON_SURFACE;
} }
bool HexagonSurface::hitTest(ofVec2f p){ bool HexagonSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
@ -183,22 +183,24 @@ bool HexagonSurface::hitTest(ofVec2f p){
} }
} }
ofVec2f HexagonSurface::getVertex(int index){ Vec2 HexagonSurface::getVertex(int index){
if(index > 2){ if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
throw runtime_error("Vertex index out of bounds."); throw runtime_error("Vertex index out of bounds.");
} }
ofVec3f vert = mesh.getVertex(index); ofVec3f vert = mesh.getVertex(index);
return ofVec2f(vert.x, vert.y); return Vec2(vert.x, vert.y);
} }
ofVec2f HexagonSurface::getTexCoord(int index){ Vec2 HexagonSurface::getTexCoord(int index){
if(index > 2){ if(index > 2){
throw runtime_error("Texture coordinate index out of bounds."); throw runtime_error("Texture coordinate index out of bounds.");
} }
return mesh.getTexCoord(index); return Vec2(
mesh.getTexCoord(index).x,
mesh.getTexCoord(index).y);
} }
ofPolyline HexagonSurface::getHitArea(){ ofPolyline HexagonSurface::getHitArea(){
@ -215,17 +217,15 @@ ofPolyline HexagonSurface::getHitArea(){
ofPolyline HexagonSurface::getTextureHitArea(){ ofPolyline HexagonSurface::getTextureHitArea(){
ofPolyline line; ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords(); Vec2 textureSize = Vec2(
ofVec2f textureSize = ofVec2f(
source->getTexture()->getWidth(), source->getTexture()->getWidth(),
source->getTexture()->getHeight()); source->getTexture()->getHeight());
for(int i = 1; i < texCoords.size(); i++){ for(int i = 1; i < mesh.getTexCoords().size(); i++){
line.addVertex(ofPoint(texCoords[i] * textureSize)); line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf()));
} }
line.close(); line.close();
return line; return line;
} }
@ -234,8 +234,12 @@ vector <ofVec3f> & HexagonSurface::getVertices(){
return mesh.getVertices(); return mesh.getVertices();
} }
vector <ofVec2f> & HexagonSurface::getTexCoords(){ vector <Vec2> & HexagonSurface::getTexCoords(){
return mesh.getTexCoords(); _texCoords.clear();
for(auto tc : mesh.getTexCoords()){
_texCoords.push_back(tc);
}
return _texCoords;
} }
BaseSurface * HexagonSurface::clone(){ BaseSurface * HexagonSurface::clone(){
@ -249,4 +253,4 @@ BaseSurface * HexagonSurface::clone(){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

25
src/Surfaces/HexagonSurface.h

@ -3,6 +3,7 @@
#include "ofMain.h" #include "ofMain.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -15,31 +16,31 @@ class HexagonSurface : public BaseSurface {
void setup(); void setup();
void setup( void setup(
vector <ofVec2f> & verts, vector <Vec2> & verts,
vector <ofVec2f> & coords, vector <Vec2> & coords,
BaseSource * newSource); BaseSource * newSource);
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, Vec2 p);
void setVertices(vector<ofVec2f> v); void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v); void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t); void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<ofVec2f> t); void setTexCoords(vector<Vec2> t);
void moveBy(ofVec2f v); void moveBy(Vec2 v);
int getType(); int getType();
bool hitTest(ofVec2f p); bool hitTest(Vec2 p);
ofVec2f getVertex(int index); Vec2 getVertex(int index);
ofVec2f getTexCoord(int index); Vec2 getTexCoord(int index);
ofPolyline getHitArea(); ofPolyline getHitArea();
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
vector <ofVec3f> & getVertices(); vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords(); vector <Vec2> & getTexCoords();
BaseSurface * clone(); BaseSurface * clone();
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

653
src/Surfaces/QuadSurface.cpp

@ -1,323 +1,330 @@
#include "QuadSurface.h" #include "QuadSurface.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
QuadSurface::QuadSurface(){ QuadSurface::QuadSurface(){
_perspectiveWarping = false; _perspectiveWarping = false;
setup(); setup();
} }
QuadSurface::~QuadSurface(){ QuadSurface::~QuadSurface(){
cout << "QuadSurface destructor." << endl; cout << "QuadSurface destructor." << endl;
} }
void QuadSurface::setup(){ void QuadSurface::setup(){
// Create 4 points for the 2 triangles // Create 4 points for the 2 triangles
ofVec2f p1 = ofVec2f(0, 0); Vec2 p1 = Vec2(0, 0);
ofVec2f p2 = ofVec2f(0, ofGetHeight()); Vec2 p2 = Vec2(0, ofGetHeight());
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight());
ofVec2f p4 = ofVec2f(ofGetWidth(), 0); Vec2 p4 = Vec2(ofGetWidth(), 0);
// Create 4 point for the texture coordinates // Create 4 point for the texture coordinates
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); Vec2 t1 = Vec2(Vec2(0.0f, 0.0f));
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); Vec2 t2 = Vec2(Vec2(1.0f, 0.0f));
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); Vec2 t3 = Vec2(Vec2(1.0f, 1.0f));
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); Vec2 t4 = Vec2(Vec2(0.0f, 1.0f));
setup(p1, p2, p3, p4, t1, t2, t3, t4, source); setup(p1, p2, p3, p4, t1, t2, t3, t4, source);
} }
void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, void QuadSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4,
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, Vec2 t1, Vec2 t2, Vec2 t3, Vec2 t4,
BaseSource * newSource){ BaseSource * newSource){
// Assign texture // Assign texture
source = newSource; source = newSource;
// Clear mesh // Clear mesh
mesh.clear(); mesh.clear();
// Create a surface with the points // Create a surface with the points
mesh.addVertex(p1); mesh.addVertex(p1.toOf());
mesh.addVertex(p2); mesh.addVertex(p2.toOf());
mesh.addVertex(p3); mesh.addVertex(p3.toOf());
mesh.addVertex(p4); mesh.addVertex(p4.toOf());
// Add 2 triangles // Add 2 triangles
mesh.addTriangle(0, 2, 3); mesh.addTriangle(0, 2, 3);
mesh.addTriangle(0, 1, 2); mesh.addTriangle(0, 1, 2);
// Add texture coordinates // Add texture coordinates
mesh.addTexCoord(t1); mesh.addTexCoord(t1.toOf());
mesh.addTexCoord(t2); mesh.addTexCoord(t2.toOf());
mesh.addTexCoord(t3); mesh.addTexCoord(t3.toOf());
mesh.addTexCoord(t4); mesh.addTexCoord(t4.toOf());
} }
void QuadSurface::draw(){ void QuadSurface::draw(){
if(source->getTexture() == 0){ if(source->getTexture() == 0){
return; return;
} }
if(!source->getTexture()->isAllocated()){ if(!source->getTexture()->isAllocated()){
return; return;
} }
if(_perspectiveWarping){ if(_perspectiveWarping){
if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){ if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
calculateHomography(); calculateHomography();
} }
ofRectangle box = getMeshBoundingBox(); ofRectangle box = getMeshBoundingBox();
ofMesh m = mesh; ofMesh m = mesh;
m.setVertex(0, ofVec3f(0, 0, 0)); m.setVertex(0, ofVec3f(0, 0, 0));
m.setVertex(1, ofVec3f(box.width, 0, 0)); m.setVertex(1, ofVec3f(box.width, 0, 0));
m.setVertex(2, ofVec3f(box.width, box.height, 0)); m.setVertex(2, ofVec3f(box.width, box.height, 0));
m.setVertex(3, ofVec3f(0, box.height, 0)); m.setVertex(3, ofVec3f(0, box.height, 0));
ofPushMatrix(); ofPushMatrix();
if(true){ if(true){
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); bool normalizedTexCoords = ofGetUsingNormalizedTexCoords();
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
glMultMatrixf(_matrix); glMultMatrixf(_matrix);
source->getTexture()->bind(); source->getTexture()->bind();
m.draw(); m.draw();
source->getTexture()->unbind(); source->getTexture()->unbind();
if(!normalizedTexCoords){ if(!normalizedTexCoords){
ofDisableNormalizedTexCoords(); ofDisableNormalizedTexCoords();
} }
} }
ofPopMatrix(); ofPopMatrix();
}else{ }else{
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); bool normalizedTexCoords = ofGetUsingNormalizedTexCoords();
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255); ofSetColor(255, 255, 255);
source->getTexture()->bind(); source->getTexture()->bind();
mesh.draw(); mesh.draw();
source->getTexture()->unbind(); source->getTexture()->unbind();
ofPopStyle(); ofPopStyle();
if(!normalizedTexCoords){ if(!normalizedTexCoords){
ofDisableNormalizedTexCoords(); ofDisableNormalizedTexCoords();
} }
} }
} }
void QuadSurface::setVertex(int index, ofVec2f p){ void QuadSurface::setVertex(int index, Vec2 p){
if(index > 3){ if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
return; return;
} }
mesh.setVertex(index, p); mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index); ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this); ofNotifyEvent(vertexChangedEvent, index, this);
} }
void QuadSurface::setVertices(vector<ofVec2f> v){ void QuadSurface::setVertices(vector<Vec2> v){
if(v.size() != 4){ if(v.size() != 4){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
mesh.setVertex(i, v[i]); mesh.setVertex(i, v[i].toOf());
} }
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
void QuadSurface::setVertices(vector<ofVec3f> v){ void QuadSurface::setVertices(vector<ofVec3f> v){
if(v.size() != 4){ if(v.size() != 4){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
mesh.setVertex(i, v[i]); mesh.setVertex(i, v[i]);
} }
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
void QuadSurface::setTexCoord(int index, ofVec2f t){ void QuadSurface::setTexCoord(int index, Vec2 t){
if(index > 3){ if(index > 3){
ofLog() << "Texture coordinate with this index does not exist: " << index ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl; << endl;
return; return;
} }
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t.toOf());
} }
void QuadSurface::setTexCoords(vector<ofVec2f> t){ void QuadSurface::setTexCoords(vector<Vec2> t){
if(t.size() != 4){ if(t.size() != 4){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < 4; ++i){ for(int i = 0; i < 4; ++i){
mesh.setTexCoord(i, t[i]); mesh.setTexCoord(i, t[i].toOf());
} }
} }
void QuadSurface::moveBy(ofVec2f v){ void QuadSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v.toOf();
} }
setMoved(true); setMoved(true);
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
int QuadSurface::getType(){ int QuadSurface::getType(){
return SurfaceType::QUAD_SURFACE; return SurfaceType::QUAD_SURFACE;
} }
bool QuadSurface::hitTest(ofVec2f p){ bool QuadSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
if(line.inside(p.x, p.y)){ if(line.inside(p.x, p.y)){
return true; return true;
}else{ }else{
return false; return false;
} }
} }
ofVec2f QuadSurface::getVertex(int index){ Vec2 QuadSurface::getVertex(int index){
if(index > 3){ if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
throw runtime_error("Vertex index out of bounds."); throw runtime_error("Vertex index out of bounds.");
} }
ofVec3f vert = mesh.getVertex(index); ofVec3f vert = mesh.getVertex(index);
return ofVec2f(vert.x, vert.y); return Vec2(vert.x, vert.y);
} }
ofVec2f QuadSurface::getTexCoord(int index){ Vec2 QuadSurface::getTexCoord(int index){
if(index > 3){ if(index > 3){
throw runtime_error("Texture coordinate index out of bounds."); throw runtime_error("Texture coordinate index out of bounds.");
} }
return mesh.getTexCoord(index); return Vec2(
} mesh.getTexCoord(index).x,
mesh.getTexCoord(index).y);
ofPolyline QuadSurface::getHitArea(){ }
ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); ofPolyline QuadSurface::getHitArea(){
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y));
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y)); line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y));
line.close(); line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y));
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y));
return line; line.close();
}
return line;
ofPolyline QuadSurface::getTextureHitArea(){ }
ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords(); ofPolyline QuadSurface::getTextureHitArea(){
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); ofPolyline line;
for(int i = 0; i < texCoords.size(); i++){ Vec2 textureSize =
line.addVertex(ofPoint(texCoords[i] * textureSize)); Vec2(source->getTexture()->getWidth(),
} source->getTexture()->getHeight());
line.close(); for(int i = 0; i < mesh.getTexCoords().size(); i++){
line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf()));
return line; }
} line.close();
vector <ofVec3f> & QuadSurface::getVertices(){ return line;
// return only joint vertices }
return mesh.getVertices();
} vector <ofVec3f> & QuadSurface::getVertices(){
// return only joint vertices
vector <ofVec2f> & QuadSurface::getTexCoords(){ return mesh.getVertices();
return mesh.getTexCoords(); }
}
vector <Vec2> & QuadSurface::getTexCoords(){
void QuadSurface::calculateHomography(){ _texCoords.clear();
float src[4][2]; for(auto tc : mesh.getTexCoords()){
float dst[4][2]; _texCoords.push_back(tc);
}
ofRectangle box = getMeshBoundingBox(); return _texCoords;
}
src[0][0] = 0;
src[0][1] = 0; void QuadSurface::calculateHomography(){
src[1][0] = box.width; float src[4][2];
src[1][1] = 0; float dst[4][2];
src[2][0] = box.width;
src[2][1] = box.height; ofRectangle box = getMeshBoundingBox();
src[3][0] = 0;
src[3][1] = box.height; src[0][0] = 0;
src[0][1] = 0;
ofVec3f p0 = mesh.getVertex(0); src[1][0] = box.width;
ofVec3f p1 = mesh.getVertex(1); src[1][1] = 0;
ofVec3f p2 = mesh.getVertex(2); src[2][0] = box.width;
ofVec3f p3 = mesh.getVertex(3); src[2][1] = box.height;
src[3][0] = 0;
dst[0][0] = p0.x; src[3][1] = box.height;
dst[0][1] = p0.y;
dst[1][0] = p1.x; ofVec3f p0 = mesh.getVertex(0);
dst[1][1] = p1.y; ofVec3f p1 = mesh.getVertex(1);
dst[2][0] = p2.x; ofVec3f p2 = mesh.getVertex(2);
dst[2][1] = p2.y; ofVec3f p3 = mesh.getVertex(3);
dst[3][0] = p3.x;
dst[3][1] = p3.y; dst[0][0] = p0.x;
dst[0][1] = p0.y;
HomographyHelper::findHomography(src, dst, _matrix); dst[1][0] = p1.x;
} dst[1][1] = p1.y;
dst[2][0] = p2.x;
void QuadSurface::setPerspectiveWarping(bool b){ dst[2][1] = p2.y;
_perspectiveWarping = b; dst[3][0] = p3.x;
} dst[3][1] = p3.y;
bool QuadSurface::getPerspectiveWarping(){ HomographyHelper::findHomography(src, dst, _matrix);
return _perspectiveWarping; }
}
void QuadSurface::setPerspectiveWarping(bool b){
ofRectangle QuadSurface::getMeshBoundingBox(){ _perspectiveWarping = b;
float minX = 10000.0f; }
float minY = 10000.0f;
float maxX = 0.0f; bool QuadSurface::getPerspectiveWarping(){
float maxY = 0.0f; return _perspectiveWarping;
}
for(int i = 0; i < mesh.getVertices().size(); ++i){
if(mesh.getVertices()[i].x < minX){ ofRectangle QuadSurface::getMeshBoundingBox(){
minX = mesh.getVertices()[i].x; float minX = 10000.0f;
} float minY = 10000.0f;
float maxX = 0.0f;
if(mesh.getVertices()[i].y < minY){ float maxY = 0.0f;
minY = mesh.getVertices()[i].y;
} for(int i = 0; i < mesh.getVertices().size(); ++i){
if(mesh.getVertices()[i].x < minX){
if(mesh.getVertices()[i].x > maxX){ minX = mesh.getVertices()[i].x;
maxX = mesh.getVertices()[i].x; }
}
if(mesh.getVertices()[i].y < minY){
if(mesh.getVertices()[i].y > maxY){ minY = mesh.getVertices()[i].y;
maxY = mesh.getVertices()[i].y; }
}
} if(mesh.getVertices()[i].x > maxX){
maxX = mesh.getVertices()[i].x;
ofRectangle boundingBox = ofRectangle(ofPoint(minX, minY), ofPoint(maxX, maxY)); }
return boundingBox;
} if(mesh.getVertices()[i].y > maxY){
maxY = mesh.getVertices()[i].y;
BaseSurface * QuadSurface::clone(){ }
QuadSurface * s = new QuadSurface(); }
s->setVertices(getVertices());
s->setTexCoords(getTexCoords()); ofRectangle boundingBox = ofRectangle(ofPoint(minX, minY), ofPoint(maxX, maxY));
s->setPerspectiveWarping(getPerspectiveWarping()); return boundingBox;
BaseSource * src = getSource(); }
src->referenceCount++;
s->setSource(src); BaseSurface * QuadSurface::clone(){
return s; QuadSurface * s = new QuadSurface();
} s->setVertices(getVertices());
s->setTexCoords(getTexCoords());
} // namespace piMapper s->setPerspectiveWarping(getPerspectiveWarping());
} // namespace ofx BaseSource * src = getSource();
src->referenceCount++;
s->setSource(src);
return s;
}
} // namespace piMapper
} // namespace ofx

111
src/Surfaces/QuadSurface.h

@ -1,55 +1,56 @@
#pragma once #pragma once
#include "ofMain.h" #include "ofMain.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "HomographyHelper.h" #include "HomographyHelper.h"
#include "Vec2.h"
namespace ofx {
namespace piMapper { namespace ofx {
namespace piMapper {
class QuadSurface : public BaseSurface {
public: class QuadSurface : public BaseSurface {
QuadSurface(); public:
~QuadSurface(); QuadSurface();
~QuadSurface();
void setup();
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, ofVec2f t1, void setup();
ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource * newSource); void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, Vec2 t1,
Vec2 t2, Vec2 t3, Vec2 t4, BaseSource * newSource);
void draw();
void draw();
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v); void setVertex(int index, Vec2 p);
void setVertices(vector<ofVec3f> v); void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t); void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<Vec2> t);
void moveBy(ofVec2f v);
void moveBy(Vec2 v);
int getType();
bool hitTest(ofVec2f p); int getType();
ofVec2f getVertex(int index); bool hitTest(Vec2 p);
ofVec2f getTexCoord(int index); Vec2 getVertex(int index);
ofPolyline getHitArea(); Vec2 getTexCoord(int index);
ofPolyline getTextureHitArea(); ofPolyline getHitArea();
vector <ofVec3f> & getVertices(); ofPolyline getTextureHitArea();
vector <ofVec2f> & getTexCoords(); vector <ofVec3f> & getVertices();
vector <Vec2> & getTexCoords();
void setPerspectiveWarping(bool b);
bool getPerspectiveWarping(); void setPerspectiveWarping(bool b);
bool getPerspectiveWarping();
ofRectangle getMeshBoundingBox();
ofRectangle getMeshBoundingBox();
BaseSurface * clone();
BaseSurface * clone();
private:
void calculateHomography(); private:
void calculateHomography();
float _matrix[16];
bool _perspectiveWarping; float _matrix[16];
}; bool _perspectiveWarping;
};
} // namespace piMapper
} // namespace ofx } // namespace piMapper
} // namespace ofx

36
src/Surfaces/SurfaceFactory.cpp

@ -29,16 +29,16 @@ BaseSurface * SurfaceFactory::createSurface(SurfaceType type){
} }
TriangleSurface * SurfaceFactory::createTriangleSurface(){ TriangleSurface * SurfaceFactory::createTriangleSurface(){
vector <ofVec2f> vertices; vector <Vec2> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); vertices.push_back(Vec2((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
texCoords.push_back(ofVec2f(0.5f, 0.0f)); texCoords.push_back(Vec2(0.5f, 0.0f));
texCoords.push_back(ofVec2f(1.0f, 1.0f)); texCoords.push_back(Vec2(1.0f, 1.0f));
texCoords.push_back(ofVec2f(0.0f, 1.0f)); texCoords.push_back(Vec2(0.0f, 1.0f));
TriangleSurface * triangleSurface = new TriangleSurface(); TriangleSurface * triangleSurface = new TriangleSurface();
@ -51,18 +51,18 @@ TriangleSurface * SurfaceFactory::createTriangleSurface(){
} }
QuadSurface * SurfaceFactory::createQuadSurface(){ QuadSurface * SurfaceFactory::createQuadSurface(){
vector <ofVec2f> vertices; vector <Vec2> vertices;
float margin = 50.0f; float margin = 50.0f;
vertices.push_back(ofVec2f(margin, margin)); vertices.push_back(Vec2(margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); vertices.push_back(Vec2((float)ofGetWidth() - margin, margin));
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin));
vector <ofVec2f> texCoords; vector <Vec2> texCoords;
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); texCoords.push_back(Vec2(Vec2(0.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); texCoords.push_back(Vec2(Vec2(1.0f, 0.0f)));
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); texCoords.push_back(Vec2(Vec2(1.0f, 1.0f)));
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); texCoords.push_back(Vec2(Vec2(0.0f, 1.0f)));
QuadSurface * quadSurface = new QuadSurface(); QuadSurface * quadSurface = new QuadSurface();
quadSurface->setPerspectiveWarping(true); quadSurface->setPerspectiveWarping(true);

6
src/Surfaces/SurfaceManager.cpp

@ -303,14 +303,14 @@ void SurfaceManager::selectVertex(int i){
ofNotifyEvent(vertexSelectedEvent, _selectedVertexIndex, this); ofNotifyEvent(vertexSelectedEvent, _selectedVertexIndex, this);
} }
void SurfaceManager::moveSelectionBy(ofVec2f v){ void SurfaceManager::moveSelectionBy(Vec2 v){
if(selectedSurface == 0){ if(selectedSurface == 0){
moveAllSurfacesBy(v); moveAllSurfacesBy(v);
return; return;
} }
if(_selectedVertexIndex != -1){ if(_selectedVertexIndex != -1){
selectedSurface->getVertices()[_selectedVertexIndex] += v; selectedSurface->getVertices()[_selectedVertexIndex] += v.toOf();
ofNotifyEvent(vertexChangedEvent, _selectedVertexIndex, this); ofNotifyEvent(vertexChangedEvent, _selectedVertexIndex, this);
}else{ }else{
selectedSurface->moveBy(v); selectedSurface->moveBy(v);
@ -321,7 +321,7 @@ void SurfaceManager::moveSelectionBy(ofVec2f v){
// it could be implemented as vector here. // it could be implemented as vector here.
} }
void SurfaceManager::moveAllSurfacesBy(ofVec2f v){ void SurfaceManager::moveAllSurfacesBy(Vec2 v){
if(_activePresetIndex < 0){ if(_activePresetIndex < 0){
ofLogWarning( ofLogWarning(
"SurfaceManager::moveAllSurfacesBy", "SurfaceManager::moveAllSurfacesBy",

7
src/Surfaces/SurfaceManager.h

@ -9,6 +9,7 @@
#include "SourceType.h" #include "SourceType.h"
#include "SurfaceStack.h" #include "SurfaceStack.h"
#include "SurfaceFactory.h" #include "SurfaceFactory.h"
#include "Vec2.h"
#include "ofEvents.h" #include "ofEvents.h"
#include "ofxXmlSettings.h" #include "ofxXmlSettings.h"
@ -50,8 +51,8 @@ class SurfaceManager {
void selectPrevVertex(); void selectPrevVertex();
void selectVertex(int i); void selectVertex(int i);
void moveSelectionBy(ofVec2f v); void moveSelectionBy(Vec2 v);
void moveAllSurfacesBy(ofVec2f v); void moveAllSurfacesBy(Vec2 v);
int size(); int size();
int getSelectedVertexIndex(); int getSelectedVertexIndex();
@ -90,4 +91,4 @@ class SurfaceManager {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

77
src/Surfaces/TriangleSurface.cpp

@ -11,20 +11,20 @@ TriangleSurface::~TriangleSurface(){}
void TriangleSurface::setup(){ void TriangleSurface::setup(){
// Create 3 points for the triangle // Create 3 points for the triangle
ofVec2f p1 = ofVec2f(ofGetWidth() / 2.0f, 0); Vec2 p1 = Vec2(ofGetWidth() / 2.0f, 0);
ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); Vec2 p2 = Vec2(Vec2(0, ofGetHeight()));
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight());
// Create 3 point for the texture coordinates // Create 3 point for the texture coordinates
ofVec2f t1 = ofVec2f(0.5f, 0); Vec2 t1 = Vec2(0.5f, 0);
ofVec2f t2 = ofVec2f(0, 1.0f); Vec2 t2 = Vec2(0, 1.0f);
ofVec2f t3 = ofVec2f(1, 1.0f); Vec2 t3 = Vec2(1, 1.0f);
setup(p1, p2, p3, t1, t2, t3, source); setup(p1, p2, p3, t1, t2, t3, source);
} }
void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, void TriangleSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1,
ofVec2f t2, ofVec2f t3, BaseSource * newSource){ Vec2 t2, Vec2 t3, BaseSource * newSource){
// Assign texture // Assign texture
source = newSource; source = newSource;
@ -32,14 +32,14 @@ void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1,
mesh.clear(); mesh.clear();
// Create a surface with the points // Create a surface with the points
mesh.addVertex(p1); mesh.addVertex(p1.toOf());
mesh.addVertex(p2); mesh.addVertex(p2.toOf());
mesh.addVertex(p3); mesh.addVertex(p3.toOf());
// Add texture coordinates // Add texture coordinates
mesh.addTexCoord(t1); mesh.addTexCoord(t1.toOf());
mesh.addTexCoord(t2); mesh.addTexCoord(t2.toOf());
mesh.addTexCoord(t3); mesh.addTexCoord(t3.toOf());
} }
void TriangleSurface::draw(){ void TriangleSurface::draw(){
@ -63,24 +63,24 @@ void TriangleSurface::draw(){
} }
} }
void TriangleSurface::setVertex(int index, ofVec2f p){ void TriangleSurface::setVertex(int index, Vec2 p){
if(index > 2){ if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
return; return;
} }
mesh.setVertex(index, p); mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index); ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this); ofNotifyEvent(vertexChangedEvent, index, this);
} }
void TriangleSurface::setVertices(vector<ofVec2f> v){ void TriangleSurface::setVertices(vector<Vec2> v){
if(v.size() != 3){ if(v.size() != 3){
throw runtime_error("Wrong number of vertices"); throw runtime_error("Wrong number of vertices");
} }
for(int i = 0; i < 3; ++i){ for(int i = 0; i < 3; ++i){
mesh.setVertex(i, v[i]); mesh.setVertex(i, v[i].toOf());
} }
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
@ -98,30 +98,30 @@ void TriangleSurface::setVertices(vector<ofVec3f> v){
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
} }
void TriangleSurface::setTexCoord(int index, ofVec2f t){ void TriangleSurface::setTexCoord(int index, Vec2 t){
if(index > 2){ if(index > 2){
ofLog() << "Texture coordinate with this index does not exist: " << index ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl; << endl;
return; return;
} }
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t.toOf());
} }
void TriangleSurface::setTexCoords(vector<ofVec2f> t){ void TriangleSurface::setTexCoords(vector<Vec2> t){
if(t.size() != 3){ if(t.size() != 3){
throw runtime_error("Wrong number of texture coordinates"); throw runtime_error("Wrong number of texture coordinates");
} }
for(int i = 0; i < 3; ++i){ for(int i = 0; i < 3; ++i){
mesh.setTexCoord(i, t[i]); mesh.setTexCoord(i, t[i].toOf());
} }
} }
void TriangleSurface::moveBy(ofVec2f v){ void TriangleSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices(); vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){ for(int i = 0; i < vertices.size(); i++){
vertices[i] += v; vertices[i] += v.toOf();
} }
setMoved(true); setMoved(true);
@ -132,7 +132,7 @@ int TriangleSurface::getType(){
return SurfaceType::TRIANGLE_SURFACE; return SurfaceType::TRIANGLE_SURFACE;
} }
bool TriangleSurface::hitTest(ofVec2f p){ bool TriangleSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
@ -143,22 +143,24 @@ bool TriangleSurface::hitTest(ofVec2f p){
} }
} }
ofVec2f TriangleSurface::getVertex(int index){ Vec2 TriangleSurface::getVertex(int index){
if(index > 2){ if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl; ofLog() << "Vertex with this index does not exist: " << index << endl;
throw runtime_error("Vertex index out of bounds."); throw runtime_error("Vertex index out of bounds.");
} }
ofVec3f vert = mesh.getVertex(index); ofVec3f vert = mesh.getVertex(index);
return ofVec2f(vert.x, vert.y); return Vec2(vert.x, vert.y);
} }
ofVec2f TriangleSurface::getTexCoord(int index){ Vec2 TriangleSurface::getTexCoord(int index){
if(index > 2){ if(index > 2){
throw runtime_error("Texture coordinate index out of bounds."); throw runtime_error("Texture coordinate index out of bounds.");
} }
return mesh.getTexCoord(index); return Vec2(
mesh.getTexCoord(index).x,
mesh.getTexCoord(index).y);
} }
ofPolyline TriangleSurface::getHitArea(){ ofPolyline TriangleSurface::getHitArea(){
@ -173,10 +175,9 @@ ofPolyline TriangleSurface::getHitArea(){
ofPolyline TriangleSurface::getTextureHitArea(){ ofPolyline TriangleSurface::getTextureHitArea(){
ofPolyline line; ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords(); Vec2 textureSize = Vec2(source->getTexture()->getWidth(), source->getTexture()->getHeight());
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); for(int i = 0; i < mesh.getTexCoords().size(); i++){
for(int i = 0; i < texCoords.size(); i++){ line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf()));
line.addVertex(ofPoint(texCoords[i] * textureSize));
} }
line.close(); line.close();
@ -188,8 +189,12 @@ vector <ofVec3f> & TriangleSurface::getVertices(){
return mesh.getVertices(); return mesh.getVertices();
} }
vector <ofVec2f> & TriangleSurface::getTexCoords(){ vector <Vec2> & TriangleSurface::getTexCoords(){
return mesh.getTexCoords(); _texCoords.clear();
for(auto tc : mesh.getTexCoords()){
_texCoords.push_back(tc);
}
return _texCoords;
} }
BaseSurface * TriangleSurface::clone(){ BaseSurface * TriangleSurface::clone(){
@ -203,4 +208,4 @@ BaseSurface * TriangleSurface::clone(){
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

25
src/Surfaces/TriangleSurface.h

@ -3,6 +3,7 @@
#include "ofMain.h" #include "ofMain.h"
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -13,30 +14,30 @@ class TriangleSurface : public BaseSurface {
~TriangleSurface(); ~TriangleSurface();
void setup(); void setup();
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1, Vec2 t2,
ofVec2f t3, BaseSource * newSource); Vec2 t3, BaseSource * newSource);
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, Vec2 p);
void setVertices(vector<ofVec2f> v); void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v); void setVertices(vector<ofVec3f> v);
void setTexCoord(int index, ofVec2f t); void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<ofVec2f> t); void setTexCoords(vector<Vec2> t);
void moveBy(ofVec2f v); void moveBy(Vec2 v);
int getType(); int getType();
bool hitTest(ofVec2f p); bool hitTest(Vec2 p);
ofVec2f getVertex(int index); Vec2 getVertex(int index);
ofVec2f getTexCoord(int index); Vec2 getTexCoord(int index);
ofPolyline getHitArea(); ofPolyline getHitArea();
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
vector <ofVec3f> & getVertices(); vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords(); vector <Vec2> & getTexCoords();
BaseSurface * clone(); BaseSurface * clone();
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

95
src/Types/Vec2.cpp

@ -0,0 +1,95 @@
#include "Vec2.h"
namespace ofx {
namespace piMapper {
Vec2::Vec2(){
x = 0.0f;
y = 0.0f;
}
Vec2::Vec2(float $x, float $y){
x = $x;
y = $y;
}
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec2::Vec2(ofVec2f & src){
x = src.x;
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<ofVec2f> Vec2::toOf(vector<Vec2> & src){
vector<ofVec2f> dst;
for(auto v : src){
dst.push_back(ofVec2f(v.x, v.y));
}
return dst;
}
float Vec2::distance(Vec2 & other){
ofVec2f v1(x, y);
ofVec2f v2(other.x, other.y);
return v1.distance(v2);
}
#else
// TODO: The same for glm::vec2
#endif
void Vec2::operator=(const Vec2 & other){
x = other.x;
y = other.y;
}
void Vec2::operator=(const ofVec3f & other){
x = other.x;
y = other.y;
}
void Vec2::operator+=(Vec2 & other){
x += other.x;
y += other.y;
}
Vec2 Vec2::operator+(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*(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);
}
bool Vec2::operator!=(Vec2 & other){
if(x == other.x && y == other.y){
return false;
}
return true;
}
} // namespace piMapper
} // namespace ofx

49
src/Types/Vec2.h

@ -0,0 +1,49 @@
#pragma once
#include "ofMain.h"
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
// ...
#else
// 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);
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec2(ofVec2f & src);
Vec2(ofVec3f & src);
ofVec2f toOf();
static ofVec2f toOf(Vec2 & src);
static vector<ofVec2f> toOf(vector<Vec2> & src);
float distance(Vec2 & other);
#else
// TODO: The same for glm::vec2
// static vector<glm::vec2> toOf(vector<Vec2> & src);
#endif
void operator=(const Vec2 & other);
void operator=(const ofVec3f & other);
void operator+=(Vec2 & other);
Vec2 operator+(Vec2 & other);
Vec2 operator/(Vec2 & other);
Vec2 operator*(Vec2 & other);
Vec2 operator-();
Vec2 operator-(Vec2 & other);
bool operator!=(Vec2 & other);
float x;
float y;
};
} // namespace piMapper
} // namespace ofx

82
src/Types/Vec3.cpp

@ -0,0 +1,82 @@
#include "Vec3.h"
namespace ofx {
namespace piMapper {
Vec3::Vec3(){
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
Vec3::Vec3(float $x, float $y, float $z){
x = $x;
y = $y;
z = $z;
}
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec3::Vec3(ofVec3f & src){
x = src.x;
y = src.y;
z = src.z;
}
ofVec3f Vec3::toOf(){
ofVec3f(x, y, z);
}
ofVec3f toOf(Vec3 & src){
return ofVec3f(src.x, src.y, src.z);
}
vector<ofVec3f> toOf(vector<Vec3> & src){
vector<ofVec3f> dst;
for(auto v : src){
dst.push_back(ofVec3f(v.x, v.y, v.z));
}
return dst;
}
#else
// TODO: The same for glm::vec2
#endif
void Vec3::operator=(const Vec3 & other){
x = other.x;
y = other.y;
z = other.z;
}
void Vec3::operator=(const ofVec3f & 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);
}
Vec3 Vec3::operator-(){
return Vec3(-x, -y, -z);
}
Vec3 Vec3::operator-(Vec3 & other){
return Vec3(
x - other.x,
y - other.y,
z - other.z);
}
bool Vec3::operator!=(Vec3 & other){
if(x == other.x && y == other.y && z == other.z){
return false;
}
return true;
}
} // namespace piMapper
} // namespace ofx

43
src/Types/Vec3.h

@ -0,0 +1,43 @@
#pragma once
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
#include "ofMain.h"
#else
// TODO: include glm
#endif
namespace ofx {
namespace piMapper {
class Vec3{
public:
Vec3();
Vec3(float $x, float $y, float $z);
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec3(ofVec3f & src);
ofVec3f toOf();
static ofVec3f toOf(Vec3 & src);
static vector<ofVec3f> toOf(vector<Vec3> & src);
#else
// TODO: The same for glm::vec2
// static vector<glm::vec2> toOf(vector<Vec2> & src);
#endif
void operator=(const Vec3 & other);
void operator=(const ofVec3f & other);
Vec3 operator+(Vec3 & other);
Vec3 operator-();
Vec3 operator-(Vec3 & other);
bool operator!=(Vec3 & other);
float x;
float y;
float z;
};
} // namespace piMapper
} // namespace ofx

15
src/UserInterface/BaseJoint.cpp

@ -9,8 +9,9 @@ BaseJoint::BaseJoint(){
} }
void BaseJoint::mousePressed(ofMouseEventArgs & args){ void BaseJoint::mousePressed(ofMouseEventArgs & args){
if(hitTest(ofVec2f(args.x, args.y))){ if(hitTest(Vec2(args.x, args.y))){
clickDistance = position - ofVec2f(args.x, args.y); Vec2 clickPosition(args.x, args.y);
clickDistance = position - clickPosition;
} }
} }
@ -22,7 +23,7 @@ void BaseJoint::mouseDragged(ofMouseEventArgs & args){
if(!bDrag){ if(!bDrag){
return; return;
} }
position = ofVec2f(args.x, args.y) + clickDistance; position = Vec2(args.x, args.y) + clickDistance;
} }
void BaseJoint::startDrag(){ void BaseJoint::startDrag(){
@ -41,7 +42,7 @@ void BaseJoint::unselect(){
selected = false; selected = false;
} }
void BaseJoint::setClickDistance(ofVec2f newClickDistance){ void BaseJoint::setClickDistance(Vec2 newClickDistance){
clickDistance = newClickDistance; clickDistance = newClickDistance;
} }
@ -63,12 +64,12 @@ void BaseJoint::setDefaultColors(){
void BaseJoint::setDefaultProperties(){ void BaseJoint::setDefaultProperties(){
enabled = true; enabled = true;
visible = true; visible = true;
position = ofVec2f(20.0f, 20.0f); position = Vec2(20.0f, 20.0f);
clickDistance = ofVec2f(0.0f, 0.0f); clickDistance = Vec2(0.0f, 0.0f);
bDrag = false; bDrag = false;
selected = false; selected = false;
strokeWidth = 1.5f; strokeWidth = 1.5f;
} }
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

9
src/UserInterface/BaseJoint.h

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ofMain.h" #include "ofMain.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -10,7 +11,7 @@ class BaseJoint {
public: public:
BaseJoint(); BaseJoint();
ofVec2f position; Vec2 position;
bool enabled; bool enabled;
bool visible; bool visible;
bool selected; bool selected;
@ -22,13 +23,13 @@ class BaseJoint {
void stopDrag(); void stopDrag();
void select(); void select();
void unselect(); void unselect();
void setClickDistance(ofVec2f newClickDistance); void setClickDistance(Vec2 newClickDistance);
bool isDragged(); bool isDragged();
bool isSelected(); bool isSelected();
virtual void update(){} virtual void update(){}
virtual void draw(){} virtual void draw(){}
virtual bool hitTest(ofVec2f position){ return false; } virtual bool hitTest(Vec2 position){ return false; }
protected: protected:
ofColor fillColor; ofColor fillColor;
@ -36,7 +37,7 @@ class BaseJoint {
ofColor fillColorSelected; ofColor fillColorSelected;
ofColor strokeColorSelected; ofColor strokeColorSelected;
float strokeWidth; float strokeWidth;
ofVec2f clickDistance; // How far from the center of the joint the user has Vec2 clickDistance; // How far from the center of the joint the user has
// clicked? // clicked?
bool bDrag; bool bDrag;

2
src/UserInterface/CircleJoint.cpp

@ -59,7 +59,7 @@ void CircleJoint::setDefaultProperties(){
radius = 10.0f; radius = 10.0f;
} }
bool CircleJoint::hitTest(ofVec2f pos){ bool CircleJoint::hitTest(Vec2 pos){
float distance = position.distance(pos); float distance = position.distance(pos);
if(distance < radius){ if(distance < radius){
return true; return true;

5
src/UserInterface/CircleJoint.h

@ -2,6 +2,7 @@
#include "ofMain.h" #include "ofMain.h"
#include "BaseJoint.h" #include "BaseJoint.h"
#include "Vec2.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
@ -12,7 +13,7 @@ class CircleJoint : public BaseJoint {
void update(); void update();
void draw(); void draw();
bool hitTest(ofVec2f position); bool hitTest(Vec2 position);
private: private:
float radius; float radius;
@ -22,4 +23,4 @@ class CircleJoint : public BaseJoint {
}; };
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

2
src/ofxPiMapper.cpp

@ -147,7 +147,7 @@ void ofxPiMapper::togglePause(){
_application.togglePause(); _application.togglePause();
} }
void ofxPiMapper::moveSelection(ofVec2f by){ void ofxPiMapper::moveSelection(ofx::piMapper::Vec2 by){
_application.moveSelection(by); _application.moveSelection(by);
} }

3
src/ofxPiMapper.h

@ -6,6 +6,7 @@
#include "Application.h" #include "Application.h"
#include "SurfaceType.h" #include "SurfaceType.h"
#include "Mode.h" #include "Mode.h"
#include "Vec2.h"
class ofxPiMapper { class ofxPiMapper {
public: public:
@ -66,7 +67,7 @@ class ofxPiMapper {
void scaleDown(); void scaleDown();
void togglePauseForSurface(unsigned int i); void togglePauseForSurface(unsigned int i);
void togglePause(); void togglePause();
void moveSelection(ofVec2f by); void moveSelection(ofx::piMapper::Vec2 by);
void createSurface(ofx::piMapper::SurfaceType type); void createSurface(ofx::piMapper::SurfaceType type);
void eraseSurface(int i); void eraseSurface(int i);

Loading…
Cancel
Save