Browse Source

ran clang Format with google code Style

master
Felix Dubrownik 11 years ago
parent
commit
6d44d1cae7
  1. 93
      example/src/ofApp.cpp
  2. 3
      example/src/ofApp.h
  3. 68
      src/BaseJoint.cpp
  4. 3
      src/BaseJoint.h
  5. 41
      src/BaseSurface.cpp
  6. 7
      src/BaseSurface.h
  7. 29
      src/CircleJoint.cpp
  8. 7
      src/CircleJoint.h
  9. 12
      src/EditorType.h
  10. 13
      src/GuiMode.h
  11. 133
      src/ProjectionEditor.cpp
  12. 7
      src/ProjectionEditor.h
  13. 67
      src/QuadSurface.cpp
  14. 13
      src/QuadSurface.h
  15. 50
      src/SourcesEditor.cpp
  16. 7
      src/SourcesEditor.h
  17. 188
      src/SurfaceManager.cpp
  18. 15
      src/SurfaceManager.h
  19. 87
      src/SurfaceManagerGui.cpp
  20. 8
      src/SurfaceManagerGui.h
  21. 12
      src/SurfaceType.h
  22. 110
      src/TextureEditor.cpp
  23. 8
      src/TextureEditor.h
  24. 59
      src/TriangleSurface.cpp
  25. 11
      src/TriangleSurface.h
  26. 97
      src/ui/RadioList.cpp
  27. 13
      src/ui/RadioList.h

93
example/src/ofApp.cpp

@ -1,7 +1,6 @@
#include "ofApp.h" #include "ofApp.h"
void ofApp::setup() void ofApp::setup() {
{
bShowInfo = false; bShowInfo = false;
// check if the surfaces.xml file is there // check if the surfaces.xml file is there
@ -23,13 +22,13 @@ void ofApp::setup()
// Genereate rects // Genereate rects
int numRects = 20; // change this to add more or less rects int numRects = 20; // change this to add more or less rects
for (int i = 0; i < numRects; i++) { for (int i = 0; i < numRects; i++) {
rects.push_back( ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), ofRandom(20)) ); rects.push_back(ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(),
ofRandom(20)));
rectSpeeds.push_back((1.0f + ofRandom(5))); rectSpeeds.push_back((1.0f + ofRandom(5)));
} }
} }
void ofApp::update() void ofApp::update() {
{
// Move rects // Move rects
for (int i = 0; i < rects.size(); i++) { for (int i = 0; i < rects.size(); i++) {
rects[i].y += rectSpeeds[i]; rects[i].y += rectSpeeds[i];
@ -49,8 +48,7 @@ void ofApp::update()
fbo->end(); fbo->end();
} }
void ofApp::draw() void ofApp::draw() {
{
// Draw the piMapper GUI // Draw the piMapper GUI
gui.draw(); gui.draw();
@ -62,7 +60,8 @@ void ofApp::draw()
ss << " 2. Texture mapping mode\n"; ss << " 2. Texture mapping mode\n";
ss << " 3. Projection mapping mode\n"; ss << " 3. Projection mapping mode\n";
ss << " 4. Source selection mode\n\n"; ss << " 4. Source selection mode\n\n";
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> keys on the keyboard.\n\n"; ss << "You can switch between the modes by using <1>, <2>, <3> and <4> "
"keys on the keyboard.\n\n";
ss << "Press <r> or <n> to add random or normal surface.\n"; ss << "Press <r> or <n> to add random or normal surface.\n";
ss << "Press <q> to add a new quad surface.\n"; ss << "Press <q> to add a new quad surface.\n";
ss << "Press <s> to save the composition.\n"; ss << "Press <s> to save the composition.\n";
@ -70,39 +69,62 @@ void ofApp::draw()
ss << "Press <a> to reassign the fbo texture to the first surface\n"; ss << "Press <a> to reassign the fbo texture to the first surface\n";
ss << "Hit <i> to hide this message."; ss << "Hit <i> to hide this message.";
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0,0,0,100), ofColor(255,255,255,200)); ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100),
ofColor(255, 255, 255, 200));
} }
} }
void ofApp::exit() void ofApp::exit() {
{
// Clear FBO from mem // Clear FBO from mem
delete fbo; delete fbo;
} }
void ofApp::keyPressed(int key) void ofApp::keyPressed(int key) {
{
cout << "Key pressed: " << static_cast<char>(key) << endl; cout << "Key pressed: " << static_cast<char>(key) << endl;
switch (key) { switch (key) {
case '1': gui.setMode(ofx::piMapper::GuiMode::NONE); break; case '1':
case '2': gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); break; gui.setMode(ofx::piMapper::GuiMode::NONE);
case '3': gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); break; break;
case '4': gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); break; case '2':
case 'i': bShowInfo = !bShowInfo; break; gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
case 'r': addRandomSurface(); break; break;
case 'q': addQuadSurface(); break; case '3':
case 'n': addSurface(); break; gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
case 'f': ofToggleFullscreen(); break; break;
case 's': surfaceManager.saveXmlSettings("surfaces.xml"); break; case '4':
case 'a': setFboAsTexture(); break; gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
case OF_KEY_BACKSPACE: surfaceManager.removeSelectedSurface(); break; break;
default: break; case 'i':
} bShowInfo = !bShowInfo;
} break;
case 'r':
void ofApp::addRandomSurface() addRandomSurface();
{ break;
case 'q':
addQuadSurface();
break;
case 'n':
addSurface();
break;
case 'f':
ofToggleFullscreen();
break;
case 's':
surfaceManager.saveXmlSettings("surfaces.xml");
break;
case 'a':
setFboAsTexture();
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
break;
default:
break;
}
}
void ofApp::addRandomSurface() {
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight()));
@ -118,8 +140,7 @@ void ofApp::addRandomSurface()
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} }
void ofApp::addQuadSurface() void ofApp::addQuadSurface() {
{
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE;
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
@ -141,8 +162,7 @@ void ofApp::addQuadSurface()
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} }
void ofApp::addSurface() void ofApp::addSurface() {
{
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE;
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, 0.0f)); vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, 0.0f));
@ -158,7 +178,6 @@ void ofApp::addSurface()
surfaceManager.selectSurface(surfaceManager.size() - 1); surfaceManager.selectSurface(surfaceManager.size() - 1);
} }
void ofApp::setFboAsTexture() void ofApp::setFboAsTexture() {
{
surfaceManager.getSurface(0)->setTexture(&fbo->getTextureReference()); surfaceManager.getSurface(0)->setTexture(&fbo->getTextureReference());
} }

3
example/src/ofApp.h

@ -3,8 +3,7 @@
#include "ofMain.h" #include "ofMain.h"
#include "ofxPiMapper.h" #include "ofxPiMapper.h"
class ofApp : public ofBaseApp class ofApp : public ofBaseApp {
{
public: public:
void setup(); void setup();
void update(); void update();

68
src/BaseJoint.cpp

@ -3,32 +3,25 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
BaseJoint::BaseJoint() BaseJoint::BaseJoint() {
{
setDefaultColors(); setDefaultColors();
setDefaultProperties(); setDefaultProperties();
registerMouseEvents(); registerMouseEvents();
} }
BaseJoint::~BaseJoint() BaseJoint::~BaseJoint() { unregisterMouseEvents(); }
{
unregisterMouseEvents();
}
void BaseJoint::registerMouseEvents() void BaseJoint::registerMouseEvents() {
{
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::unregisterMouseEvents() void BaseJoint::unregisterMouseEvents() {
{
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::mousePressed(ofMouseEventArgs& args) void BaseJoint::mousePressed(ofMouseEventArgs& args) {
{
if (hitTest(ofVec2f(args.x, args.y))) { if (hitTest(ofVec2f(args.x, args.y))) {
// selected = true; // selected = true;
clickDistance = position - ofVec2f(args.x, args.y); clickDistance = position - ofVec2f(args.x, args.y);
@ -36,62 +29,37 @@ void BaseJoint::mousePressed(ofMouseEventArgs& args)
} }
} }
void BaseJoint::mouseReleased(int x, int y, int button) void BaseJoint::mouseReleased(int x, int y, int button) { stopDrag(); }
{
stopDrag();
}
void BaseJoint::mouseDragged(ofMouseEventArgs& args) void BaseJoint::mouseDragged(ofMouseEventArgs& args) {
{
if (!bDrag) return; if (!bDrag) return;
position = ofVec2f(args.x, args.y) + clickDistance; position = ofVec2f(args.x, args.y) + clickDistance;
} }
void BaseJoint::startDrag() void BaseJoint::startDrag() { bDrag = true; }
{
bDrag = true;
}
void BaseJoint::stopDrag() void BaseJoint::stopDrag() { bDrag = false; }
{
bDrag = false;
}
void BaseJoint::select() void BaseJoint::select() { selected = true; }
{
selected = true;
}
void BaseJoint::unselect() void BaseJoint::unselect() { selected = false; }
{
selected = false;
}
void BaseJoint::setClickDistance(ofVec2f newClickDistance) void BaseJoint::setClickDistance(ofVec2f newClickDistance) {
{
clickDistance = newClickDistance; clickDistance = newClickDistance;
} }
bool BaseJoint::isDragged() bool BaseJoint::isDragged() { return bDrag; }
{
return bDrag;
}
bool BaseJoint::isSelected() bool BaseJoint::isSelected() { return selected; }
{
return selected;
}
void BaseJoint::setDefaultColors() void BaseJoint::setDefaultColors() {
{
fillColor = ofColor(0, 255, 255, 0); fillColor = ofColor(0, 255, 255, 0);
strokeColor = ofColor(255, 255, 255); strokeColor = ofColor(255, 255, 255);
fillColorSelected = ofColor(255, 255, 0, 0); fillColorSelected = ofColor(255, 255, 0, 0);
strokeColorSelected = ofColor(255, 0, 0); strokeColorSelected = ofColor(255, 0, 0);
} }
void BaseJoint::setDefaultProperties() void BaseJoint::setDefaultProperties() {
{
enabled = true; enabled = true;
visible = true; visible = true;
position = ofVec2f(20.0f, 20.0f); position = ofVec2f(20.0f, 20.0f);
@ -100,5 +68,5 @@ void BaseJoint::setDefaultProperties()
selected = false; selected = false;
strokeWidth = 1.5f; strokeWidth = 1.5f;
} }
}
}} }

3
src/BaseJoint.h

@ -39,7 +39,8 @@ namespace piMapper{
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 clicked? ofVec2f clickDistance; // How far from the center of the joint the user has
// clicked?
bool bDrag; bool bDrag;
private: private:

41
src/BaseSurface.cpp

@ -3,14 +3,12 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
BaseSurface::BaseSurface() BaseSurface::BaseSurface() {
{
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
createDefaultTexture(); createDefaultTexture();
} }
void BaseSurface::createDefaultTexture() void BaseSurface::createDefaultTexture() {
{
ofPixels pixels; ofPixels pixels;
pixels.allocate(500, 500, 1); pixels.allocate(500, 500, 1);
for (int i = 0; i < pixels.size(); i++) { for (int i = 0; i < pixels.size(); i++) {
@ -23,10 +21,14 @@ void BaseSurface::createDefaultTexture()
for (int x = 0; x < pixels.getHeight(); x += squareSize) { for (int x = 0; x < pixels.getHeight(); x += squareSize) {
for (int yi = 0; yi < squareSize; yi++) { for (int yi = 0; yi < squareSize; yi++) {
for (int xi = 0; xi < squareSize; xi++) { for (int xi = 0; xi < squareSize; xi++) {
if ( sx && sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 255; if (sx && sy)
else if ( sx && !sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 0; pixels[(y + yi) * pixels.getWidth() + x + xi] = 255;
else if ( !sx && sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 0; else if (sx && !sy)
else pixels[(y+yi)*pixels.getWidth()+x+xi] = 255; pixels[(y + yi) * pixels.getWidth() + x + xi] = 0;
else if (!sx && sy)
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0;
else
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255;
} }
} }
sx = !sx; sx = !sx;
@ -41,12 +43,12 @@ void BaseSurface::createDefaultTexture()
texture = &defaultTexture; texture = &defaultTexture;
} }
void BaseSurface::drawTexture(ofVec2f position) void BaseSurface::drawTexture(ofVec2f position) {
{
ofMesh texMesh; ofMesh texMesh;
texMesh.addVertex(position); texMesh.addVertex(position);
texMesh.addVertex(position + ofVec2f(texture->getWidth(), 0.0f)); texMesh.addVertex(position + ofVec2f(texture->getWidth(), 0.0f));
texMesh.addVertex(position + ofVec2f(texture->getWidth(), texture->getHeight())); texMesh.addVertex(position +
ofVec2f(texture->getWidth(), texture->getHeight()));
texMesh.addVertex(position + ofVec2f(0.0f, texture->getHeight())); texMesh.addVertex(position + ofVec2f(0.0f, texture->getHeight()));
texMesh.addTriangle(0, 2, 3); texMesh.addTriangle(0, 2, 3);
texMesh.addTriangle(0, 1, 2); texMesh.addTriangle(0, 1, 2);
@ -59,19 +61,10 @@ void BaseSurface::drawTexture(ofVec2f position)
texture->unbind(); texture->unbind();
} }
void BaseSurface::setTexture(ofTexture *texturePtr) void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; }
{
texture = texturePtr;
}
ofTexture* BaseSurface::getTexture() ofTexture* BaseSurface::getTexture() { return texture; }
{
return texture;
}
ofTexture* BaseSurface::getDefaultTexture() ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
{ }
return &defaultTexture;
} }
}}

7
src/BaseSurface.h

@ -7,8 +7,7 @@ using namespace std;
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class BaseSurface class BaseSurface {
{
public: public:
BaseSurface(); BaseSurface();
virtual void setup() {}; virtual void setup() {};
@ -37,5 +36,5 @@ protected:
void createDefaultTexture(); void createDefaultTexture();
}; };
}
}} }

29
src/CircleJoint.cpp

@ -3,18 +3,13 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
CircleJoint::CircleJoint() CircleJoint::CircleJoint() { setDefaultProperties(); }
{
setDefaultProperties();
}
void CircleJoint::update() void CircleJoint::update() {
{
if (!enabled) return; if (!enabled) return;
} }
void CircleJoint::draw() void CircleJoint::draw() {
{
if (!visible) return; if (!visible) return;
if (!enabled) return; if (!enabled) return;
@ -41,16 +36,14 @@ void CircleJoint::draw()
ofPopStyle(); ofPopStyle();
} }
void CircleJoint::setDefaultProperties() void CircleJoint::setDefaultProperties() { radius = 10.0f; }
{
radius = 10.0f;
}
bool CircleJoint::hitTest(ofVec2f pos) bool CircleJoint::hitTest(ofVec2f pos) {
{
float distance = position.distance(pos); float distance = position.distance(pos);
if ( distance < radius ) return true; if (distance < radius)
else return false; return true;
else
return false;
}
}
} }
}}

7
src/CircleJoint.h

@ -3,11 +3,9 @@
#include "ofMain.h" #include "ofMain.h"
#include "BaseJoint.h" #include "BaseJoint.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class CircleJoint : public BaseJoint class CircleJoint : public BaseJoint {
{
public: public:
CircleJoint(); CircleJoint();
@ -20,4 +18,5 @@ private:
void setDefaultProperties(); void setDefaultProperties();
}; };
}} }
}

12
src/EditorType.h

@ -2,12 +2,8 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct EditorType struct EditorType {
{ enum { TEXTURE, PROJECTION };
enum {
TEXTURE,
PROJECTION
}; };
}; }
}
}}

13
src/GuiMode.h

@ -2,13 +2,8 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct GuiMode struct GuiMode {
{ enum { NONE, TEXTURE_MAPPING, PROJECTION_MAPPING, SOURCE_SELECTION };
enum {
NONE,
TEXTURE_MAPPING,
PROJECTION_MAPPING,
SOURCE_SELECTION
}; };
}; }
}} }

133
src/ProjectionEditor.cpp

@ -2,75 +2,66 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
ProjectionEditor::ProjectionEditor() ProjectionEditor::ProjectionEditor() {
{
surfaceManager = NULL; surfaceManager = NULL;
bShiftKeyDown = false; bShiftKeyDown = false;
fSnapDistance = 10.0f; fSnapDistance = 10.0f;
enable(); enable();
} }
ProjectionEditor::~ProjectionEditor() ProjectionEditor::~ProjectionEditor() {
{
clearJoints(); clearJoints();
surfaceManager = NULL; surfaceManager = NULL;
disable(); disable();
} }
void ProjectionEditor::registerAppEvents() void ProjectionEditor::registerAppEvents() {
{
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); ofAddListener(ofEvents().update, this, &ProjectionEditor::update);
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage);
} }
void ProjectionEditor::unregisterAppEvents() void ProjectionEditor::unregisterAppEvents() {
{
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update);
ofRemoveListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); ofRemoveListener(ofEvents().messageEvent, this,
&ProjectionEditor::gotMessage);
} }
void ProjectionEditor::registerMouseEvents() void ProjectionEditor::registerMouseEvents() {
{
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged);
} }
void ProjectionEditor::unregisterMouseEvents() void ProjectionEditor::unregisterMouseEvents() {
{ ofRemoveListener(ofEvents().mouseDragged, this,
ofRemoveListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); &ProjectionEditor::mouseDragged);
} }
void ProjectionEditor::registerKeyEvents() void ProjectionEditor::registerKeyEvents() {
{
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed);
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased);
} }
void ProjectionEditor::unregisterKeyEvents() void ProjectionEditor::unregisterKeyEvents() {
{
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed);
ofRemoveListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); ofRemoveListener(ofEvents().keyReleased, this,
&ProjectionEditor::keyReleased);
} }
void ProjectionEditor::enable() void ProjectionEditor::enable() {
{
registerAppEvents(); registerAppEvents();
registerMouseEvents(); registerMouseEvents();
registerKeyEvents(); registerKeyEvents();
} }
void ProjectionEditor::disable() void ProjectionEditor::disable() {
{
unregisterAppEvents(); unregisterAppEvents();
unregisterMouseEvents(); unregisterMouseEvents();
unregisterKeyEvents(); unregisterKeyEvents();
} }
void ProjectionEditor::update(ofEventArgs &args) void ProjectionEditor::update(ofEventArgs& args) {
{
// update surface if one of the joints is being dragged // update surface if one of the joints is being dragged
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
if (joints[i]->isDragged() || joints[i]->isSelected()) { if (joints[i]->isDragged() || joints[i]->isSelected()) {
if (surfaceManager->getSelectedSurface() != NULL) { if (surfaceManager->getSelectedSurface() != NULL) {
// update vertex to new location // update vertex to new location
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position);
@ -85,16 +76,14 @@ void ProjectionEditor::update(ofEventArgs &args)
} }
} }
void ProjectionEditor::draw() void ProjectionEditor::draw() {
{
if (surfaceManager == NULL) return; if (surfaceManager == NULL) return;
if (surfaceManager->getSelectedSurface() == NULL) return; if (surfaceManager->getSelectedSurface() == NULL) return;
if (joints.size() <= 0) createJoints(); if (joints.size() <= 0) createJoints();
drawJoints(); drawJoints();
} }
void ProjectionEditor::mouseDragged(ofMouseEventArgs &args) void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) {
{
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
// Collect all vertices of the projection surfaces // Collect all vertices of the projection surfaces
@ -127,33 +116,44 @@ void ProjectionEditor::mouseDragged(ofMouseEventArgs &args)
} }
} }
void ProjectionEditor::keyPressed(ofKeyEventArgs &args) void ProjectionEditor::keyPressed(ofKeyEventArgs& args) {
{
int key = args.key; int key = args.key;
float moveStep; float moveStep;
if (bShiftKeyDown) moveStep = 10.0f; if (bShiftKeyDown)
else moveStep = 0.5f; moveStep = 10.0f;
else
moveStep = 0.5f;
switch (key) { switch (key) {
case OF_KEY_LEFT: moveSelection(ofVec2f(-moveStep,0.0f)); break; case OF_KEY_LEFT:
case OF_KEY_RIGHT: moveSelection(ofVec2f(moveStep,0.0f)); break; moveSelection(ofVec2f(-moveStep, 0.0f));
case OF_KEY_UP: moveSelection(ofVec2f(0.0f,-moveStep)); break; break;
case OF_KEY_DOWN: moveSelection(ofVec2f(0.0f,moveStep)); break; case OF_KEY_RIGHT:
case OF_KEY_SHIFT: bShiftKeyDown = true; break; moveSelection(ofVec2f(moveStep, 0.0f));
break;
case OF_KEY_UP:
moveSelection(ofVec2f(0.0f, -moveStep));
break;
case OF_KEY_DOWN:
moveSelection(ofVec2f(0.0f, moveStep));
break;
case OF_KEY_SHIFT:
bShiftKeyDown = true;
break;
} }
} }
void ProjectionEditor::keyReleased(ofKeyEventArgs &args) void ProjectionEditor::keyReleased(ofKeyEventArgs& args) {
{
int key = args.key; int key = args.key;
switch (key) { switch (key) {
case OF_KEY_SHIFT: bShiftKeyDown = false; break; case OF_KEY_SHIFT:
bShiftKeyDown = false;
break;
} }
} }
void ProjectionEditor::gotMessage(ofMessage& msg) void ProjectionEditor::gotMessage(ofMessage& msg) {
{
if (msg.message == "surfaceSelected") { if (msg.message == "surfaceSelected") {
// refresh gui // refresh gui
clearJoints(); clearJoints();
@ -161,21 +161,18 @@ void ProjectionEditor::gotMessage(ofMessage& msg)
} }
} }
void ProjectionEditor::setSurfaceManager(SurfaceManager *newSurfaceManager) void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) {
{
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
} }
void ProjectionEditor::clearJoints() void ProjectionEditor::clearJoints() {
{
while (joints.size()) { while (joints.size()) {
delete joints.back(); delete joints.back();
joints.pop_back(); joints.pop_back();
} }
} }
void ProjectionEditor::createJoints() void ProjectionEditor::createJoints() {
{
if (surfaceManager == NULL) return; if (surfaceManager == NULL) return;
clearJoints(); clearJoints();
@ -184,7 +181,8 @@ void ProjectionEditor::createJoints()
return; return;
} }
vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices(); vector<ofVec3f>& vertices =
surfaceManager->getSelectedSurface()->getVertices();
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());
@ -192,42 +190,39 @@ void ProjectionEditor::createJoints()
} }
} }
void ProjectionEditor::updateJoints() void ProjectionEditor::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 = ofVec2f(vertices[i].x, vertices[i].y);
} }
} }
void ProjectionEditor::unselectAllJoints() void ProjectionEditor::unselectAllJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->unselect(); joints[i]->unselect();
} }
} }
void ProjectionEditor::moveSelectedSurface(ofVec2f by) void ProjectionEditor::moveSelectedSurface(ofVec2f by) {
{
if (surfaceManager == NULL) return; if (surfaceManager == NULL) return;
if (surfaceManager->getSelectedSurface() == NULL) return; if (surfaceManager->getSelectedSurface() == NULL) return;
surfaceManager->getSelectedSurface()->moveBy(by); surfaceManager->getSelectedSurface()->moveBy(by);
/*vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices(); /*vector<ofVec3f>& vertices =
surfaceManager->getSelectedSurface()->getVertices();
for (int i=0; i<vertices.size(); i++) { for (int i=0; i<vertices.size(); i++) {
vertices[i] += by; vertices[i] += by;
}*/ }*/
updateJoints(); updateJoints();
} }
void ProjectionEditor::stopDragJoints() void ProjectionEditor::stopDragJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->stopDrag(); joints[i]->stopDrag();
} }
} }
void ProjectionEditor::moveSelection(ofVec2f by) void ProjectionEditor::moveSelection(ofVec2f by) {
{
// check if joints selected // check if joints selected
bool bJointSelected = false; bool bJointSelected = false;
BaseJoint* selectedJoint; BaseJoint* selectedJoint;
@ -246,13 +241,11 @@ void ProjectionEditor::moveSelection(ofVec2f by)
} }
} }
void ProjectionEditor::setSnapDistance(float newSnapDistance) void ProjectionEditor::setSnapDistance(float newSnapDistance) {
{
fSnapDistance = newSnapDistance; fSnapDistance = newSnapDistance;
} }
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f 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];
@ -261,10 +254,10 @@ CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos)
return NULL; return NULL;
} }
void ProjectionEditor::drawJoints() void ProjectionEditor::drawJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->draw(); joints[i]->draw();
} }
} }
}} }
}

7
src/ProjectionEditor.h

@ -5,8 +5,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class ProjectionEditor class ProjectionEditor {
{
public: public:
ProjectionEditor(); ProjectionEditor();
~ProjectionEditor(); ~ProjectionEditor();
@ -47,5 +46,5 @@ private:
void drawJoints(); void drawJoints();
}; };
}
}} }

67
src/QuadSurface.cpp

@ -2,19 +2,14 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
QuadSurface::QuadSurface() QuadSurface::QuadSurface() {
{
cout << "QuadSurface constructor." << endl; cout << "QuadSurface constructor." << endl;
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); ofVec2f p1 = ofVec2f(0, 0);
ofVec2f p2 = ofVec2f(0, ofGetHeight()); ofVec2f p2 = ofVec2f(0, ofGetHeight());
@ -31,8 +26,8 @@ void QuadSurface::setup()
} }
void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4,
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr ) ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4,
{ ofTexture* texturePtr) {
// Assign texture // Assign texture
texture = texturePtr; texture = texturePtr;
@ -72,8 +67,7 @@ void QuadSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4,
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::draw() void QuadSurface::draw() {
{
/*if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){ /*if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
calculate4dTextureCoords(); calculate4dTextureCoords();
}*/ }*/
@ -86,8 +80,7 @@ void QuadSurface::draw()
texture->unbind(); texture->unbind();
} }
void QuadSurface::setVertex(int index, ofVec2f p) void QuadSurface::setVertex(int index, ofVec2f 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;
@ -97,10 +90,10 @@ void QuadSurface::setVertex(int index, ofVec2f p)
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::setTexCoord(int index, ofVec2f t) void QuadSurface::setTexCoord(int index, ofVec2f t) {
{
if (index > 3) { if (index > 3) {
ofLog() << "Texture coordinate with this index does not exist: " << index << endl; ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl;
return; return;
} }
@ -108,8 +101,7 @@ void QuadSurface::setTexCoord(int index, ofVec2f t)
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
void QuadSurface::moveBy(ofVec2f v) void QuadSurface::moveBy(ofVec2f 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;
@ -117,13 +109,9 @@ void QuadSurface::moveBy(ofVec2f v)
calculate4dTextureCoords(); calculate4dTextureCoords();
} }
int QuadSurface::getType() int QuadSurface::getType() { return SurfaceType::QUAD_SURFACE; }
{
return SurfaceType::QUAD_SURFACE;
}
bool QuadSurface::hitTest(ofVec2f p) bool QuadSurface::hitTest(ofVec2f p) {
{
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
@ -134,8 +122,7 @@ bool QuadSurface::hitTest(ofVec2f p)
} }
} }
ofVec2f QuadSurface::getVertex(int index) ofVec2f 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 std::runtime_error("Vertex index out of bounds."); throw std::runtime_error("Vertex index out of bounds.");
@ -145,8 +132,7 @@ ofVec2f QuadSurface::getVertex(int index)
return ofVec2f(vert.x, vert.y); return ofVec2f(vert.x, vert.y);
} }
ofVec2f QuadSurface::getTexCoord(int index) ofVec2f QuadSurface::getTexCoord(int index) {
{
if (index > 3) { if (index > 3) {
throw std::runtime_error("Texture coordinate index out of bounds."); throw std::runtime_error("Texture coordinate index out of bounds.");
} }
@ -154,8 +140,7 @@ ofVec2f QuadSurface::getTexCoord(int index)
return mesh.getTexCoord(index); return mesh.getTexCoord(index);
} }
ofPolyline QuadSurface::getHitArea() ofPolyline QuadSurface::getHitArea() {
{
ofPolyline line; ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); 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(1).x, mesh.getVertex(1).y));
@ -166,8 +151,7 @@ ofPolyline QuadSurface::getHitArea()
return line; return line;
} }
ofPolyline QuadSurface::getTextureHitArea() ofPolyline QuadSurface::getTextureHitArea() {
{
ofPolyline line; ofPolyline line;
vector<ofVec2f>& texCoords = mesh.getTexCoords(); vector<ofVec2f>& texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight());
@ -179,20 +163,14 @@ ofPolyline QuadSurface::getTextureHitArea()
return line; return line;
} }
vector<ofVec3f>& QuadSurface::getVertices() vector<ofVec3f>& QuadSurface::getVertices() {
{
// return only joint vertices // return only joint vertices
return mesh.getVertices(); return mesh.getVertices();
} }
vector<ofVec2f>& QuadSurface::getTexCoords() vector<ofVec2f>& QuadSurface::getTexCoords() { return mesh.getTexCoords(); }
{
return mesh.getTexCoords();
}
void QuadSurface::calculate4dTextureCoords() void QuadSurface::calculate4dTextureCoords() {
{
// Perspective Warping with OpenGL Fixed Pipeline and q coordinates // Perspective Warping with OpenGL Fixed Pipeline and q coordinates
// see: // see:
// http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/ // http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/
@ -260,7 +238,6 @@ void QuadSurface::calculate4dTextureCoords()
quadTexCoordinates[12] = t3.x; quadTexCoordinates[12] = t3.x;
quadTexCoordinates[13] = t3.y * q3; quadTexCoordinates[13] = t3.y * q3;
quadTexCoordinates[15] = q3; quadTexCoordinates[15] = q3;
} }
}
}} }

13
src/QuadSurface.h

@ -6,17 +6,15 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class QuadSurface : public BaseSurface class QuadSurface : public BaseSurface {
{
public: public:
QuadSurface(); QuadSurface();
~QuadSurface(); ~QuadSurface();
void setup(); void setup();
void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, ofVec2f t1,
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr);
ofTexture* texturePtr );
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, ofVec2f p);
@ -31,11 +29,12 @@ public:
ofPolyline getTextureHitArea(); ofPolyline getTextureHitArea();
vector<ofVec3f>& getVertices(); vector<ofVec3f>& getVertices();
vector<ofVec2f>& getTexCoords(); vector<ofVec2f>& getTexCoords();
private: private:
void calculate4dTextureCoords(); void calculate4dTextureCoords();
GLfloat quadVertices[12]; GLfloat quadVertices[12];
GLubyte quadIndices[6]; GLubyte quadIndices[6];
GLfloat quadTexCoordinates[16]; GLfloat quadTexCoordinates[16];
}; };
}
}} }

50
src/SourcesEditor.cpp

@ -2,14 +2,12 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SourcesEditor::SourcesEditor() SourcesEditor::SourcesEditor() {
{
defImgDir = DEFAULT_IMAGES_DIR; defImgDir = DEFAULT_IMAGES_DIR;
registerAppEvents(); registerAppEvents();
} }
SourcesEditor::~SourcesEditor() SourcesEditor::~SourcesEditor() {
{
unregisterAppEvents(); unregisterAppEvents();
delete gui; delete gui;
while (images.size()) { while (images.size()) {
@ -18,18 +16,15 @@ SourcesEditor::~SourcesEditor()
} }
} }
void SourcesEditor::registerAppEvents() void SourcesEditor::registerAppEvents() {
{
ofAddListener(ofEvents().setup, this, &SourcesEditor::setup); ofAddListener(ofEvents().setup, this, &SourcesEditor::setup);
} }
void SourcesEditor::unregisterAppEvents() void SourcesEditor::unregisterAppEvents() {
{
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup);
} }
void SourcesEditor::setup(ofEventArgs& args) void SourcesEditor::setup(ofEventArgs& args) {
{
gui = new RadioList(); gui = new RadioList();
// read directory contents // read directory contents
@ -49,8 +44,7 @@ void SourcesEditor::setup(ofEventArgs& args)
ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent); ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent);
} }
void SourcesEditor::draw() void SourcesEditor::draw() {
{
// Don't draw if there is no source selected // Don't draw if there is no source selected
if (surfaceManager->getSelectedSurface() == NULL) { if (surfaceManager->getSelectedSurface() == NULL) {
return; return;
@ -59,8 +53,7 @@ void SourcesEditor::draw()
gui->draw(); gui->draw();
} }
void SourcesEditor::loadImage( string name, string path ) void SourcesEditor::loadImage(string name, string path) {
{
images.push_back(new ofImage()); images.push_back(new ofImage());
images.back()->loadImage(path); images.back()->loadImage(path);
@ -69,13 +62,9 @@ void SourcesEditor::loadImage( string name, string path )
ofSendMessage("imageLoaded"); ofSendMessage("imageLoaded");
} }
void SourcesEditor::disable() void SourcesEditor::disable() { gui->disable(); }
{
gui->disable();
}
void SourcesEditor::enable() void SourcesEditor::enable() {
{
// Don't enable if there is no surface selected // Don't enable if there is no surface selected
if (surfaceManager->getSelectedSurface() == NULL) { if (surfaceManager->getSelectedSurface() == NULL) {
cout << "No surface selected. Not enable()ing source list." << endl; cout << "No surface selected. Not enable()ing source list." << endl;
@ -85,13 +74,11 @@ void SourcesEditor::enable()
gui->enable(); gui->enable();
} }
void SourcesEditor::setSurfaceManager(SurfaceManager *newSurfaceManager) void SourcesEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) {
{
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
} }
void SourcesEditor::selectImageSourceRadioButton(string name) void SourcesEditor::selectImageSourceRadioButton(string name) {
{
if (name == "none") { if (name == "none") {
gui->unselectAll(); gui->unselectAll();
return; return;
@ -106,13 +93,9 @@ void SourcesEditor::selectImageSourceRadioButton(string name)
} }
} }
int SourcesEditor::getLoadedTexCount() int SourcesEditor::getLoadedTexCount() { return images.size(); }
{
return images.size();
}
ofTexture* SourcesEditor::getTexture(int index) ofTexture* SourcesEditor::getTexture(int index) {
{
if (index >= images.size()) { if (index >= images.size()) {
throw std::runtime_error("Texture index out of bounds."); throw std::runtime_error("Texture index out of bounds.");
} }
@ -120,8 +103,7 @@ ofTexture* SourcesEditor::getTexture(int index)
return &images[index]->getTextureReference(); return &images[index]->getTextureReference();
} }
void SourcesEditor::guiEvent(string &imageName) void SourcesEditor::guiEvent(string& imageName) {
{
string name = imageName; string name = imageName;
if (surfaceManager->getSelectedSurface() == NULL) { if (surfaceManager->getSelectedSurface() == NULL) {
@ -135,5 +117,5 @@ void SourcesEditor::guiEvent(string &imageName)
surfaceManager->getSelectedSurface()->setTexture(texture); surfaceManager->getSelectedSurface()->setTexture(texture);
surfaceManager->manageMemory(); surfaceManager->manageMemory();
} }
}
}} }

7
src/SourcesEditor.h

@ -9,8 +9,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SourcesEditor class SourcesEditor {
{
public: public:
SourcesEditor(); SourcesEditor();
~SourcesEditor(); ~SourcesEditor();
@ -37,5 +36,5 @@ private:
vector<ofImage*> images; vector<ofImage*> images;
vector<string> imageNames; vector<string> imageNames;
}; };
}
}} }

188
src/SurfaceManager.cpp

@ -2,59 +2,47 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SurfaceManager::SurfaceManager() SurfaceManager::SurfaceManager() {}
{
} SurfaceManager::~SurfaceManager() { clear(); }
SurfaceManager::~SurfaceManager() void SurfaceManager::draw() {
{
clear();
}
void SurfaceManager::draw()
{
for (int i = 0; i < surfaces.size(); i++) { for (int i = 0; i < surfaces.size(); i++) {
surfaces[i]->draw(); surfaces[i]->draw();
} }
} }
void SurfaceManager::addSurface(int surfaceType) void SurfaceManager::addSurface(int surfaceType) {
{
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if (surfaceType == SurfaceType::TRIANGLE_SURFACE) {
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
} } else if (surfaceType == SurfaceType::QUAD_SURFACE) {
else if (surfaceType == SurfaceType::QUAD_SURFACE ) {
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
} } else {
else {
throw std::runtime_error("Attempt to add non-existing surface type."); throw std::runtime_error("Attempt to add non-existing surface type.");
} }
} }
void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr) void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr) {
{
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if (surfaceType == SurfaceType::TRIANGLE_SURFACE) {
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
surfaces.back()->setTexture(texturePtr); surfaces.back()->setTexture(texturePtr);
} } else if (surfaceType == SurfaceType::QUAD_SURFACE) {
else if (surfaceType == SurfaceType::QUAD_SURFACE ) {
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
surfaces.back()->setTexture(texturePtr); surfaces.back()->setTexture(texturePtr);
} } else {
else {
throw std::runtime_error("Attempt to add non-existing surface type."); throw std::runtime_error("Attempt to add non-existing surface type.");
} }
} }
void SurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, vector<ofVec2f> texCoords) void SurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices,
{ vector<ofVec2f> texCoords) {
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if (surfaceType == SurfaceType::TRIANGLE_SURFACE) {
if (vertices.size() < 3) { if (vertices.size() < 3) {
throw std::runtime_error("There must be 3 vertices for a triangle surface."); throw std::runtime_error(
"There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) { } else if (texCoords.size() < 3) {
throw std::runtime_error("There must be 3 texture coordinates for a triangle surface."); throw std::runtime_error(
"There must be 3 texture coordinates for a triangle surface.");
} }
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
@ -64,12 +52,12 @@ void SurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, vecto
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} } else if (surfaceType == SurfaceType::QUAD_SURFACE) {
else if (surfaceType == SurfaceType::QUAD_SURFACE ) {
if (vertices.size() < 4) { if (vertices.size() < 4) {
throw std::runtime_error("There must be 4 vertices for a quad surface."); throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) { } else if (texCoords.size() < 4) {
throw std::runtime_error("There must be 4 texture coordinates for a quad surface."); throw std::runtime_error(
"There must be 4 texture coordinates for a quad surface.");
} }
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
@ -78,21 +66,21 @@ void SurfaceManager::addSurface(int surfaceType, vector<ofVec2f> vertices, vecto
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} } else {
else {
throw std::runtime_error("Attempt to add non-existing surface type."); throw std::runtime_error("Attempt to add non-existing surface type.");
} }
} }
void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vector<ofVec2f> vertices, vector<ofVec2f> texCoords) void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr,
{ vector<ofVec2f> vertices,
vector<ofVec2f> texCoords) {
if (surfaceType == SurfaceType::TRIANGLE_SURFACE) { if (surfaceType == SurfaceType::TRIANGLE_SURFACE) {
if (vertices.size() < 3) { if (vertices.size() < 3) {
throw std::runtime_error("There must be 3 vertices for a triangle surface."); throw std::runtime_error(
"There must be 3 vertices for a triangle surface.");
} else if (texCoords.size() < 3) { } else if (texCoords.size() < 3) {
throw std::runtime_error("Thre must be 3 texture coordinates for a triangle surface."); throw std::runtime_error(
"Thre must be 3 texture coordinates for a triangle surface.");
} }
surfaces.push_back(new TriangleSurface()); surfaces.push_back(new TriangleSurface());
@ -103,12 +91,12 @@ void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vector<o
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} } else if (surfaceType == SurfaceType::QUAD_SURFACE) {
else if (surfaceType == SurfaceType::QUAD_SURFACE ) {
if (vertices.size() < 4) { if (vertices.size() < 4) {
throw std::runtime_error("There must be 4 vertices for a quad surface."); throw std::runtime_error("There must be 4 vertices for a quad surface.");
} else if (texCoords.size() < 4) { } else if (texCoords.size() < 4) {
throw std::runtime_error("Thre must be 4 texture coordinates for a quad surface."); throw std::runtime_error(
"Thre must be 4 texture coordinates for a quad surface.");
} }
surfaces.push_back(new QuadSurface()); surfaces.push_back(new QuadSurface());
@ -118,14 +106,12 @@ void SurfaceManager::addSurface(int surfaceType, ofTexture* texturePtr, vector<o
surfaces.back()->setVertex(i, vertices[i]); surfaces.back()->setVertex(i, vertices[i]);
surfaces.back()->setTexCoord(i, texCoords[i]); surfaces.back()->setTexCoord(i, texCoords[i]);
} }
} } else {
else {
throw std::runtime_error("Attempt to add non-existing surface type."); throw std::runtime_error("Attempt to add non-existing surface type.");
} }
} }
void SurfaceManager::removeSelectedSurface() void SurfaceManager::removeSelectedSurface() {
{
if (selectedSurface == NULL) return; if (selectedSurface == NULL) return;
for (int i = 0; i < surfaces.size(); i++) { for (int i = 0; i < surfaces.size(); i++) {
@ -138,14 +124,14 @@ void SurfaceManager::removeSelectedSurface()
} }
} }
void SurfaceManager::manageMemory() void SurfaceManager::manageMemory() {
{
// check if each of the sources is assigned to a surface or not // check if each of the sources is assigned to a surface or not
for (int i = 0; i < loadedImageSources.size(); i++) { for (int i = 0; i < loadedImageSources.size(); i++) {
bool bAssigned = false; bool bAssigned = false;
for (int j = 0; j < surfaces.size(); j++) { for (int j = 0; j < surfaces.size(); j++) {
if ( surfaces[j]->getTexture() == &loadedImageSources[i]->getTextureReference() ) { if (surfaces[j]->getTexture() ==
&loadedImageSources[i]->getTextureReference()) {
bAssigned = true; bAssigned = true;
break; break;
} }
@ -162,8 +148,7 @@ void SurfaceManager::manageMemory()
} }
} }
void SurfaceManager::clear() void SurfaceManager::clear() {
{
// delete all extra allocations from the heap // delete all extra allocations from the heap
while (surfaces.size()) { while (surfaces.size()) {
delete surfaces.back(); delete surfaces.back();
@ -190,15 +175,13 @@ void SurfaceManager::clear()
// } // }
// } // }
void SurfaceManager::saveXmlSettings(string fileName) void SurfaceManager::saveXmlSettings(string fileName) {
{
xmlSettings.clear(); xmlSettings.clear();
// save surfaces // save surfaces
xmlSettings.addTag("surfaces"); xmlSettings.addTag("surfaces");
xmlSettings.pushTag("surfaces"); xmlSettings.pushTag("surfaces");
for (int i = 0; i < surfaces.size(); i++) { for (int i = 0; i < surfaces.size(); i++) {
xmlSettings.addTag("surface"); xmlSettings.addTag("surface");
xmlSettings.pushTag("surface", i); xmlSettings.pushTag("surface", i);
BaseSurface* surface = surfaces[i]; BaseSurface* surface = surfaces[i];
@ -240,7 +223,6 @@ void SurfaceManager::saveXmlSettings(string fileName)
// xmlSettings.addValue("source-path", "/root/etc/image.jpg"); // xmlSettings.addValue("source-path", "/root/etc/image.jpg");
xmlSettings.popTag(); // source xmlSettings.popTag(); // source
// xmlSettings.addTag("type"); // xmlSettings.addTag("type");
// xmlSettings.pushTag("type"); // xmlSettings.pushTag("type");
// // surfaceType == SurfaceType::TRIANGLE_SURFACE // // surfaceType == SurfaceType::TRIANGLE_SURFACE
@ -255,10 +237,7 @@ void SurfaceManager::saveXmlSettings(string fileName)
xmlSettings.save(fileName); xmlSettings.save(fileName);
} }
void SurfaceManager::loadXmlSettings(string fileName) void SurfaceManager::loadXmlSettings(string fileName) {
{
if (!xmlSettings.loadFile(fileName)) { if (!xmlSettings.loadFile(fileName)) {
ofLog(OF_LOG_WARNING, "Could not load XML settings."); ofLog(OF_LOG_WARNING, "Could not load XML settings.");
return; return;
@ -289,30 +268,31 @@ void SurfaceManager::loadXmlSettings(string fileName)
// // attempt to load surface type // // attempt to load surface type
// ofLog(OF_LOG_WARNING, "Attempt to load surface type."); // ofLog(OF_LOG_WARNING, "Attempt to load surface type.");
// xmlSettings.pushTag("type"); // xmlSettings.pushTag("type");
// string surfaceType = xmlSettings.getValue("surface-type", "TRIANGLE_SURFACE"); // string surfaceType = xmlSettings.getValue("surface-type",
// "TRIANGLE_SURFACE");
// xmlSettings.popTag(); // type // xmlSettings.popTag(); // type
xmlSettings.pushTag("vertices"); xmlSettings.pushTag("vertices");
vector<ofVec2f> vertices; vector<ofVec2f> vertices;
int vertexCount = xmlSettings.getNumTags("vertex"); int vertexCount = xmlSettings.getNumTags("vertex");
// it's a triangle ? // it's a triangle ?
if (vertexCount == 3) if (vertexCount == 3) {
{
ofLog(OF_LOG_NOTICE, "create Triangle"); ofLog(OF_LOG_NOTICE, "create Triangle");
xmlSettings.pushTag("vertex", 0); xmlSettings.pushTag("vertex", 0);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("vertex", 1); xmlSettings.pushTag("vertex", 1);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 100.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("vertex", 2); xmlSettings.pushTag("vertex", 2);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 100.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.popTag(); // vertices xmlSettings.popTag(); // vertices
@ -322,24 +302,27 @@ void SurfaceManager::loadXmlSettings(string fileName)
vector<ofVec2f> texCoords; vector<ofVec2f> texCoords;
xmlSettings.pushTag("texCoord", 0); xmlSettings.pushTag("texCoord", 0);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 1); xmlSettings.pushTag("texCoord", 1);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 1.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 2); xmlSettings.pushTag("texCoord", 2);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 1.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.popTag(); // texCoords xmlSettings.popTag(); // texCoords
// now we have variables sourceName and sourceTexture // now we have variables sourceName and sourceTexture
// by checking those we can use one or another addSurface method // by checking those we can use one or another addSurface method
if (sourceName != "none" && sourceTexture != NULL) { if (sourceName != "none" && sourceTexture != NULL) {
addSurface(SurfaceType::TRIANGLE_SURFACE, sourceTexture, vertices, texCoords); addSurface(SurfaceType::TRIANGLE_SURFACE, sourceTexture, vertices,
texCoords);
} else { } else {
addSurface(SurfaceType::TRIANGLE_SURFACE, vertices, texCoords); addSurface(SurfaceType::TRIANGLE_SURFACE, vertices, texCoords);
} }
@ -349,19 +332,23 @@ void SurfaceManager::loadXmlSettings(string fileName)
// if (surface-type == QUAD_SURFACE) // if (surface-type == QUAD_SURFACE)
{ {
xmlSettings.pushTag("vertex", 0); xmlSettings.pushTag("vertex", 0);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("vertex", 1); xmlSettings.pushTag("vertex", 1);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 0.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 100.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("vertex", 2); xmlSettings.pushTag("vertex", 2);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 100.0f), xmlSettings.getValue("y", 100.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 100.0f),
xmlSettings.getValue("y", 100.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("vertex", 3); xmlSettings.pushTag("vertex", 3);
vertices.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 100.0f) ) ); vertices.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 100.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.popTag(); // vertices xmlSettings.popTag(); // vertices
@ -371,33 +358,35 @@ void SurfaceManager::loadXmlSettings(string fileName)
vector<ofVec2f> texCoords; vector<ofVec2f> texCoords;
xmlSettings.pushTag("texCoord", 0); xmlSettings.pushTag("texCoord", 0);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 0.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 1); xmlSettings.pushTag("texCoord", 1);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 0.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 1.0f),
xmlSettings.getValue("y", 0.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 2); xmlSettings.pushTag("texCoord", 2);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 1.0f), xmlSettings.getValue("y", 1.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 1.0f),
xmlSettings.getValue("y", 1.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.pushTag("texCoord", 3); xmlSettings.pushTag("texCoord", 3);
texCoords.push_back( ofVec2f( xmlSettings.getValue("x", 0.0f), xmlSettings.getValue("y", 1.0f) ) ); texCoords.push_back(ofVec2f(xmlSettings.getValue("x", 0.0f),
xmlSettings.getValue("y", 1.0f)));
xmlSettings.popTag(); xmlSettings.popTag();
xmlSettings.popTag(); // texCoords xmlSettings.popTag(); // texCoords
// now we have variables sourceName and sourceTexture // now we have variables sourceName and sourceTexture
// by checking those we can use one or another addSurface method // by checking those we can use one or another addSurface method
if (sourceName != "none" && sourceTexture != NULL) { if (sourceName != "none" && sourceTexture != NULL) {
addSurface(SurfaceType::QUAD_SURFACE, sourceTexture, vertices, texCoords); addSurface(SurfaceType::QUAD_SURFACE, sourceTexture, vertices,
texCoords);
} else { } else {
addSurface(SurfaceType::QUAD_SURFACE, vertices, texCoords); addSurface(SurfaceType::QUAD_SURFACE, vertices, texCoords);
} }
} }
xmlSettings.popTag(); // surface xmlSettings.popTag(); // surface
@ -406,8 +395,7 @@ void SurfaceManager::loadXmlSettings(string fileName)
xmlSettings.popTag(); // surfaces xmlSettings.popTag(); // surfaces
} }
BaseSurface* SurfaceManager::selectSurface(int index) BaseSurface* SurfaceManager::selectSurface(int index) {
{
if (index >= surfaces.size()) { if (index >= surfaces.size()) {
throw std::runtime_error("Surface index out of bounds."); throw std::runtime_error("Surface index out of bounds.");
} }
@ -418,18 +406,11 @@ BaseSurface* SurfaceManager::selectSurface(int index)
ofSendMessage("surfaceSelected"); ofSendMessage("surfaceSelected");
} }
BaseSurface* SurfaceManager::getSelectedSurface() BaseSurface* SurfaceManager::getSelectedSurface() { return selectedSurface; }
{
return selectedSurface;
}
void SurfaceManager::deselectSurface() void SurfaceManager::deselectSurface() { selectedSurface = NULL; }
{
selectedSurface = NULL;
}
ofTexture* SurfaceManager::loadImageSource(string name, string path) ofTexture* SurfaceManager::loadImageSource(string name, string path) {
{
// check if it is loaded // check if it is loaded
for (int i = 0; i < loadedImageSourceNames.size(); i++) { for (int i = 0; i < loadedImageSourceNames.size(); i++) {
if (loadedImageSourceNames[i] == name) { if (loadedImageSourceNames[i] == name) {
@ -448,8 +429,7 @@ ofTexture* SurfaceManager::loadImageSource(string name, string path)
return &image->getTextureReference(); return &image->getTextureReference();
} }
string SurfaceManager::getSelectedSurfaceSourceName() string SurfaceManager::getSelectedSurfaceSourceName() {
{
if (selectedSurface == NULL) { if (selectedSurface == NULL) {
return "none"; return "none";
} }
@ -457,8 +437,7 @@ string SurfaceManager::getSelectedSurfaceSourceName()
return getSurfaceSourceName(selectedSurface); return getSurfaceSourceName(selectedSurface);
} }
string SurfaceManager::getSurfaceSourceName(BaseSurface *surface) string SurfaceManager::getSurfaceSourceName(BaseSurface* surface) {
{
ofTexture* tex = surface->getTexture(); ofTexture* tex = surface->getTexture();
for (int i = 0; i < loadedImageSources.size(); i++) { for (int i = 0; i < loadedImageSources.size(); i++) {
if (tex == &loadedImageSources[i]->getTextureReference()) { if (tex == &loadedImageSources[i]->getTextureReference()) {
@ -469,8 +448,7 @@ string SurfaceManager::getSurfaceSourceName(BaseSurface *surface)
return "none"; return "none";
} }
BaseSurface* SurfaceManager::getSurface(int index) BaseSurface* SurfaceManager::getSurface(int index) {
{
if (index >= surfaces.size()) { if (index >= surfaces.size()) {
throw std::runtime_error("Surface index out of bounds."); throw std::runtime_error("Surface index out of bounds.");
return NULL; return NULL;
@ -479,10 +457,6 @@ BaseSurface* SurfaceManager::getSurface(int index)
return surfaces[index]; return surfaces[index];
} }
int SurfaceManager::size() int SurfaceManager::size() { return surfaces.size(); }
{ }
return surfaces.size();
} }
}}

15
src/SurfaceManager.h

@ -10,11 +10,9 @@
using namespace std; using namespace std;
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SurfaceManager class SurfaceManager {
{
public: public:
SurfaceManager(); SurfaceManager();
~SurfaceManager(); ~SurfaceManager();
@ -22,8 +20,10 @@ public:
void draw(); void draw();
void addSurface(int surfaceType); void addSurface(int surfaceType);
void addSurface(int surfaceType, ofTexture* texturePtr); void addSurface(int surfaceType, ofTexture* texturePtr);
void addSurface(int surfaceType, vector<ofVec2f> vertices, vector<ofVec2f> texCoords); void addSurface(int surfaceType, vector<ofVec2f> vertices,
void addSurface(int surfaceType, ofTexture* texturePtr, vector<ofVec2f> vertices, vector<ofVec2f> texCoords); vector<ofVec2f> texCoords);
void addSurface(int surfaceType, ofTexture* texturePtr,
vector<ofVec2f> vertices, vector<ofVec2f> texCoords);
void removeSelectedSurface(); void removeSelectedSurface();
void manageMemory(); // deletes unasigned sources void manageMemory(); // deletes unasigned sources
void clear(); void clear();
@ -45,7 +45,6 @@ private:
vector<string> loadedImageSourceNames; vector<string> loadedImageSourceNames;
vector<ofImage*> loadedImageSources; vector<ofImage*> loadedImageSources;
ofxXmlSettings xmlSettings; ofxXmlSettings xmlSettings;
}; };
}
}} }

87
src/SurfaceManagerGui.cpp

@ -2,8 +2,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
SurfaceManagerGui::SurfaceManagerGui() SurfaceManagerGui::SurfaceManagerGui() {
{
surfaceManager = NULL; surfaceManager = NULL;
guiMode = GuiMode::NONE; guiMode = GuiMode::NONE;
bDrag = false; bDrag = false;
@ -11,34 +10,35 @@ SurfaceManagerGui::SurfaceManagerGui()
ofHideCursor(); ofHideCursor();
} }
SurfaceManagerGui::~SurfaceManagerGui() SurfaceManagerGui::~SurfaceManagerGui() {
{
unregisterMouseEvents(); unregisterMouseEvents();
surfaceManager = NULL; surfaceManager = NULL;
} }
void SurfaceManagerGui::registerMouseEvents() void SurfaceManagerGui::registerMouseEvents() {
{ ofAddListener(ofEvents().mousePressed, this,
ofAddListener(ofEvents().mousePressed, this, &SurfaceManagerGui::mousePressed); &SurfaceManagerGui::mousePressed);
ofAddListener(ofEvents().mouseReleased, this, &SurfaceManagerGui::mouseReleased); ofAddListener(ofEvents().mouseReleased, this,
ofAddListener(ofEvents().mouseDragged, this, &SurfaceManagerGui::mouseDragged); &SurfaceManagerGui::mouseReleased);
ofAddListener(ofEvents().mouseDragged, this,
&SurfaceManagerGui::mouseDragged);
} }
void SurfaceManagerGui::unregisterMouseEvents() void SurfaceManagerGui::unregisterMouseEvents() {
{ ofRemoveListener(ofEvents().mousePressed, this,
ofRemoveListener(ofEvents().mousePressed, this, &SurfaceManagerGui::mousePressed); &SurfaceManagerGui::mousePressed);
ofRemoveListener(ofEvents().mouseReleased, this, &SurfaceManagerGui::mouseReleased); ofRemoveListener(ofEvents().mouseReleased, this,
ofRemoveListener(ofEvents().mouseDragged, this, &SurfaceManagerGui::mouseDragged); &SurfaceManagerGui::mouseReleased);
ofRemoveListener(ofEvents().mouseDragged, this,
&SurfaceManagerGui::mouseDragged);
} }
void SurfaceManagerGui::draw() void SurfaceManagerGui::draw() {
{
if (surfaceManager == NULL) return; if (surfaceManager == NULL) return;
if (guiMode == GuiMode::NONE) { if (guiMode == GuiMode::NONE) {
surfaceManager->draw(); surfaceManager->draw();
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { } else if (guiMode == GuiMode::TEXTURE_MAPPING) {
// draw the texture of the selected surface // draw the texture of the selected surface
if (surfaceManager->getSelectedSurface() != NULL) { if (surfaceManager->getSelectedSurface() != NULL) {
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0));
@ -60,7 +60,6 @@ void SurfaceManagerGui::draw()
textureEditor.draw(); textureEditor.draw();
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { } else if (guiMode == GuiMode::PROJECTION_MAPPING) {
// draw projection surfaces first // draw projection surfaces first
surfaceManager->draw(); surfaceManager->draw();
@ -81,15 +80,14 @@ void SurfaceManagerGui::draw()
} }
} }
void SurfaceManagerGui::mousePressed(ofMouseEventArgs &args) void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) {
{
if (guiMode == GuiMode::NONE) { if (guiMode == GuiMode::NONE) {
return; return;
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { } else if (guiMode == GuiMode::TEXTURE_MAPPING) {
bool bSurfaceSelected = false; bool bSurfaceSelected = false;
CircleJoint* hitJoint = textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); CircleJoint* hitJoint =
textureEditor.hitTestJoints(ofVec2f(args.x, args.y));
if (hitJoint != NULL) { if (hitJoint != NULL) {
textureEditor.unselectAllJoints(); textureEditor.unselectAllJoints();
hitJoint->select(); hitJoint->select();
@ -101,17 +99,18 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) {
// hittest texture area to see if we are hitting the texture surface // hittest texture area to see if we are hitting the texture surface
if ( surfaceManager->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y) ) { if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside(
args.x, args.y)) {
clickPosition = ofVec2f(args.x, args.y); clickPosition = ofVec2f(args.x, args.y);
startDrag(); startDrag();
} }
} }
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { } else if (guiMode == GuiMode::PROJECTION_MAPPING) {
bool bSurfaceSelected = false; bool bSurfaceSelected = false;
CircleJoint* hitJoint = projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); CircleJoint* hitJoint =
projectionEditor.hitTestJoints(ofVec2f(args.x, args.y));
if (hitJoint != NULL) { if (hitJoint != NULL) {
projectionEditor.unselectAllJoints(); projectionEditor.unselectAllJoints();
hitJoint->select(); hitJoint->select();
@ -133,7 +132,8 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
} }
if (bSurfaceSelected && hitJoint == NULL) { if (bSurfaceSelected && hitJoint == NULL) {
// if not hitting the joints, start drag only if we have a selected surface // if not hitting the joints, start drag only if we have a selected
// surface
clickPosition = ofVec2f(args.x, args.y); clickPosition = ofVec2f(args.x, args.y);
startDrag(); startDrag();
} }
@ -144,19 +144,16 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
surfaceManager->deselectSurface(); surfaceManager->deselectSurface();
} }
} else if (guiMode == GuiMode::SOURCE_SELECTION) { } else if (guiMode == GuiMode::SOURCE_SELECTION) {
} }
} }
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs &args) void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) {
{
stopDrag(); stopDrag();
projectionEditor.stopDragJoints(); projectionEditor.stopDragJoints();
textureEditor.stopDragJoints(); textureEditor.stopDragJoints();
} }
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs &args) void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) {
{
if (bDrag) { if (bDrag) {
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
ofVec2f distance = mousePosition - clickPosition; ofVec2f distance = mousePosition - clickPosition;
@ -171,17 +168,14 @@ void SurfaceManagerGui::mouseDragged(ofMouseEventArgs &args)
} }
} }
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) {
{
surfaceManager = newSurfaceManager; surfaceManager = newSurfaceManager;
projectionEditor.setSurfaceManager(surfaceManager); projectionEditor.setSurfaceManager(surfaceManager);
sourcesEditor.setSurfaceManager(surfaceManager); sourcesEditor.setSurfaceManager(surfaceManager);
} }
void SurfaceManagerGui::setMode(int newGuiMode) void SurfaceManagerGui::setMode(int newGuiMode) {
{ if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING &&
if (newGuiMode != GuiMode::NONE &&
newGuiMode != GuiMode::TEXTURE_MAPPING &&
newGuiMode != GuiMode::PROJECTION_MAPPING && newGuiMode != GuiMode::PROJECTION_MAPPING &&
newGuiMode != GuiMode::SOURCE_SELECTION) { newGuiMode != GuiMode::SOURCE_SELECTION) {
throw std::runtime_error("Trying to set invalid mode."); throw std::runtime_error("Trying to set invalid mode.");
@ -218,8 +212,7 @@ void SurfaceManagerGui::setMode(int newGuiMode)
} }
} }
void SurfaceManagerGui::drawSelectedSurfaceHighlight() void SurfaceManagerGui::drawSelectedSurfaceHighlight() {
{
if (surfaceManager->getSelectedSurface() == NULL) return; if (surfaceManager->getSelectedSurface() == NULL) return;
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea();
@ -231,8 +224,7 @@ void SurfaceManagerGui::drawSelectedSurfaceHighlight()
ofPopStyle(); ofPopStyle();
} }
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() {
{
if (surfaceManager->getSelectedSurface() == NULL) return; if (surfaceManager->getSelectedSurface() == NULL) return;
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea();
@ -242,17 +234,10 @@ void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight()
ofSetColor(255, 255, 0, 255); ofSetColor(255, 255, 0, 255);
line.draw(); line.draw();
ofPopStyle(); ofPopStyle();
} }
void SurfaceManagerGui::startDrag() void SurfaceManagerGui::startDrag() { bDrag = true; }
{
bDrag = true;
}
void SurfaceManagerGui::stopDrag() void SurfaceManagerGui::stopDrag() { bDrag = false; }
{ }
bDrag = false;
} }
}}

8
src/SurfaceManagerGui.h

@ -14,8 +14,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class SurfaceManagerGui class SurfaceManagerGui {
{
public: public:
SurfaceManagerGui(); SurfaceManagerGui();
~SurfaceManagerGui(); ~SurfaceManagerGui();
@ -42,7 +41,6 @@ private:
int guiMode; int guiMode;
bool bDrag; bool bDrag;
ofVec2f clickPosition; ofVec2f clickPosition;
}; };
}
}} }

12
src/SurfaceType.h

@ -2,12 +2,8 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
struct SurfaceType struct SurfaceType {
{ enum { TRIANGLE_SURFACE, QUAD_SURFACE };
enum {
TRIANGLE_SURFACE,
QUAD_SURFACE
}; };
}; }
}
}}

110
src/TextureEditor.cpp

@ -2,59 +2,51 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TextureEditor::TextureEditor() TextureEditor::TextureEditor() {
{
clear(); clear();
enable(); enable();
} }
TextureEditor::~TextureEditor() TextureEditor::~TextureEditor() {
{
clear(); clear();
disable(); disable();
} }
void TextureEditor::registerAppEvents() void TextureEditor::registerAppEvents() {
{
ofAddListener(ofEvents().update, this, &TextureEditor::update); ofAddListener(ofEvents().update, this, &TextureEditor::update);
} }
void TextureEditor::unregisterAppEvents() void TextureEditor::unregisterAppEvents() {
{
ofRemoveListener(ofEvents().update, this, &TextureEditor::update); ofRemoveListener(ofEvents().update, this, &TextureEditor::update);
} }
void TextureEditor::registerKeyEvents() void TextureEditor::registerKeyEvents() {
{
ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed);
ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased);
} }
void TextureEditor::unregisterKeyEvents() void TextureEditor::unregisterKeyEvents() {
{
ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed);
ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased);
} }
void TextureEditor::enable() void TextureEditor::enable() {
{
registerAppEvents(); registerAppEvents();
registerKeyEvents(); registerKeyEvents();
bShiftKeyDown = false; bShiftKeyDown = false;
} }
void TextureEditor::disable() void TextureEditor::disable() {
{
unregisterAppEvents(); unregisterAppEvents();
unregisterKeyEvents(); unregisterKeyEvents();
} }
void TextureEditor::update(ofEventArgs &args) void TextureEditor::update(ofEventArgs& args) {
{
if (surface == NULL) return; if (surface == NULL) return;
// update surface if one of the joints is being dragged // update surface if one of the joints is being dragged
ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() ); ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(),
surface->getTexture()->getHeight());
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
if (joints[i]->isDragged() || joints[i]->isSelected()) { if (joints[i]->isDragged() || joints[i]->isSelected()) {
// update vertex to new location // update vertex to new location
@ -64,64 +56,71 @@ void TextureEditor::update(ofEventArgs &args)
} }
} }
void TextureEditor::keyPressed(ofKeyEventArgs &args) void TextureEditor::keyPressed(ofKeyEventArgs& args) {
{
int key = args.key; int key = args.key;
float moveStep; float moveStep;
if (bShiftKeyDown) moveStep = 10.0f; if (bShiftKeyDown)
else moveStep = 0.5f; moveStep = 10.0f;
else
moveStep = 0.5f;
switch (key) { switch (key) {
case OF_KEY_LEFT: moveSelection(ofVec2f(-moveStep,0.0f)); break; case OF_KEY_LEFT:
case OF_KEY_RIGHT: moveSelection(ofVec2f(moveStep,0.0f)); break; moveSelection(ofVec2f(-moveStep, 0.0f));
case OF_KEY_UP: moveSelection(ofVec2f(0.0f,-moveStep)); break; break;
case OF_KEY_DOWN: moveSelection(ofVec2f(0.0f,moveStep)); break; case OF_KEY_RIGHT:
case OF_KEY_SHIFT: bShiftKeyDown = true; break; moveSelection(ofVec2f(moveStep, 0.0f));
break;
case OF_KEY_UP:
moveSelection(ofVec2f(0.0f, -moveStep));
break;
case OF_KEY_DOWN:
moveSelection(ofVec2f(0.0f, moveStep));
break;
case OF_KEY_SHIFT:
bShiftKeyDown = true;
break;
} }
} }
void TextureEditor::keyReleased(ofKeyEventArgs &args) void TextureEditor::keyReleased(ofKeyEventArgs& args) {
{
int key = args.key; int key = args.key;
switch (key) { switch (key) {
case OF_KEY_SHIFT: bShiftKeyDown = false; break; case OF_KEY_SHIFT:
bShiftKeyDown = false;
break;
} }
} }
void TextureEditor::draw() {
void TextureEditor::draw()
{
if (surface == NULL) return; if (surface == NULL) return;
drawJoints(); drawJoints();
} }
void TextureEditor::drawJoints() void TextureEditor::drawJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->draw(); joints[i]->draw();
} }
} }
void TextureEditor::setSurface(BaseSurface* newSurface) void TextureEditor::setSurface(BaseSurface* newSurface) {
{
surface = newSurface; surface = newSurface;
createJoints(); createJoints();
} }
void TextureEditor::clear() void TextureEditor::clear() {
{
surface = NULL; surface = NULL;
clearJoints(); clearJoints();
} }
void TextureEditor::createJoints() void TextureEditor::createJoints() {
{
if (surface == NULL) return; if (surface == NULL) return;
clearJoints(); clearJoints();
vector<ofVec2f>& texCoords = surface->getTexCoords(); vector<ofVec2f>& texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), surface->getTexture()->getHeight()); ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(),
surface->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for (int i = 0; i < texCoords.size(); i++) {
joints.push_back(new CircleJoint()); joints.push_back(new CircleJoint());
@ -129,41 +128,37 @@ void TextureEditor::createJoints()
} }
} }
void TextureEditor::clearJoints() void TextureEditor::clearJoints() {
{
while (joints.size()) { while (joints.size()) {
delete joints.back(); delete joints.back();
joints.pop_back(); joints.pop_back();
} }
} }
void TextureEditor::unselectAllJoints() void TextureEditor::unselectAllJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->unselect(); joints[i]->unselect();
} }
} }
void TextureEditor::moveTexCoords(ofVec2f by) void TextureEditor::moveTexCoords(ofVec2f by) {
{
if (surface == NULL) return; if (surface == NULL) return;
vector<ofVec2f>& texCoords = surface->getTexCoords(); vector<ofVec2f>& texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() ); ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(),
surface->getTexture()->getHeight());
for (int i = 0; i < texCoords.size(); i++) { for (int i = 0; i < texCoords.size(); i++) {
joints[i]->position += by; joints[i]->position += by;
texCoords[i] = joints[i]->position / textureSize; texCoords[i] = joints[i]->position / textureSize;
} }
} }
void TextureEditor::stopDragJoints() void TextureEditor::stopDragJoints() {
{
for (int i = 0; i < joints.size(); i++) { for (int i = 0; i < joints.size(); i++) {
joints[i]->stopDrag(); joints[i]->stopDrag();
} }
} }
void TextureEditor::moveSelection(ofVec2f by) void TextureEditor::moveSelection(ofVec2f by) {
{
// check if joints selected // check if joints selected
bool bJointSelected = false; bool bJointSelected = false;
BaseJoint* selectedJoint; BaseJoint* selectedJoint;
@ -182,8 +177,7 @@ void TextureEditor::moveSelection(ofVec2f by)
} }
} }
CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos) CircleJoint* TextureEditor::hitTestJoints(ofVec2f 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];
@ -191,5 +185,5 @@ CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos)
} }
return NULL; return NULL;
} }
}
}} }

8
src/TextureEditor.h

@ -5,11 +5,9 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "CircleJoint.h" #include "CircleJoint.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TextureEditor class TextureEditor {
{
public: public:
TextureEditor(); TextureEditor();
~TextureEditor(); ~TextureEditor();
@ -41,5 +39,5 @@ private:
vector<CircleJoint*> joints; vector<CircleJoint*> joints;
bool bShiftKeyDown; bool bShiftKeyDown;
}; };
}
}} }

59
src/TriangleSurface.cpp

@ -2,19 +2,16 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
TriangleSurface::TriangleSurface() TriangleSurface::TriangleSurface() {
{
cout << "TriangleSurface constructor." << endl; cout << "TriangleSurface constructor." << endl;
setup(); setup();
} }
TriangleSurface::~TriangleSurface() TriangleSurface::~TriangleSurface() {
{
cout << "TriangleSurface destructor." << endl; cout << "TriangleSurface destructor." << endl;
} }
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); ofVec2f p1 = ofVec2f(ofGetWidth() / 2.0f, 0);
ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight()));
@ -28,8 +25,8 @@ void TriangleSurface::setup()
setup(p1, p2, p3, t1, t2, t3, texture); setup(p1, p2, p3, t1, t2, t3, texture);
} }
void TriangleSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr ) void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1,
{ ofVec2f t2, ofVec2f t3, ofTexture* texturePtr) {
// Assign texture // Assign texture
texture = texturePtr; texture = texturePtr;
@ -47,15 +44,13 @@ void TriangleSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofV
mesh.addTexCoord(t3); mesh.addTexCoord(t3);
} }
void TriangleSurface::draw() void TriangleSurface::draw() {
{
texture->bind(); texture->bind();
mesh.draw(); mesh.draw();
texture->unbind(); texture->unbind();
} }
void TriangleSurface::setVertex(int index, ofVec2f p) void TriangleSurface::setVertex(int index, ofVec2f 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;
@ -64,31 +59,26 @@ void TriangleSurface::setVertex(int index, ofVec2f p)
mesh.setVertex(index, p); mesh.setVertex(index, p);
} }
void TriangleSurface::setTexCoord(int index, ofVec2f t) void TriangleSurface::setTexCoord(int index, ofVec2f t) {
{
if (index > 2) { if (index > 2) {
ofLog() << "Texture coordinate with this index does not exist: " << index << endl; ofLog() << "Texture coordinate with this index does not exist: " << index
<< endl;
return; return;
} }
mesh.setTexCoord(index, t); mesh.setTexCoord(index, t);
} }
void TriangleSurface::moveBy(ofVec2f v) void TriangleSurface::moveBy(ofVec2f 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;
} }
} }
int TriangleSurface::getType() int TriangleSurface::getType() { return SurfaceType::TRIANGLE_SURFACE; }
{
return SurfaceType::TRIANGLE_SURFACE;
}
bool TriangleSurface::hitTest(ofVec2f p) bool TriangleSurface::hitTest(ofVec2f p) {
{
// Construct ofPolyline from vertices // Construct ofPolyline from vertices
ofPolyline line = getHitArea(); ofPolyline line = getHitArea();
@ -99,8 +89,7 @@ bool TriangleSurface::hitTest(ofVec2f p)
} }
} }
ofVec2f TriangleSurface::getVertex(int index) ofVec2f 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 std::runtime_error("Vertex index out of bounds."); throw std::runtime_error("Vertex index out of bounds.");
@ -110,8 +99,7 @@ ofVec2f TriangleSurface::getVertex(int index)
return ofVec2f(vert.x, vert.y); return ofVec2f(vert.x, vert.y);
} }
ofVec2f TriangleSurface::getTexCoord(int index) ofVec2f TriangleSurface::getTexCoord(int index) {
{
if (index > 2) { if (index > 2) {
throw std::runtime_error("Texture coordinate index out of bounds."); throw std::runtime_error("Texture coordinate index out of bounds.");
} }
@ -119,8 +107,7 @@ ofVec2f TriangleSurface::getTexCoord(int index)
return mesh.getTexCoord(index); return mesh.getTexCoord(index);
} }
ofPolyline TriangleSurface::getHitArea() ofPolyline TriangleSurface::getHitArea() {
{
ofPolyline line; ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); 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(1).x, mesh.getVertex(1).y));
@ -130,8 +117,7 @@ ofPolyline TriangleSurface::getHitArea()
return line; return line;
} }
ofPolyline TriangleSurface::getTextureHitArea() ofPolyline TriangleSurface::getTextureHitArea() {
{
ofPolyline line; ofPolyline line;
vector<ofVec2f>& texCoords = mesh.getTexCoords(); vector<ofVec2f>& texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight());
@ -143,16 +129,11 @@ ofPolyline TriangleSurface::getTextureHitArea()
return line; return line;
} }
vector<ofVec3f>& TriangleSurface::getVertices() vector<ofVec3f>& TriangleSurface::getVertices() {
{
// return only joint vertices // return only joint vertices
return mesh.getVertices(); return mesh.getVertices();
} }
vector<ofVec2f>& TriangleSurface::getTexCoords() vector<ofVec2f>& TriangleSurface::getTexCoords() { return mesh.getTexCoords(); }
{ }
return mesh.getTexCoords();
} }
}}

11
src/TriangleSurface.h

@ -4,17 +4,16 @@
#include "BaseSurface.h" #include "BaseSurface.h"
#include "SurfaceType.h" #include "SurfaceType.h"
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class TriangleSurface : public BaseSurface class TriangleSurface : public BaseSurface {
{
public: public:
TriangleSurface(); TriangleSurface();
~TriangleSurface(); ~TriangleSurface();
void setup(); void setup();
void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr ); void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2,
ofVec2f t3, ofTexture* texturePtr);
void draw(); void draw();
void setVertex(int index, ofVec2f p); void setVertex(int index, ofVec2f p);
void setTexCoord(int index, ofVec2f t); void setTexCoord(int index, ofVec2f t);
@ -29,5 +28,5 @@ public:
vector<ofVec3f>& getVertices(); vector<ofVec3f>& getVertices();
vector<ofVec2f>& getTexCoords(); vector<ofVec2f>& getTexCoords();
}; };
}
}} }

97
src/ui/RadioList.cpp

@ -2,31 +2,24 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
RadioList::RadioList() RadioList::RadioList() {
{
storedTitle = ""; storedTitle = "";
storedSelectedItem = 0; storedSelectedItem = 0;
} }
RadioList::RadioList(vector<string> &labels) RadioList::RadioList(vector<string>& labels) {
{
RadioList(); RadioList();
setup(labels); setup(labels);
} }
RadioList::RadioList(string title, vector<string> &labels) RadioList::RadioList(string title, vector<string>& labels) {
{
RadioList(); RadioList();
setup(title, labels); setup(title, labels);
} }
RadioList::~RadioList() RadioList::~RadioList() { clear(); }
{
clear();
}
void RadioList::setup(vector<string> &labels) void RadioList::setup(vector<string>& labels) {
{
// Copy incomming labels for later use // Copy incomming labels for later use
storedLabels = labels; storedLabels = labels;
@ -43,37 +36,25 @@ void RadioList::setup(vector<string> &labels)
cout << "num items: " << guiGroup.getNumControls() << endl; cout << "num items: " << guiGroup.getNumControls() << endl;
} }
void RadioList::setup(string title, vector<string> &labels) void RadioList::setup(string title, vector<string>& labels) {
{
// Store title for later use // Store title for later use
storedTitle = title; storedTitle = title;
guiGroup.setName(title); guiGroup.setName(title);
setup(labels); setup(labels);
} }
void RadioList::draw() void RadioList::draw() { guiGroup.draw(); }
{
guiGroup.draw();
}
void RadioList::setTitle(string title) void RadioList::setTitle(string title) {
{
storedTitle = title; storedTitle = title;
guiGroup.setName(title); guiGroup.setName(title);
} }
void RadioList::setPosition(ofPoint p) void RadioList::setPosition(ofPoint p) { guiGroup.setPosition(p); }
{
guiGroup.setPosition(p);
}
void RadioList::setPosition(float x, float y) void RadioList::setPosition(float x, float y) { guiGroup.setPosition(x, y); }
{
guiGroup.setPosition(x, y);
}
void RadioList::selectItem(int index) void RadioList::selectItem(int index) {
{
if (index >= guiGroup.getNumControls()) { if (index >= guiGroup.getNumControls()) {
return; return;
} }
@ -90,8 +71,7 @@ void RadioList::selectItem(int index)
storedSelectedItem = index; storedSelectedItem = index;
} }
void RadioList::enable() void RadioList::enable() {
{
if (guiGroup.getNumControls() >= 0) { if (guiGroup.getNumControls() >= 0) {
clear(); clear();
} }
@ -100,7 +80,8 @@ void RadioList::enable()
setup(storedTitle, storedLabels); setup(storedTitle, storedLabels);
// Select the stored selected item without throwing an event // Select the stored selected item without throwing an event
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(storedSelectedItem)); ofxToggle* toggle =
static_cast<ofxToggle*>(guiGroup.getControl(storedSelectedItem));
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = true; *toggle = true;
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
@ -108,14 +89,12 @@ void RadioList::enable()
cout << "num items after enable: " << guiGroup.getNumControls() << endl; cout << "num items after enable: " << guiGroup.getNumControls() << endl;
} }
void RadioList::disable() void RadioList::disable() {
{
// Just remove everything // Just remove everything
clear(); clear();
} }
void RadioList::clear() void RadioList::clear() {
{
int i; int i;
for (i = 0; i < guiGroup.getNumControls(); i++) { for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
@ -125,40 +104,27 @@ void RadioList::clear()
guiGroup.clear(); guiGroup.clear();
} }
void RadioList::unselectAll() void RadioList::unselectAll() {
{
int i; int i;
for (i = 0; i < guiGroup.getNumControls(); i++) { for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
ofParameter<bool>* paramPtr = static_cast<ofParameter<bool>*>(&toggle->getParameter()); ofParameter<bool>* paramPtr =
static_cast<ofParameter<bool>*>(&toggle->getParameter());
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = false; *toggle = false;
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
} }
} }
ofPoint RadioList::getPosition() ofPoint RadioList::getPosition() { return guiGroup.getPosition(); }
{
return guiGroup.getPosition();
}
float RadioList::getWidth() float RadioList::getWidth() { return guiGroup.getWidth(); }
{
return guiGroup.getWidth();
}
float RadioList::getHeight() float RadioList::getHeight() { return guiGroup.getHeight(); }
{
return guiGroup.getHeight();
}
string RadioList::getTitle() string RadioList::getTitle() { return guiGroup.getName(); }
{
return guiGroup.getName();
}
string RadioList::getItemName(int index) string RadioList::getItemName(int index) {
{
if (index >= guiGroup.getNumControls()) { if (index >= guiGroup.getNumControls()) {
return ""; return "";
} }
@ -167,20 +133,17 @@ string RadioList::getItemName(int index)
return toggle->getName(); return toggle->getName();
} }
int RadioList::size() int RadioList::size() { return guiGroup.getNumControls(); }
{
return guiGroup.getNumControls();
}
void RadioList::onToggleClicked(bool &toggleValue) void RadioList::onToggleClicked(bool& toggleValue) {
{
unselectAll(); unselectAll();
// Search for the actual toggle triggering the event // Search for the actual toggle triggering the event
int i; int i;
for (i = 0; i < guiGroup.getNumControls(); i++) { for (i = 0; i < guiGroup.getNumControls(); i++) {
ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i)); ofxToggle* toggle = static_cast<ofxToggle*>(guiGroup.getControl(i));
ofParameter<bool>* paramPtr = static_cast<ofParameter<bool>*>(&toggle->getParameter()); ofParameter<bool>* paramPtr =
static_cast<ofParameter<bool>*>(&toggle->getParameter());
if (&(paramPtr->get()) == &toggleValue) { if (&(paramPtr->get()) == &toggleValue) {
selectItem(i); selectItem(i);
@ -188,5 +151,5 @@ void RadioList::onToggleClicked(bool &toggleValue)
} }
} }
} }
}
}} }

13
src/ui/RadioList.h

@ -7,8 +7,7 @@
namespace ofx { namespace ofx {
namespace piMapper { namespace piMapper {
class RadioList class RadioList {
{
public: public:
RadioList(); RadioList();
RadioList(vector<string> &labels); RadioList(vector<string> &labels);
@ -33,8 +32,10 @@ public:
string getItemName(int index); string getItemName(int index);
int size(); int size();
// This event notifies about a toggle being selected and passes it's name to the listeners. // This event notifies about a toggle being selected and passes it's name to
// Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr, &listenerClass::listenerMethod) // the listeners.
// Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr,
// &listenerClass::listenerMethod)
// to listen to this. Listner method void listenerMethod(string & radioName) // to listen to this. Listner method void listenerMethod(string & radioName)
ofEvent<string> radioSelectedEvent; ofEvent<string> radioSelectedEvent;
@ -46,5 +47,5 @@ private:
void onToggleClicked(bool &toggleValue); void onToggleClicked(bool &toggleValue);
}; };
}
}} }
Loading…
Cancel
Save