Browse Source

Update code to use Vec3 and Vec2 everywhere

master
Krisjanis Rijnieks 8 years ago
parent
commit
9966ecf83a
  1. 5
      src/Application/Application.cpp
  2. 2
      src/Application/Application.h
  3. 21
      src/Application/Modes/ProjectionMappingMode.cpp
  4. 1
      src/Application/Modes/ProjectionMappingMode.h
  5. 2
      src/Application/Modes/TextureMappingMode.cpp
  6. 74
      src/Application/SettingsLoader.cpp
  7. 1
      src/Application/SettingsLoader.h
  8. 6
      src/Commands/AddGridColCmd.cpp
  9. 5
      src/Commands/AddGridColCmd.h
  10. 6
      src/Commands/AddGridRowCmd.cpp
  11. 3
      src/Commands/AddGridRowCmd.h
  12. 2
      src/Commands/DuplicateSurfaceCmd.cpp
  13. 2
      src/Commands/DuplicateSurfaceCmd.h
  14. 2
      src/Commands/MvSelectionCmd.cpp
  15. 6
      src/Commands/MvSelectionCmd.h
  16. 4
      src/Commands/MvSurfaceVertCmd.h
  17. 8
      src/Commands/RmGridColCmd.cpp
  18. 3
      src/Commands/RmGridColCmd.h
  19. 8
      src/Commands/RmGridRowCmd.cpp
  20. 3
      src/Commands/RmGridRowCmd.h
  21. 4
      src/Commands/StartDragSurfaceCmd.cpp
  22. 4
      src/Commands/StartDragSurfaceCmd.h
  23. 35
      src/Gui/Widgets/ProjectionEditorWidget.cpp
  24. 5
      src/Gui/Widgets/ProjectionEditorWidget.h
  25. 26
      src/Gui/Widgets/TextureEditorWidget.cpp
  26. 38
      src/Surfaces/BaseSurface.cpp
  27. 29
      src/Surfaces/BaseSurface.h
  28. 11
      src/Surfaces/CircleSurface.cpp
  29. 2
      src/Surfaces/CircleSurface.h
  30. 52
      src/Surfaces/GridWarpSurface.cpp
  31. 16
      src/Surfaces/GridWarpSurface.h
  32. 75
      src/Surfaces/HexagonSurface.cpp
  33. 19
      src/Surfaces/HexagonSurface.h
  34. 90
      src/Surfaces/QuadSurface.cpp
  35. 26
      src/Surfaces/QuadSurface.h
  36. 18
      src/Surfaces/SurfaceFactory.cpp
  37. 8
      src/Surfaces/SurfaceManager.cpp
  38. 8
      src/Surfaces/SurfaceManager.h
  39. 2
      src/Surfaces/SurfaceStack.cpp
  40. 4
      src/Surfaces/SurfaceStack.h
  41. 80
      src/Surfaces/TriangleSurface.cpp
  42. 22
      src/Surfaces/TriangleSurface.h
  43. 74
      src/Types/Vec2.cpp
  44. 35
      src/Types/Vec2.h
  45. 111
      src/Types/Vec3.cpp
  46. 34
      src/Types/Vec3.h
  47. 2
      src/ofxPiMapper.cpp
  48. 3
      src/ofxPiMapper.h

5
src/Application/Application.cpp

@ -356,13 +356,14 @@ void Application::selectPrevTexCoord(){
}
}
void Application::moveSelection(Vec2 by){
void Application::moveSelection(Vec3 by){
if(_state == ProjectionMappingMode::instance()){
getCmdManager()->exec(new MvSelectionCmd(getSurfaceManager(), by));
}else if(_state == TextureMappingMode::instance()){
Vec2 tcBy(by.x, by.y);
int selectedTexCoord = Gui::instance()->getTextureEditorWidget().getSelectedTexCoord();
if(selectedTexCoord >= 0){
moveTexCoord(selectedTexCoord, by);
moveTexCoord(selectedTexCoord, tcBy);
}
}
}

2
src/Application/Application.h

@ -114,7 +114,7 @@ class Application {
Moves vertex when in projection mapping mode.
Moves texture coordinate when in texture mapping mode.
*/
void moveSelection(Vec2 by);
void moveSelection(Vec3 by);
void setPresentationMode();
void setTextureMode();

21
src/Application/Modes/ProjectionMappingMode.cpp

@ -114,33 +114,33 @@ void ProjectionMappingMode::onKeyPressed(Application * app, ofKeyEventArgs & arg
case OF_KEY_UP:
if(app->isShiftKeyDown()){
app->moveSelection(Vec2(0.0f, -10.0f));
app->moveSelection(Vec3(0.0f, -10.0f, 0.0f));
}else{
app->moveSelection(Vec2(0.0f, -1.0f));
app->moveSelection(Vec3(0.0f, -1.0f, 0.0f));
}
break;
case OF_KEY_DOWN:
if(app->isShiftKeyDown()){
app->moveSelection(Vec2(0.0f, 10.0f));
app->moveSelection(Vec3(0.0f, 10.0f, 0.0f));
}else{
app->moveSelection(Vec2(0.0f, 1.0f));
app->moveSelection(Vec3(0.0f, 1.0f, 0.0f));
}
break;
case OF_KEY_LEFT:
if(app->isShiftKeyDown()){
app->moveSelection(Vec2(-10.0f, 0.0f));
app->moveSelection(Vec3(-10.0f, 0.0f, 0.0f));
}else{
app->moveSelection(Vec2(-1.0f, 0.0f));
app->moveSelection(Vec3(-1.0f, 0.0f, 0.0f));
}
break;
case OF_KEY_RIGHT:
if(app->isShiftKeyDown()){
app->moveSelection(Vec2(10.0f, 0.0f));
app->moveSelection(Vec3(10.0f, 0.0f, 0.0f));
}else{
app->moveSelection(Vec2(1.0f, 0.0f));
app->moveSelection(Vec3(1.0f, 0.0f, 0.0f));
}
break;
@ -242,7 +242,10 @@ void ProjectionMappingMode::onMouseDragged(Application * app, ofMouseEventArgs &
if(_bSurfaceDrag){
Vec2 mousePosition = Vec2(args.x, args.y);
Vec2 distance = mousePosition - _clickPosition;
Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(distance);
Gui::instance()->getProjectionEditorWidget().moveSelectedSurface(Vec3(
distance.x,
distance.y,
0.0f));
_clickPosition = mousePosition;
}
}

1
src/Application/Modes/ProjectionMappingMode.h

@ -10,6 +10,7 @@
#include "Gui.h"
#include "ScaleWidget.h"
#include "Vec2.h"
#include "Vec3.h"
namespace ofx {
namespace piMapper {

2
src/Application/Modes/TextureMappingMode.cpp

@ -264,7 +264,7 @@ void TextureMappingMode::drawTexture(Application * app){
ofEnableNormalizedTexCoords();
ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->getSelectedSurface()->drawTexture(Vec2(0, 0));
app->getSurfaceManager()->getSelectedSurface()->drawTexture(Vec3(0.0f, 0.0f, 0.0f));
if(!normalizedTexCoords){
ofDisableNormalizedTexCoords();

74
src/Application/SettingsLoader.cpp

@ -178,11 +178,11 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->pushTag("surface", i);
xmlSettings->addTag("vertices");
xmlSettings->pushTag("vertices");
vector <ofVec3f> * vertices = &surface->getVertices();
for(int j = 0; j < vertices->size(); j++){
vector<Vec3> vertices = surface->getVertices();
for(int j = 0; j < vertices.size(); j++){
xmlSettings->addTag("vertex");
xmlSettings->pushTag("vertex", j);
ofVec3f * vertex = &(*vertices)[j];
Vec3 * vertex = &vertices[j];
xmlSettings->addValue("x", vertex->x);
xmlSettings->addValue("y", vertex->y);
@ -194,11 +194,11 @@ bool SettingsLoader::save(SurfaceManager & surfaceManager, string fileName){
xmlSettings->addTag("texCoords");
xmlSettings->pushTag("texCoords");
vector <Vec2> * texCoords = &surface->getTexCoords();
for(int j = 0; j < texCoords->size(); j++){
vector<Vec2> texCoords = surface->getTexCoords();
for(int j = 0; j < texCoords.size(); j++){
xmlSettings->addTag("texCoord");
xmlSettings->pushTag("texCoord", j);
Vec2 * texCoord = &(*texCoords)[j];
Vec2 * texCoord = &texCoords[j];
xmlSettings->addValue("x", texCoord->x);
xmlSettings->addValue("y", texCoord->y);
xmlSettings->popTag(); // texCoord
@ -252,29 +252,35 @@ bool SettingsLoader::create(string fileName){
}
BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
vector <Vec2> vertices;
vector <Vec3> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 1)){
xmlSettings->pushTag("vertex", 1);
vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 2)){
xmlSettings->pushTag("vertex", 2);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f),
0.0f));
xmlSettings->popTag();
}
@ -321,36 +327,44 @@ BaseSurface * SettingsLoader::getTriangleSurface(ofxXmlSettings * xmlSettings){
}
BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
vector <Vec2> vertices;
vector<Vec3> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
if(xmlSettings->tagExists("vertex", 0)){
xmlSettings->pushTag("vertex", 0);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 1)){
xmlSettings->pushTag("vertex", 1);
vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 2)){
xmlSettings->pushTag("vertex", 2);
vertices.push_back(Vec2(xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 100.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 100.0f),
xmlSettings->getValue("y", 100.0f),
0.0f));
xmlSettings->popTag();
}
if(xmlSettings->tagExists("vertex", 3)){
xmlSettings->pushTag("vertex", 3);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 100.0f),
0.0f));
xmlSettings->popTag();
}
@ -415,7 +429,7 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){
}
BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
vector <Vec2> vertices;
vector <Vec3> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
@ -424,8 +438,10 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
while(xmlSettings->tagExists("vertex", iv)){
xmlSettings->pushTag("vertex", iv);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag();
++iv;
}
@ -476,7 +492,7 @@ BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){
}
BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
vector <Vec2> vertices;
vector <Vec3> vertices;
if(xmlSettings->tagExists("vertices")){
xmlSettings->pushTag("vertices");
@ -484,8 +500,10 @@ BaseSurface * SettingsLoader::getHexagonSurface(ofxXmlSettings * xmlSettings){
unsigned int v = 0;
while(xmlSettings->tagExists("vertex", v)){
xmlSettings->pushTag("vertex", v);
vertices.push_back(Vec2(xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f)));
vertices.push_back(Vec3(
xmlSettings->getValue("x", 0.0f),
xmlSettings->getValue("y", 0.0f),
0.0f));
xmlSettings->popTag(); // vertex
v += 1;
}

1
src/Application/SettingsLoader.h

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

6
src/Commands/AddGridColCmd.cpp

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

5
src/Commands/AddGridColCmd.h

@ -5,6 +5,7 @@
#include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h"
#include "Vec2.h"
#include "Vec3.h"
class ofxPiMapper;
@ -19,8 +20,8 @@ class AddGridColCmd : public BaseUndoCmd {
void undo();
private:
vector <ofVec3f> _vertices;
vector <Vec2> _texCoords;
vector<Vec3> _vertices;
vector<Vec2> _texCoords;
GridWarpSurface * _surface;
};

6
src/Commands/AddGridRowCmd.cpp

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

3
src/Commands/AddGridRowCmd.h

@ -5,6 +5,7 @@
#include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h"
#include "Vec2.h"
#include "Vec3.h"
class ofxPiMapper;
@ -19,7 +20,7 @@ class AddGridRowCmd : public BaseUndoCmd {
void undo();
private:
vector <ofVec3f> _vertices;
vector <Vec3> _vertices;
vector <Vec2> _texCoords;
GridWarpSurface * _surface;

2
src/Commands/DuplicateSurfaceCmd.cpp

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

2
src/Commands/DuplicateSurfaceCmd.h

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

2
src/Commands/MvSelectionCmd.cpp

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

6
src/Commands/MvSelectionCmd.h

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

4
src/Commands/MvSurfaceVertCmd.h

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

8
src/Commands/RmGridColCmd.cpp

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

3
src/Commands/RmGridColCmd.h

@ -5,6 +5,7 @@
#include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h"
#include "Vec2.h"
#include "Vec3.h"
class ofxPiMapper;
@ -19,7 +20,7 @@ class RmGridColCmd : public BaseUndoCmd {
void undo();
private:
vector <ofVec3f> _vertices;
vector <Vec3> _vertices;
vector <Vec2> _texCoords;
GridWarpSurface * _surface;
bool _doNotUndo;

8
src/Commands/RmGridRowCmd.cpp

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

3
src/Commands/RmGridRowCmd.h

@ -5,6 +5,7 @@
#include "GridWarpSurface.h"
#include "ProjectionEditorWidget.h"
#include "Vec2.h"
#include "Vec3.h"
class ofxPiMapper;
@ -19,7 +20,7 @@ class RmGridRowCmd : public BaseUndoCmd {
void undo();
private:
vector <ofVec3f> _vertices;
vector <Vec3> _vertices;
vector <Vec2> _texCoords;
GridWarpSurface * _surface;
bool _doNotUndo;

4
src/Commands/StartDragSurfaceCmd.cpp

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

4
src/Commands/StartDragSurfaceCmd.h

@ -2,7 +2,7 @@
#include "BaseCmd.h"
#include "BaseSurface.h"
#include "Vec2.h"
#include "Vec3.h"
namespace ofx {
namespace piMapper {
@ -16,7 +16,7 @@ class StartDragSurfaceCmd : public BaseUndoCmd {
private:
BaseSurface * _surface;
vector <ofVec3f> _previousVertices;
vector <Vec3> _previousVertices;
};

35
src/Gui/Widgets/ProjectionEditorWidget.cpp

@ -15,7 +15,10 @@ void ProjectionEditorWidget::update(){
if(joints[i]->isDragged() || joints[i]->isSelected()){
if(surfaceManager->getSelectedSurface() != 0){
// update vertex to new location
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position);
surfaceManager->getSelectedSurface()->setVertex(i, Vec3(
joints[i]->position.x,
joints[i]->position.y,
0.0f));
}else{
// clear joints if there is no surface selected
// as the remove selected surface in the surface manager
@ -50,14 +53,16 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){
Vec2 mousePosition = Vec2(args.x, args.y);
// Collect all vertices of the projection surfaces
vector <ofVec3f *> allVertices;
vector<Vec3> allVertices;
for(int i = 0; i < surfaceManager->size(); i++){
BaseSurface * surface = surfaceManager->getSurface(i);
if(surface == surfaceManager->getSelectedSurface()){
continue; // Don't add vertices of selected surface
continue; // Don't add vertices of the selected surface
}
for(int j = 0; j < surface->getVertices().size(); j++){
allVertices.push_back(&surface->getVertices()[j]);
allVertices.push_back(surface->getVertices()[j]);
}
}
@ -65,13 +70,12 @@ void ProjectionEditorWidget::mouseDragged(ofMouseEventArgs & args){
for(int i = 0; i < joints.size(); i++){
if(joints[i]->isDragged()){
for(int j = 0; j < allVertices.size(); j++){
Vec2 v(*allVertices[j]);
Vec2 v(allVertices[j].x, allVertices[j].y);
float distance = mousePosition.distance(v);
if(distance < fSnapDistance){
joints[i]->position = *allVertices[j];
Vec2 jointPosition(joints[i]->position);
Vec2 clickPosition(args.x, args.y);
Vec2 clickDistance = jointPosition - clickPosition;
joints[i]->position = v;
Vec2 clickDistance = joints[i]->position - Vec2(args.x, args.y);
joints[i]->setClickDistance(clickDistance);
break;
}
@ -133,8 +137,7 @@ void ProjectionEditorWidget::createJoints(){
return;
}
vector <ofVec3f> & vertices =
surfaceManager->getSelectedSurface()->getVertices();
vector<Vec3> vertices = surfaceManager->getSelectedSurface()->getVertices();
for(int i = 0; i < vertices.size(); i++){
joints.push_back(new CircleJoint());
@ -144,8 +147,8 @@ void ProjectionEditorWidget::createJoints(){
void ProjectionEditorWidget::updateJoints(){
if(surfaceManager->getSelectedSurface()){
vector <ofVec3f> & vertices =
surfaceManager->getSelectedSurface()->getVertices();
vector<Vec3> vertices = surfaceManager->getSelectedSurface()->getVertices();
for(int i = 0; i < vertices.size(); i++){
joints[i]->position = Vec2(vertices[i].x, vertices[i].y);
}
@ -159,13 +162,15 @@ void ProjectionEditorWidget::unselectAllJoints(){
}
}
void ProjectionEditorWidget::moveSelectedSurface(Vec2 by){
void ProjectionEditorWidget::moveSelectedSurface(Vec3 by){
if(surfaceManager == 0){
return;
}
if(surfaceManager->getSelectedSurface() == 0){
return;
}
surfaceManager->getSelectedSurface()->moveBy(by);
updateJoints();
}
@ -207,7 +212,7 @@ void ProjectionEditorWidget::onVertexChanged(int & i){
}
}
void ProjectionEditorWidget::onVerticesChanged(vector<ofVec3f> & vertices){
void ProjectionEditorWidget::onVerticesChanged(vector<Vec3> & vertices){
createJoints();
}

5
src/Gui/Widgets/ProjectionEditorWidget.h

@ -3,6 +3,7 @@
#include "SurfaceManager.h"
#include "CircleJoint.h"
#include "Vec2.h"
#include "Vec3.h"
namespace ofx {
namespace piMapper {
@ -23,7 +24,7 @@ class ProjectionEditorWidget {
void createJoints();
void updateJoints();
void unselectAllJoints();
void moveSelectedSurface(Vec2 by);
void moveSelectedSurface(Vec3 by);
void stopDragJoints();
void updateVertices();
void setSnapDistance(float newSnapDistance);
@ -31,7 +32,7 @@ class ProjectionEditorWidget {
vector <CircleJoint *> * getJoints();
void onVertexChanged(int & i);
void onVerticesChanged(vector<ofVec3f> & vertices);
void onVerticesChanged(vector<Vec3> & vertices);
void onSurfaceSelected(int & surfaceIndex);
void onVertexSelected(int & vertexIndex);
void onVertexUnselected(int & vertexIndex);

26
src/Gui/Widgets/TextureEditorWidget.cpp

@ -44,9 +44,10 @@ void TextureEditorWidget::update(){
if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){
GridWarpSurface * s = (GridWarpSurface *)surface;
vector <Vec2> & texCoords = surface->getTexCoords();
Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
vector<Vec2> texCoords = surface->getTexCoords();
Vec2 textureSize = Vec2(
surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
int rows = s->getGridRows();
int cols = s->getGridCols();
@ -131,8 +132,9 @@ void TextureEditorWidget::createJoints(){
if(surface == 0){
return;
}
clearJoints();
vector <Vec2> & texCoords = surface->getTexCoords();
vector<Vec2> texCoords = surface->getTexCoords();
if(surface->getSource()->getTexture()->isAllocated()){
_pollCreateJoints = false;
@ -141,11 +143,12 @@ void TextureEditorWidget::createJoints(){
return;
}
Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
Vec2 textureSize = Vec2(
surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
// Select joints depending on the surface type
vector <Vec2> tc;
vector<Vec2> tc;
if(surface->getType() == SurfaceType::TRIANGLE_SURFACE){
tc = texCoords;
@ -279,9 +282,10 @@ void TextureEditorWidget::moveTexCoords(Vec2 by){
return;
}
vector <Vec2> & texCoords = surface->getTexCoords();
Vec2 textureSize = Vec2(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
vector<Vec2> texCoords = surface->getTexCoords();
Vec2 textureSize = Vec2(
surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
for(int i = 0; i < joints.size(); i++){
joints[i]->position += by;
@ -408,4 +412,4 @@ vector <CircleJoint *> & TextureEditorWidget::getJoints(){
}
} // namespace piMapper
} // namespace ofx
} // namespace ofx

38
src/Surfaces/BaseSurface.cpp

@ -21,7 +21,10 @@ void BaseSurface::createDefaultTexture(){
for(int i = 0; i < pixels.size(); i++){
pixels[i] = 255;
}
int squareSize = 10; // size of each test pattern square
// size of each test pattern square
int squareSize = 10;
bool sy = false;
for(int y = 0; y < pixels.getWidth(); y += squareSize){
bool sx = false;
@ -46,53 +49,54 @@ void BaseSurface::createDefaultTexture(){
// load pixels into texture
defaultTexture.loadData(pixels);
// Create new source to be the default
defaultSource = new BaseSource(&defaultTexture);
source = defaultSource;
}
void BaseSurface::drawTexture(Vec2 position){
void BaseSurface::drawTexture(Vec3 position){
if(source->getTexture() == 0){
ofLogWarning("BaseSurface") << "Source texture empty. Not drawing.";
return;
}
// TODO: Do not recreate this in each draw loop
ofMesh texMesh;
texMesh.addVertex(position.toOf());
Vec2 topRight(source->getTexture()->getWidth(), 0.0f);
// Add vertices to the mesh
texMesh.addVertex(position.toOf());
Vec3 topRight(source->getTexture()->getWidth(), 0.0f, 0.0f);
texMesh.addVertex((position + topRight).toOf());
Vec2 bottomRight(source->getTexture()->getWidth(), source->getTexture()->getHeight());
Vec3 bottomRight(source->getTexture()->getWidth(), source->getTexture()->getHeight(), 0.0f);
texMesh.addVertex((position + bottomRight).toOf());
Vec2 bottomLeft(0.0f, source->getTexture()->getHeight());
Vec3 bottomLeft(0.0f, source->getTexture()->getHeight(), 0.0f);
texMesh.addVertex((position + bottomLeft).toOf());
// Make triangles out of added vertices
texMesh.addTriangle(0, 2, 3);
texMesh.addTriangle(0, 1, 2);
// Add texture coordinates for the added vertices
texMesh.addTexCoord(Vec2(0.0f, 0.0f).toOf());
texMesh.addTexCoord(Vec2(1.0f, 0.0f).toOf());
texMesh.addTexCoord(Vec2(1.0f, 1.0f).toOf());
texMesh.addTexCoord(Vec2(0.0f, 1.0f).toOf());
// Draw mesh
source->getTexture()->bind();
texMesh.draw();
source->getTexture()->unbind();
}
//void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; }
void BaseSurface::setSource(BaseSource * newSource){
source = newSource;
}
//ofTexture* BaseSurface::getTexture() { return texture; }
BaseSource * BaseSurface::getSource(){
return source;
}
//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
BaseSource * BaseSurface::getDefaultSource(){
return defaultSource;
}
@ -102,16 +106,20 @@ void BaseSurface::setMoved(bool moved){
}
void BaseSurface::scaleTo(float scale){
ofPoint centroid = getBoundingBox().getCenter();
Vec3 centroid(
getBoundingBox().getCenter().x,
getBoundingBox().getCenter().y,
getBoundingBox().getCenter().z);
for(unsigned int i = 0; i < mesh.getVertices().size(); ++i){
ofVec3f d = (mesh.getVertices()[i] - centroid) / _scale;
Vec3 d = (Vec3(mesh.getVertices()[i]) - centroid) / _scale;
d *= scale;
mesh.getVertices()[i] = centroid + d;
mesh.getVertices()[i] = (centroid + d).toOf();
}
_scale = scale;
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
bool BaseSurface::getMoved(){

29
src/Surfaces/BaseSurface.h

@ -4,6 +4,7 @@
#include <string>
#include "BaseSource.h"
#include "Vec2.h"
#include "Vec3.h"
using namespace std;
@ -18,25 +19,20 @@ class BaseSurface {
virtual void setup() = 0;
virtual void draw() = 0;
virtual void setVertex(int index, Vec2 p) = 0;
virtual void setVertices(vector<Vec2> v) = 0;
virtual void setVertex(int index, Vec3 p) = 0;
virtual void setVertices(vector<Vec3> v) = 0;
virtual void setTexCoord(int index, Vec2 t) = 0;
virtual void setTexCoords(vector<Vec2> t) = 0;
virtual void moveBy(Vec2 v) = 0;
virtual void moveBy(Vec3 v) = 0;
virtual int getType() = 0;
virtual bool hitTest(Vec2 p) = 0;
virtual ofPolyline getHitArea() = 0;
virtual ofPolyline getTextureHitArea() = 0;
virtual vector <ofVec3f> & getVertices() = 0;
virtual vector <Vec2> & getTexCoords() = 0;
virtual vector<Vec3> getVertices() = 0;
virtual vector<Vec2> getTexCoords() = 0;
virtual BaseSurface * clone() = 0;
void drawTexture(Vec2 position);
void drawTexture(Vec3 position);
void setSource(BaseSource * newSource);
void setMoved(bool moved);
void scaleTo(float scale);
@ -50,26 +46,19 @@ class BaseSurface {
ofMesh & getMesh();
ofRectangle & getBoundingBox();
ofEvent <vector<ofVec3f>> verticesChangedEvent;
ofEvent <int> vertexChangedEvent;
ofEvent<vector<Vec3>> verticesChangedEvent;
ofEvent<int> vertexChangedEvent;
protected:
ofMesh mesh;
ofRectangle _boundingBox;
ofTexture defaultTexture;
BaseSource * source;
BaseSource * defaultSource;
void createDefaultTexture();
bool _moved;
float _scale;
vector<Vec2> _texCoords;
};
} // namespace piMapper

11
src/Surfaces/CircleSurface.cpp

@ -1,6 +1,7 @@
//
// CircleSurface.cpp
// Copyright (c) 2017 Cristobal Mendoza
// With modifications by Krisjanis Rijnieks (c) 2017
// http://cuppetellimendoza.com
#include "CircleSurface.h"
@ -19,8 +20,6 @@ CircleSurface::CircleSurface(QuadSurface &surface) {
setPerspectiveWarping(surface.getPerspectiveWarping());
}
CircleSurface::~CircleSurface() {}
void CircleSurface::setup() {
QuadSurface::setup();
@ -264,10 +263,10 @@ void CircleSurface::setupTextures() {
// meshes are similar:
// Create 4 points for the 2 triangles
Vec3 p1 = Vec3(0, 0, 0);
Vec3 p2 = Vec3(0, h, 0);
Vec3 p3 = Vec3(w, h, 0);
Vec3 p4 = Vec3(w, 0, 0);
Vec3 p1 = Vec3(0.0f, 0.0f, 0.0f);
Vec3 p2 = Vec3(0.0f, h, 0.0f);
Vec3 p3 = Vec3(w, h, 0.0f);
Vec3 p4 = Vec3(w, 0.0f, 0.0f);
// Create 4 point for the texture coordinates
Vec2 t1 = Vec2(Vec2(0.0f, 1.0f));

2
src/Surfaces/CircleSurface.h

@ -1,6 +1,7 @@
//
// CircleSurface.h
// Copyright (c) 2017 Cristobal Mendoza
// With modifications by Krisjanis Rijnieks (c) 2017
// http://cuppetellimendoza.com
#ifndef OFXPIMAPPER_CIRCLESURFACE_H
@ -20,7 +21,6 @@ class CircleSurface : public QuadSurface {
CircleSurface();
CircleSurface(QuadSurface &surface);
int getType() override;
~CircleSurface();
void draw() override;
void setup() override;

52
src/Surfaces/GridWarpSurface.cpp

@ -9,10 +9,6 @@ GridWarpSurface::GridWarpSurface(){
createGridMesh();
}
void GridWarpSurface::setup(){
// Nothing here yet
}
void GridWarpSurface::draw(){
if(source->getTexture() == 0){
return;
@ -34,15 +30,14 @@ void GridWarpSurface::draw(){
}
}
void GridWarpSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){
vertices[i] += v.toOf();
void GridWarpSurface::moveBy(Vec3 v){
for(int i = 0; i < mesh.getVertices().size(); i++){
mesh.getVertices()[i] += v.toOf();
}
setMoved(true);
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
int GridWarpSurface::getType(){
@ -146,17 +141,16 @@ ofPolyline GridWarpSurface::getTextureHitArea(){
return line;
}
void GridWarpSurface::setVertex(int index, Vec2 p){
void GridWarpSurface::setVertex(int index, Vec3 vert){
if(index >= mesh.getVertices().size()){
throw runtime_error("Vertex with provided index does not exist");
}
mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index);
mesh.setVertex(index, vert.toOf());
ofNotifyEvent(vertexChangedEvent, index, this);
}
void GridWarpSurface::setVertices(vector<Vec2> v){
void GridWarpSurface::setVertices(vector<Vec3> v){
if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices");
}
@ -165,19 +159,8 @@ void GridWarpSurface::setVertices(vector<Vec2> v){
mesh.setVertex(i, v[i].toOf());
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void GridWarpSurface::setVertices(vector<ofVec3f> v){
if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < v.size(); ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
void GridWarpSurface::setTexCoord(int index, Vec2 t){
@ -197,16 +180,12 @@ void GridWarpSurface::setTexCoords(vector<Vec2> t){
}
vector <ofVec3f> & GridWarpSurface::getVertices(){
return mesh.getVertices();
vector<Vec3> GridWarpSurface::getVertices(){
return Vec3::fromOf(mesh.getVertices());
}
vector <Vec2> & GridWarpSurface::getTexCoords(){
_texCoords.clear();
for(auto c : mesh.getTexCoords()){
_texCoords.push_back(Vec2(c));
}
return _texCoords;
vector<Vec2> GridWarpSurface::getTexCoords(){
return Vec2::fromOf(mesh.getTexCoords());
}
void GridWarpSurface::createGridMesh(){
@ -251,7 +230,8 @@ void GridWarpSurface::createGridMesh(){
}
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
BaseSurface * GridWarpSurface::clone(){

16
src/Surfaces/GridWarpSurface.h

@ -5,6 +5,7 @@
#include "SurfaceType.h"
#include "HomographyHelper.h"
#include "Vec2.h"
#include "Vec3.h"
namespace ofx {
namespace piMapper {
@ -13,9 +14,9 @@ class GridWarpSurface : public BaseSurface {
public:
GridWarpSurface();
void setup();
void setup(){};
void draw();
void moveBy(Vec2 v);
void moveBy(Vec3 v);
int getType();
int getGridRows();
@ -28,13 +29,12 @@ class GridWarpSurface : public BaseSurface {
ofPolyline getHitArea();
ofPolyline getTextureHitArea();
void setVertex(int index, Vec2 p);
void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v);
void setVertex(int index, Vec3 p);
void setVertices(vector<Vec3> v);
void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<Vec2> t);
vector <ofVec3f> & getVertices();
vector <Vec2> & getTexCoords();
vector<Vec3> getVertices();
vector<Vec2> getTexCoords();
void createGridMesh();
@ -43,8 +43,6 @@ class GridWarpSurface : public BaseSurface {
private:
int _gridCols;
int _gridRows;
vector<Vec2> _texCoords;
};
} // namespace piMapper

75
src/Surfaces/HexagonSurface.cpp

@ -11,19 +11,19 @@ void HexagonSurface::setup(){
// Create 6 + 1 points for the hexagon surface.
vector <Vec2> verts;
vector <Vec3> verts;
verts.resize(7);
// Start with the center.
verts[0] = Vec2((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f);
verts[0] = Vec3((float)ofGetWidth() / 2.0f, (float)ofGetHeight() / 2.0f, 0.0f);
// Then from top left clockwise.
verts[1] = Vec2((float)ofGetWidth() / 3.0f, 0);
verts[2] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, 0);
verts[3] = Vec2(ofGetWidth(), (float)ofGetHeight() / 2.0f);
verts[4] = Vec2((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight());
verts[5] = Vec2((float)ofGetWidth() / 3.0f, ofGetHeight());
verts[6] = Vec2(0, (float)ofGetHeight() / 2.0f);
verts[1] = Vec3((float)ofGetWidth() / 3.0f, 0.0f, 0.0f);
verts[2] = Vec3((float)ofGetWidth() / 3.0f * 2.0f, 0.0f, 0.0f);
verts[3] = Vec3(ofGetWidth(), (float)ofGetHeight() / 2.0f, 0.0f);
verts[4] = Vec3((float)ofGetWidth() / 3.0f * 2.0f, ofGetHeight(), 0.0f);
verts[5] = Vec3((float)ofGetWidth() / 3.0f, ofGetHeight(), 0.0f);
verts[6] = Vec3(0, (float)ofGetHeight() / 2.0f, 0.0f);
// No create the texture coordinates.
vector <Vec2> coords;
@ -45,7 +45,7 @@ void HexagonSurface::setup(){
}
void HexagonSurface::setup(
vector <Vec2> & verts,
vector <Vec3> & verts,
vector <Vec2> & coords,
BaseSource * newSource){
@ -103,18 +103,17 @@ void HexagonSurface::draw(){
}
}
void HexagonSurface::setVertex(int index, Vec2 p){
void HexagonSurface::setVertex(int index, Vec3 p){
if(index >= mesh.getVertices().size()){
ofLog() << "Vertex with this index does not exist: " << index << endl;
return;
}
mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this);
}
void HexagonSurface::setVertices(vector<Vec2> v){
void HexagonSurface::setVertices(vector<Vec3> v){
if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices");
}
@ -123,19 +122,8 @@ void HexagonSurface::setVertices(vector<Vec2> v){
mesh.setVertex(i, v[i].toOf());
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void HexagonSurface::setVertices(vector<ofVec3f> v){
if(v.size() != mesh.getVertices().size()){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < v.size(); ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
void HexagonSurface::setTexCoord(int index, Vec2 t){
@ -152,20 +140,20 @@ void HexagonSurface::setTexCoords(vector<Vec2> t){
if(t.size() != mesh.getTexCoords().size()){
throw runtime_error("Wrong number of texture coordinates");
}
for(int i = 0; i < t.size(); ++i){
mesh.setTexCoord(i, t[i].toOf());
}
}
void HexagonSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){
vertices[i] += v.toOf();
void HexagonSurface::moveBy(Vec3 v){
for(int i = 0; i < mesh.getVertices().size(); i++){
mesh.getVertices()[i] += v.toOf();
}
setMoved(true);
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
int HexagonSurface::getType(){
@ -173,7 +161,6 @@ int HexagonSurface::getType(){
}
bool HexagonSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices
ofPolyline line = getHitArea();
if(line.inside(p.x, p.y)){
@ -183,18 +170,20 @@ bool HexagonSurface::hitTest(Vec2 p){
}
}
Vec2 HexagonSurface::getVertex(int index){
Vec3 HexagonSurface::getVertex(int index){
if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl;
throw runtime_error("Vertex index out of bounds.");
}
ofVec3f vert = mesh.getVertex(index);
return Vec2(vert.x, vert.y);
return Vec3(
mesh.getVertex(index).x,
mesh.getVertex(index).y,
mesh.getVertex(index).z);
}
Vec2 HexagonSurface::getTexCoord(int index){
if(index > 2){
if(index > 1){
throw runtime_error("Texture coordinate index out of bounds.");
}
@ -211,7 +200,6 @@ ofPolyline HexagonSurface::getHitArea(){
}
line.close();
return line;
}
@ -229,17 +217,12 @@ ofPolyline HexagonSurface::getTextureHitArea(){
return line;
}
vector <ofVec3f> & HexagonSurface::getVertices(){
// return only joint vertices
return mesh.getVertices();
vector<Vec3> HexagonSurface::getVertices(){
return Vec3::fromOf(mesh.getVertices());
}
vector <Vec2> & HexagonSurface::getTexCoords(){
_texCoords.clear();
for(auto tc : mesh.getTexCoords()){
_texCoords.push_back(tc);
}
return _texCoords;
vector<Vec2> HexagonSurface::getTexCoords(){
return Vec2::fromOf(mesh.getTexCoords());
}
BaseSurface * HexagonSurface::clone(){

19
src/Surfaces/HexagonSurface.h

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

90
src/Surfaces/QuadSurface.cpp

@ -14,21 +14,21 @@ QuadSurface::~QuadSurface(){
void QuadSurface::setup(){
// Create 4 points for the 2 triangles
Vec2 p1 = Vec2(0, 0);
Vec2 p2 = Vec2(0, ofGetHeight());
Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight());
Vec2 p4 = Vec2(ofGetWidth(), 0);
Vec3 p1 = Vec3(0.0f, 0.0f, 0.0f);
Vec3 p2 = Vec3(0.0f, ofGetHeight(), 0.0f);
Vec3 p3 = Vec3(ofGetWidth(), ofGetHeight(), 0.0f);
Vec3 p4 = Vec3(ofGetWidth(), 0.0f, 0.0f);
// Create 4 point for the texture coordinates
Vec2 t1 = Vec2(Vec2(0.0f, 0.0f));
Vec2 t2 = Vec2(Vec2(1.0f, 0.0f));
Vec2 t3 = Vec2(Vec2(1.0f, 1.0f));
Vec2 t4 = Vec2(Vec2(0.0f, 1.0f));
Vec2 t1 = Vec2(0.0f, 0.0f);
Vec2 t2 = Vec2(1.0f, 0.0f);
Vec2 t3 = Vec2(1.0f, 1.0f);
Vec2 t4 = Vec2(0.0f, 1.0f);
setup(p1, p2, p3, p4, t1, t2, t3, t4, source);
}
void QuadSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4,
void QuadSurface::setup(Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4,
Vec2 t1, Vec2 t2, Vec2 t3, Vec2 t4,
BaseSource * newSource){
// Assign texture
@ -71,10 +71,10 @@ void QuadSurface::draw(){
ofRectangle box = getMeshBoundingBox();
ofMesh m = mesh;
m.setVertex(0, ofVec3f(0, 0, 0));
m.setVertex(1, ofVec3f(box.width, 0, 0));
m.setVertex(2, ofVec3f(box.width, box.height, 0));
m.setVertex(3, ofVec3f(0, box.height, 0));
m.setVertex(0, Vec3(0, 0, 0).toOf());
m.setVertex(1, Vec3(box.width, 0, 0).toOf());
m.setVertex(2, Vec3(box.width, box.height, 0).toOf());
m.setVertex(3, Vec3(0, box.height, 0).toOf());
ofPushMatrix();
if(true){
@ -110,18 +110,17 @@ void QuadSurface::draw(){
}
}
void QuadSurface::setVertex(int index, Vec2 p){
void QuadSurface::setVertex(int index, Vec3 p){
if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl;
return;
}
mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this);
}
void QuadSurface::setVertices(vector<Vec2> v){
void QuadSurface::setVertices(vector<Vec3> v){
if(v.size() != 4){
throw runtime_error("Wrong number of vertices");
}
@ -130,19 +129,8 @@ void QuadSurface::setVertices(vector<Vec2> v){
mesh.setVertex(i, v[i].toOf());
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void QuadSurface::setVertices(vector<ofVec3f> v){
if(v.size() != 4){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 4; ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
void QuadSurface::setTexCoord(int index, Vec2 t){
@ -164,15 +152,14 @@ void QuadSurface::setTexCoords(vector<Vec2> t){
}
}
void QuadSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){
vertices[i] += v.toOf();
void QuadSurface::moveBy(Vec3 v){
for(int i = 0; i < mesh.getVertices().size(); i++){
mesh.getVertices()[i] += v.toOf();
}
setMoved(true);
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
int QuadSurface::getType(){
@ -180,7 +167,6 @@ int QuadSurface::getType(){
}
bool QuadSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices
ofPolyline line = getHitArea();
if(line.inside(p.x, p.y)){
@ -190,14 +176,16 @@ bool QuadSurface::hitTest(Vec2 p){
}
}
Vec2 QuadSurface::getVertex(int index){
Vec3 QuadSurface::getVertex(int index){
if(index > 3){
ofLog() << "Vertex with this index does not exist: " << index << endl;
throw runtime_error("Vertex index out of bounds.");
}
ofVec3f vert = mesh.getVertex(index);
return Vec2(vert.x, vert.y);
return Vec3(
mesh.getVertex(index).x,
mesh.getVertex(index).y,
mesh.getVertex(index).z);
}
Vec2 QuadSurface::getTexCoord(int index){
@ -212,6 +200,7 @@ Vec2 QuadSurface::getTexCoord(int index){
ofPolyline QuadSurface::getHitArea(){
ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y));
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y));
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y));
@ -234,17 +223,12 @@ ofPolyline QuadSurface::getTextureHitArea(){
return line;
}
vector <ofVec3f> & QuadSurface::getVertices(){
// return only joint vertices
return mesh.getVertices();
vector<Vec3> QuadSurface::getVertices(){
return Vec3::fromOf(mesh.getVertices());
}
vector <Vec2> & QuadSurface::getTexCoords(){
_texCoords.clear();
for(auto tc : mesh.getTexCoords()){
_texCoords.push_back(tc);
}
return _texCoords;
vector<Vec2> QuadSurface::getTexCoords(){
return Vec2::fromOf(mesh.getTexCoords());
}
void QuadSurface::calculateHomography(){
@ -262,10 +246,10 @@ void QuadSurface::calculateHomography(){
src[3][0] = 0;
src[3][1] = box.height;
ofVec3f p0 = mesh.getVertex(0);
ofVec3f p1 = mesh.getVertex(1);
ofVec3f p2 = mesh.getVertex(2);
ofVec3f p3 = mesh.getVertex(3);
Vec3 p0(mesh.getVertex(0).x, mesh.getVertex(0).y, mesh.getVertex(0).z);
Vec3 p1(mesh.getVertex(1).x, mesh.getVertex(1).y, mesh.getVertex(1).z);
Vec3 p2(mesh.getVertex(2).x, mesh.getVertex(2).y, mesh.getVertex(2).z);
Vec3 p3(mesh.getVertex(3).x, mesh.getVertex(3).y, mesh.getVertex(3).z);
dst[0][0] = p0.x;
dst[0][1] = p0.y;

26
src/Surfaces/QuadSurface.h

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

18
src/Surfaces/SurfaceFactory.cpp

@ -29,11 +29,11 @@ BaseSurface * SurfaceFactory::createSurface(SurfaceType type){
}
TriangleSurface * SurfaceFactory::createTriangleSurface(){
vector <Vec2> vertices;
vector <Vec3> vertices;
float margin = 50.0f;
vertices.push_back(Vec2((float)ofGetWidth() / 2.0f, margin));
vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin));
vertices.push_back(Vec3((float)ofGetWidth() / 2.0f, margin, 0.0f));
vertices.push_back(Vec3((float)ofGetWidth() - margin, (float)ofGetHeight() - margin, 0.0f));
vertices.push_back(Vec3(margin, (float)ofGetHeight() - margin, 0.0f));
vector <Vec2> texCoords;
texCoords.push_back(Vec2(0.5f, 0.0f));
@ -51,12 +51,12 @@ TriangleSurface * SurfaceFactory::createTriangleSurface(){
}
QuadSurface * SurfaceFactory::createQuadSurface(){
vector <Vec2> vertices;
vector <Vec3> vertices;
float margin = 50.0f;
vertices.push_back(Vec2(margin, margin));
vertices.push_back(Vec2((float)ofGetWidth() - margin, margin));
vertices.push_back(Vec2((float)ofGetWidth() - margin, (float)ofGetHeight() - margin));
vertices.push_back(Vec2(margin, (float)ofGetHeight() - margin));
vertices.push_back(Vec3(margin, margin, 0.0f));
vertices.push_back(Vec3((float)ofGetWidth() - margin, margin, 0.0f));
vertices.push_back(Vec3((float)ofGetWidth() - margin, (float)ofGetHeight() - margin, 0.0f));
vertices.push_back(Vec3(margin, (float)ofGetHeight() - margin, 0.0f));
vector <Vec2> texCoords;
texCoords.push_back(Vec2(Vec2(0.0f, 0.0f)));

8
src/Surfaces/SurfaceManager.cpp

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

8
src/Surfaces/SurfaceManager.h

@ -51,8 +51,8 @@ class SurfaceManager {
void selectPrevVertex();
void selectVertex(int i);
void moveSelectionBy(Vec2 v);
void moveAllSurfacesBy(Vec2 v);
void moveSelectionBy(Vec3 v);
void moveAllSurfacesBy(Vec3 v);
int size();
int getSelectedVertexIndex();
@ -61,13 +61,13 @@ class SurfaceManager {
unsigned int getNumPresets();
ofEvent <int> vertexChangedEvent;
ofEvent <vector<ofVec3f>> verticesChangedEvent;
ofEvent <vector<Vec3>> verticesChangedEvent;
ofEvent <int> surfaceSelectedEvent;
ofEvent <int> vertexSelectedEvent;
ofEvent <int> vertexUnselectedEvent;
void onVertexChanged(int & i);
void onVerticesChanged(vector<ofVec3f> & vertices);
void onVerticesChanged(vector<Vec3> & vertices);
SurfaceStack * getActivePreset();
SurfaceStack * createPreset();

2
src/Surfaces/SurfaceStack.cpp

@ -65,7 +65,7 @@ BaseSurface * SurfaceStack::back(){
return _surfaces.back();
}
void SurfaceStack::onVerticesChanged(vector<ofVec3f> & vertices){
void SurfaceStack::onVerticesChanged(vector<Vec3> & vertices){
ofNotifyEvent(verticesChangedEvent, vertices, this);
}

4
src/Surfaces/SurfaceStack.h

@ -21,10 +21,10 @@ class SurfaceStack {
BaseSurface * at(int i);
BaseSurface * back();
ofEvent <vector<ofVec3f>> verticesChangedEvent;
ofEvent <vector<Vec3>> verticesChangedEvent;
ofEvent <int> vertexChangedEvent;
void onVerticesChanged(vector<ofVec3f> & vertices);
void onVerticesChanged(vector<Vec3> & vertices);
void onVertexChanged(int & i);
vector<BaseSurface *> & getSurfaces(){ return _surfaces; };

80
src/Surfaces/TriangleSurface.cpp

@ -7,23 +7,22 @@ TriangleSurface::TriangleSurface(){
setup();
}
TriangleSurface::~TriangleSurface(){}
void TriangleSurface::setup(){
// Create 3 points for the triangle
Vec2 p1 = Vec2(ofGetWidth() / 2.0f, 0);
Vec2 p2 = Vec2(Vec2(0, ofGetHeight()));
Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight());
Vec3 p1 = Vec3((float)ofGetWidth() / 2.0f, 0.0f, 0.0f);
Vec3 p2 = Vec3(0.0f, (float)ofGetHeight(), 0.0f);
Vec3 p3 = Vec3((float)ofGetWidth(), (float)ofGetHeight(), 0.0f);
// Create 3 point for the texture coordinates
Vec2 t1 = Vec2(0.5f, 0);
Vec2 t2 = Vec2(0, 1.0f);
Vec2 t3 = Vec2(1, 1.0f);
Vec2 t1 = Vec2(0.5f, 0.0f);
Vec2 t2 = Vec2(0.0f, 1.0f);
Vec2 t3 = Vec2(1.0f, 1.0f);
setup(p1, p2, p3, t1, t2, t3, source);
}
void TriangleSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1,
void TriangleSurface::setup(Vec3 p1, Vec3 p2, Vec3 p3, Vec2 t1,
Vec2 t2, Vec2 t3, BaseSource * newSource){
// Assign texture
source = newSource;
@ -63,18 +62,17 @@ void TriangleSurface::draw(){
}
}
void TriangleSurface::setVertex(int index, Vec2 p){
void TriangleSurface::setVertex(int index, Vec3 p){
if(index > 2){
ofLog() << "Vertex with this index does not exist: " << index << endl;
return;
}
mesh.setVertex(index, p.toOf());
ofVec3f v = mesh.getVertex(index);
ofNotifyEvent(vertexChangedEvent, index, this);
}
void TriangleSurface::setVertices(vector<Vec2> v){
void TriangleSurface::setVertices(vector<Vec3> v){
if(v.size() != 3){
throw runtime_error("Wrong number of vertices");
}
@ -83,19 +81,8 @@ void TriangleSurface::setVertices(vector<Vec2> v){
mesh.setVertex(i, v[i].toOf());
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
}
void TriangleSurface::setVertices(vector<ofVec3f> v){
if(v.size() != 3){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 3; ++i){
mesh.setVertex(i, v[i]);
}
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
void TriangleSurface::setTexCoord(int index, Vec2 t){
@ -112,20 +99,20 @@ void TriangleSurface::setTexCoords(vector<Vec2> t){
if(t.size() != 3){
throw runtime_error("Wrong number of texture coordinates");
}
for(int i = 0; i < 3; ++i){
mesh.setTexCoord(i, t[i].toOf());
}
}
void TriangleSurface::moveBy(Vec2 v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){
vertices[i] += v.toOf();
void TriangleSurface::moveBy(Vec3 v){
for(auto i = 0; i < mesh.getVertices().size(); ++i){
mesh.getVertices()[i] += v.toOf();
}
setMoved(true);
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this);
vector<Vec3> vertices = Vec3::fromOf(mesh.getVertices());
ofNotifyEvent(verticesChangedEvent, vertices, this);
}
int TriangleSurface::getType(){
@ -133,9 +120,8 @@ int TriangleSurface::getType(){
}
bool TriangleSurface::hitTest(Vec2 p){
// Construct ofPolyline from vertices
ofPolyline line = getHitArea();
if(line.inside(p.x, p.y)){
return true;
}else{
@ -149,12 +135,14 @@ Vec2 TriangleSurface::getVertex(int index){
throw runtime_error("Vertex index out of bounds.");
}
ofVec3f vert = mesh.getVertex(index);
return Vec2(vert.x, vert.y);
return Vec2(
mesh.getVertex(index).x,
mesh.getVertex(index).y);
}
Vec2 TriangleSurface::getTexCoord(int index){
if(index > 2){
ofLog() << "Texture coordinate with this index does not exist: " << index << endl;
throw runtime_error("Texture coordinate index out of bounds.");
}
@ -165,6 +153,7 @@ Vec2 TriangleSurface::getTexCoord(int index){
ofPolyline TriangleSurface::getHitArea(){
ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y));
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y));
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y));
@ -175,26 +164,25 @@ ofPolyline TriangleSurface::getHitArea(){
ofPolyline TriangleSurface::getTextureHitArea(){
ofPolyline line;
Vec2 textureSize = Vec2(source->getTexture()->getWidth(), source->getTexture()->getHeight());
Vec2 textureSize = Vec2(
source->getTexture()->getWidth(),
source->getTexture()->getHeight());
for(int i = 0; i < mesh.getTexCoords().size(); i++){
line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf()));
}
line.close();
return line;
}
vector <ofVec3f> & TriangleSurface::getVertices(){
// return only joint vertices
return mesh.getVertices();
vector<Vec3> TriangleSurface::getVertices(){
return Vec3::fromOf(mesh.getVertices());
}
vector <Vec2> & TriangleSurface::getTexCoords(){
_texCoords.clear();
for(auto tc : mesh.getTexCoords()){
_texCoords.push_back(tc);
}
return _texCoords;
vector<Vec2> TriangleSurface::getTexCoords(){
return Vec2::fromOf(mesh.getTexCoords());
}
BaseSurface * TriangleSurface::clone(){

22
src/Surfaces/TriangleSurface.h

@ -4,6 +4,7 @@
#include "BaseSurface.h"
#include "SurfaceType.h"
#include "Vec2.h"
#include "Vec3.h"
namespace ofx {
namespace piMapper {
@ -11,21 +12,18 @@ namespace piMapper {
class TriangleSurface : public BaseSurface {
public:
TriangleSurface();
~TriangleSurface();
void setup();
void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 t1, Vec2 t2,
Vec2 t3, BaseSource * newSource);
void setup(
Vec3 p1, Vec3 p2, Vec3 p3,
Vec2 t1, Vec2 t2, Vec2 t3,
BaseSource * newSource);
void draw();
void setVertex(int index, Vec2 p);
void setVertices(vector<Vec2> v);
void setVertices(vector<ofVec3f> v);
void setVertex(int index, Vec3 p);
void setVertices(vector<Vec3> v);
void setTexCoord(int index, Vec2 t);
void setTexCoords(vector<Vec2> t);
void moveBy(Vec2 v);
void moveBy(Vec3 v);
int getType();
bool hitTest(Vec2 p);
@ -33,8 +31,8 @@ class TriangleSurface : public BaseSurface {
Vec2 getTexCoord(int index);
ofPolyline getHitArea();
ofPolyline getTextureHitArea();
vector <ofVec3f> & getVertices();
vector <Vec2> & getTexCoords();
vector<Vec3> getVertices();
vector<Vec2> getTexCoords();
BaseSurface * clone();
};

74
src/Types/Vec2.cpp

@ -4,13 +4,12 @@ namespace ofx {
namespace piMapper {
Vec2::Vec2(){
x = 0.0f;
y = 0.0f;
Vec2(0.0f, 0.0f);
}
Vec2::Vec2(float $x, float $y){
x = $x;
y = $y;
Vec2::Vec2(float ix, float iy){
x = ix;
y = iy;
}
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
@ -19,28 +18,27 @@ Vec2::Vec2(float $x, float $y){
y = src.y;
}
Vec2::Vec2(ofVec3f & src){
x = src.x;
y = src.y;
}
ofVec2f Vec2::toOf(){
return ofVec2f(x, y);
}
ofVec2f Vec2::toOf(Vec2 & src){
return ofVec2f(src.x, src.y);
}
vector<ofVec2f> Vec2::toOf(vector<Vec2> & src){
vector<ofVec2f> dst;
for(auto v : src){
dst.push_back(ofVec2f(v.x, v.y));
vector<ofVec2f> retVal;
for(auto itm : src){
retVal.push_back(itm.toOf());
}
return dst;
return retVal;
}
float Vec2::distance(Vec2 & other){
vector<Vec2> Vec2::fromOf(vector<ofVec2f> & src){
vector<Vec2> retVal;
for(auto itm : src){
retVal.push_back(Vec2(itm));
}
return retVal;
}
float Vec2::distance(const Vec2 & other){
ofVec2f v1(x, y);
ofVec2f v2(other.x, other.y);
return v1.distance(v2);
@ -54,41 +52,43 @@ void Vec2::operator=(const Vec2 & other){
y = other.y;
}
void Vec2::operator=(const ofVec3f & other){
x = other.x;
y = other.y;
}
void Vec2::operator+=(Vec2 & other){
void Vec2::operator+=(const Vec2 & other){
x += other.x;
y += other.y;
}
Vec2 Vec2::operator+(Vec2 & other){
Vec2 Vec2::operator+(const Vec2 & other){
return Vec2(x + other.x, y + other.y);
}
Vec2 Vec2::operator/(Vec2 & other){
return Vec2(x / other.x, y / other.y);
Vec2 Vec2::operator-(){
return Vec2(-x, -y);
}
Vec2 Vec2::operator*(Vec2 & other){
return Vec2(x * other.x, y * other.y);
Vec2 Vec2::operator-(const Vec2 & other){
return Vec2(x - other.x, y - other.y);
}
Vec2 Vec2::operator-(){
return Vec2(-x, -y);
Vec2 Vec2::operator*(const Vec2 & other){
return Vec2(x * other.x, y * other.y);
}
Vec2 Vec2::operator-(Vec2 & other){
return Vec2(x - other.x, y - other.y);
Vec2 Vec2::operator/(const Vec2 & other){
return Vec2(x / other.x, y / other.y);
}
bool Vec2::operator!=(Vec2 & other){
bool Vec2::operator==(const Vec2 & other){
if(x == other.x && y == other.y){
return false;
return true;
}
return false;
}
bool Vec2::operator!=(const Vec2 & other){
if(x != other.x && y != other.y){
return true;
}
return true;
return false;
}
} // namespace piMapper

35
src/Types/Vec2.h

@ -1,45 +1,40 @@
#pragma once
#include "ofMain.h"
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
// ...
#include "ofVec2f.h"
#else
// TODO: include glm
// TODO: include glm
#endif
namespace ofx {
namespace piMapper {
//#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
class Vec2{
public:
Vec2();
Vec2(float $x, float $y);
Vec2(float ix, float iy);
// TODO: Achieve this with templates
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec2(ofVec2f & src);
Vec2(ofVec3f & src);
ofVec2f toOf();
static ofVec2f toOf(Vec2 & src);
static vector<ofVec2f> toOf(vector<Vec2> & src);
float distance(Vec2 & other);
static vector<Vec2> fromOf(vector<ofVec2f> & src);
#else
// TODO: The same for glm::vec2
// static vector<glm::vec2> toOf(vector<Vec2> & src);
// TODO: glm
#endif
void operator=(const Vec2 & other);
void operator=(const ofVec3f & other);
void operator+=(Vec2 & other);
float distance(const Vec2 & other);
Vec2 operator+(Vec2 & other);
Vec2 operator/(Vec2 & other);
Vec2 operator*(Vec2 & other);
void operator=(const Vec2 & other);
void operator+=(const Vec2 & other);
Vec2 operator+(const Vec2 & other);
Vec2 operator-();
Vec2 operator-(Vec2 & other);
bool operator!=(Vec2 & other);
Vec2 operator-(const Vec2 & other);
Vec2 operator*(const Vec2 & other);
Vec2 operator/(const Vec2 & other);
bool operator==(const Vec2 & other);
bool operator!=(const Vec2 & other);
float x;
float y;

111
src/Types/Vec3.cpp

@ -4,15 +4,13 @@ namespace ofx {
namespace piMapper {
Vec3::Vec3(){
x = 0.0f;
y = 0.0f;
z = 0.0f;
Vec3(0.0f, 0.0f, 0.0f);
}
Vec3::Vec3(float $x, float $y, float $z){
x = $x;
y = $y;
z = $z;
Vec3::Vec3(float ix, float iy, float iz){
x = ix;
y = iy;
z = iz;
}
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
@ -23,22 +21,26 @@ Vec3::Vec3(float $x, float $y, float $z){
}
ofVec3f Vec3::toOf(){
ofVec3f(x, y, z);
return ofVec3f(x, y, z);
}
ofVec3f toOf(Vec3 & src){
return ofVec3f(src.x, src.y, src.z);
vector<ofVec3f> Vec3::toOf(vector<Vec3> & src){
vector<ofVec3f> retVal;
for(auto itm : src){
retVal.push_back(itm.toOf());
}
return retVal;
}
vector<ofVec3f> toOf(vector<Vec3> & src){
vector<ofVec3f> dst;
for(auto v : src){
dst.push_back(ofVec3f(v.x, v.y, v.z));
vector<Vec3> Vec3::fromOf(vector<ofVec3f> & src){
vector<Vec3> retVal;
for(auto itm : src){
retVal.push_back(Vec3(itm));
}
return dst;
return retVal;
}
#else
// TODO: The same for glm::vec2
// TODO: Vec3::Vec3(glm::vec3 & src){...}
#endif
void Vec3::operator=(const Vec3 & other){
@ -47,35 +49,76 @@ void Vec3::operator=(const Vec3 & other){
z = other.z;
}
void Vec3::operator=(const ofVec3f & other){
x = other.x;
y = other.y;
z = other.z;
void Vec3::operator+=(const Vec3 & other){
x += other.x;
y += other.y;
z += other.z;
}
Vec3 Vec3::operator+(Vec3 & other){
return Vec3(
x + other.x,
y + other.y,
z + other.z);
void Vec3::operator*=(const Vec3 & other){
x *= other.x;
y *= other.y;
z *= other.z;
}
void Vec3::operator*=(float n){
x *= n;
y *= n;
z *= n;
}
void Vec3::operator/=(const Vec3 & other){
x /= other.x;
y /= other.y;
z /= other.z;
}
void Vec3::operator/=(float n){
x /= n;
y /= n;
z /= n;
}
Vec3 Vec3::operator+(const Vec3 & other){
return Vec3(x + other.x, y + other.y, z + other.z);
}
Vec3 Vec3::operator-(){
return Vec3(-x, -y, -z);
}
Vec3 Vec3::operator-(Vec3 & other){
return Vec3(
x - other.x,
y - other.y,
z - other.z);
Vec3 Vec3::operator-(const Vec3 & other){
return Vec3(x - other.x, y - other.y, z - other.z);
}
Vec3 Vec3::operator*(const Vec3 & other){
return Vec3(x * other.x, y * other.y, z * other.z);
}
Vec3 Vec3::operator*(float n){
return Vec3(x * n, y * n, z * n);
}
Vec3 Vec3::operator/(const Vec3 & other){
return Vec3(x / other.x, y / other.y, z / other.z);
}
Vec3 Vec3::operator/(float n){
return Vec3(x / n, y / n, z / n);
}
bool Vec3::operator!=(Vec3 & other){
bool Vec3::operator==(const Vec3 & other){
if(x == other.x && y == other.y && z == other.z){
return false;
return true;
}
return false;
}
bool Vec3::operator!=(const Vec3 & other){
if(x != other.x && y != other.y && z != other.z){
return true;
}
return true;
return false;
}
} // namespace piMapper

34
src/Types/Vec3.h

@ -1,9 +1,9 @@
#pragma once
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
#include "ofMain.h"
#include "ofVec3f.h"
#else
// TODO: include glm
// TODO: include glm
#endif
namespace ofx {
@ -12,27 +12,33 @@ namespace piMapper {
class Vec3{
public:
Vec3();
Vec3(float $x, float $y, float $z);
Vec3(float ix, float iy, float iz);
// TODO: achieve this with templates
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
Vec3(ofVec3f & src);
ofVec3f toOf();
static ofVec3f toOf(Vec3 & src);
static vector<ofVec3f> toOf(vector<Vec3> & src);
static vector<Vec3> fromOf(vector<ofVec3f> & src);
#else
// TODO: The same for glm::vec2
// static vector<glm::vec2> toOf(vector<Vec2> & src);
// TODO: Vec3(glm::vec3 & src);
#endif
void operator=(const Vec3 & other);
void operator=(const ofVec3f & other);
Vec3 operator+(Vec3 & other);
void operator+=(const Vec3 & other);
void operator*=(const Vec3 & other);
void operator*=(float n);
void operator/=(const Vec3 & other);
void operator/=(float n);
Vec3 operator+(const Vec3 & other);
Vec3 operator-();
Vec3 operator-(Vec3 & other);
bool operator!=(Vec3 & other);
Vec3 operator-(const Vec3 & other);
Vec3 operator*(const Vec3 & other);
Vec3 operator*(float n);
Vec3 operator/(const Vec3 & other);
Vec3 operator/(float n);
bool operator==(const Vec3 & other);
bool operator!=(const Vec3 & other);
float x;
float y;

2
src/ofxPiMapper.cpp

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

3
src/ofxPiMapper.h

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

Loading…
Cancel
Save