27 changed files with 2194 additions and 2395 deletions
@ -1,164 +1,183 @@ |
|||
#include "ofApp.h" |
|||
|
|||
void ofApp::setup() |
|||
{ |
|||
bShowInfo = false; |
|||
|
|||
// check if the surfaces.xml file is there
|
|||
// if not - load defaultSurfaces.xml
|
|||
if ( ofFile::doesFileExist("surfaces.xml") ) { |
|||
surfaceManager.loadXmlSettings("surfaces.xml"); |
|||
} else { |
|||
surfaceManager.loadXmlSettings("defaultSurfaces.xml"); |
|||
} |
|||
|
|||
// Pass the surface manager to the mapper graphical user interface
|
|||
gui.setSurfaceManager( &surfaceManager ); |
|||
|
|||
// Create FBO
|
|||
fbo = new ofFbo(); |
|||
fbo->allocate( 500, 500 ); |
|||
setFboAsTexture(); |
|||
|
|||
// Genereate rects
|
|||
int numRects = 20; // change this to add more or less rects
|
|||
for ( int i=0; i<numRects; i++ ) { |
|||
rects.push_back( ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), ofRandom(20)) ); |
|||
rectSpeeds.push_back( (1.0f + ofRandom(5)) ); |
|||
} |
|||
void ofApp::setup() { |
|||
bShowInfo = false; |
|||
|
|||
// check if the surfaces.xml file is there
|
|||
// if not - load defaultSurfaces.xml
|
|||
if (ofFile::doesFileExist("surfaces.xml")) { |
|||
surfaceManager.loadXmlSettings("surfaces.xml"); |
|||
} else { |
|||
surfaceManager.loadXmlSettings("defaultSurfaces.xml"); |
|||
} |
|||
|
|||
// Pass the surface manager to the mapper graphical user interface
|
|||
gui.setSurfaceManager(&surfaceManager); |
|||
|
|||
// Create FBO
|
|||
fbo = new ofFbo(); |
|||
fbo->allocate(500, 500); |
|||
setFboAsTexture(); |
|||
|
|||
// Genereate rects
|
|||
int numRects = 20; // change this to add more or less rects
|
|||
for (int i = 0; i < numRects; i++) { |
|||
rects.push_back(ofRectangle(0, ofRandom(fbo->getHeight()), fbo->getWidth(), |
|||
ofRandom(20))); |
|||
rectSpeeds.push_back((1.0f + ofRandom(5))); |
|||
} |
|||
} |
|||
|
|||
void ofApp::update() |
|||
{ |
|||
// Move rects
|
|||
for ( int i=0; i<rects.size(); i++ ) { |
|||
rects[i].y += rectSpeeds[i]; |
|||
if ( rects[i].y > fbo->getHeight() ) { |
|||
rects[i].y = -rects[i].getHeight(); |
|||
} |
|||
} |
|||
|
|||
// Fill FBO
|
|||
fbo->begin(); |
|||
ofClear(0); |
|||
ofBackground(0); |
|||
ofSetColor(255); |
|||
for ( int i=0; i<rects.size(); i++ ) { |
|||
ofRect( rects[i] ); |
|||
void ofApp::update() { |
|||
// Move rects
|
|||
for (int i = 0; i < rects.size(); i++) { |
|||
rects[i].y += rectSpeeds[i]; |
|||
if (rects[i].y > fbo->getHeight()) { |
|||
rects[i].y = -rects[i].getHeight(); |
|||
} |
|||
fbo->end(); |
|||
} |
|||
|
|||
// Fill FBO
|
|||
fbo->begin(); |
|||
ofClear(0); |
|||
ofBackground(0); |
|||
ofSetColor(255); |
|||
for (int i = 0; i < rects.size(); i++) { |
|||
ofRect(rects[i]); |
|||
} |
|||
fbo->end(); |
|||
} |
|||
|
|||
void ofApp::draw() |
|||
{ |
|||
// Draw the piMapper GUI
|
|||
gui.draw(); |
|||
|
|||
if ( bShowInfo ) { |
|||
// Draw instructions
|
|||
stringstream ss; |
|||
ss << "There are 4 modes:\n\n"; |
|||
ss << " 1. Presentation mode\n"; |
|||
ss << " 2. Texture mapping mode\n"; |
|||
ss << " 3. Projection mapping mode\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 << "Press <r> or <n> to add random or normal surface.\n"; |
|||
ss << "Press <q> to add a new quad surface.\n"; |
|||
ss << "Press <s> to save the composition.\n"; |
|||
ss << "Press <f> to toggle fullscreen.\n"; |
|||
ss << "Press <a> to reassign the fbo texture to the first surface\n"; |
|||
ss << "Hit <i> to hide this message."; |
|||
|
|||
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0,0,0,100), ofColor(255,255,255,200)); |
|||
} |
|||
void ofApp::draw() { |
|||
// Draw the piMapper GUI
|
|||
gui.draw(); |
|||
|
|||
if (bShowInfo) { |
|||
// Draw instructions
|
|||
stringstream ss; |
|||
ss << "There are 4 modes:\n\n"; |
|||
ss << " 1. Presentation mode\n"; |
|||
ss << " 2. Texture mapping mode\n"; |
|||
ss << " 3. Projection mapping mode\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 << "Press <r> or <n> to add random or normal surface.\n"; |
|||
ss << "Press <q> to add a new quad surface.\n"; |
|||
ss << "Press <s> to save the composition.\n"; |
|||
ss << "Press <f> to toggle fullscreen.\n"; |
|||
ss << "Press <a> to reassign the fbo texture to the first surface\n"; |
|||
ss << "Hit <i> to hide this message."; |
|||
|
|||
ofDrawBitmapStringHighlight(ss.str(), 10, 20, ofColor(0, 0, 0, 100), |
|||
ofColor(255, 255, 255, 200)); |
|||
} |
|||
} |
|||
|
|||
void ofApp::exit() |
|||
{ |
|||
// Clear FBO from mem
|
|||
delete fbo; |
|||
void ofApp::exit() { |
|||
// Clear FBO from mem
|
|||
delete fbo; |
|||
} |
|||
|
|||
void ofApp::keyPressed(int key) |
|||
{ |
|||
cout << "Key pressed: " << static_cast<char>(key) << endl; |
|||
|
|||
switch (key) { |
|||
case '1': gui.setMode(ofx::piMapper::GuiMode::NONE); break; |
|||
case '2': gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); break; |
|||
case '3': gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); break; |
|||
case '4': gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); break; |
|||
case 'i': bShowInfo = !bShowInfo; break; |
|||
case 'r': 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::keyPressed(int key) { |
|||
cout << "Key pressed: " << static_cast<char>(key) << endl; |
|||
|
|||
switch (key) { |
|||
case '1': |
|||
gui.setMode(ofx::piMapper::GuiMode::NONE); |
|||
break; |
|||
case '2': |
|||
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING); |
|||
break; |
|||
case '3': |
|||
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING); |
|||
break; |
|||
case '4': |
|||
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION); |
|||
break; |
|||
case 'i': |
|||
bShowInfo = !bShowInfo; |
|||
break; |
|||
case 'r': |
|||
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; |
|||
vector<ofVec2f> vertices; |
|||
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); |
|||
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); |
|||
vertices.push_back( ofVec2f( ofRandomWidth(), ofRandomHeight() ) ); |
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); |
|||
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); |
|||
texCoords.push_back( ofVec2f( ofRandomuf(), ofRandomuf() ) ); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size()-1); |
|||
void ofApp::addRandomSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
vector<ofVec2f> vertices; |
|||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|||
vertices.push_back(ofVec2f(ofRandomWidth(), ofRandomHeight())); |
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf())); |
|||
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf())); |
|||
texCoords.push_back(ofVec2f(ofRandomuf(), ofRandomuf())); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
} |
|||
|
|||
void ofApp::addQuadSurface() |
|||
{ |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
vector<ofVec2f> vertices; |
|||
|
|||
int border = 50; |
|||
vertices.push_back(ofVec2f(border, border)); |
|||
vertices.push_back(ofVec2f(ofGetWidth() - border, border)); |
|||
vertices.push_back(ofVec2f(ofGetWidth() - border, ofGetHeight() - border)); |
|||
vertices.push_back(ofVec2f(border, ofGetHeight() - border)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size()-1); |
|||
void ofApp::addQuadSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
vector<ofVec2f> vertices; |
|||
|
|||
int border = 50; |
|||
vertices.push_back(ofVec2f(border, border)); |
|||
vertices.push_back(ofVec2f(ofGetWidth() - border, border)); |
|||
vertices.push_back(ofVec2f(ofGetWidth() - border, ofGetHeight() - border)); |
|||
vertices.push_back(ofVec2f(border, ofGetHeight() - border)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
} |
|||
|
|||
void ofApp::addSurface() |
|||
{ |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
vector<ofVec2f> vertices; |
|||
vertices.push_back( ofVec2f( (float)ofGetWidth()/2.0f, 0.0f ) ); |
|||
vertices.push_back( ofVec2f( (float)ofGetWidth(), (float)ofGetHeight() ) ); |
|||
vertices.push_back( ofVec2f( 0.0f, (float)ofGetHeight() ) ); |
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back( ofVec2f( 0.5f, 0.0f ) ); |
|||
texCoords.push_back( ofVec2f( 1.0f, 1.0f ) ); |
|||
texCoords.push_back( ofVec2f( 0.0f, 1.0f ) ); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size()-1); |
|||
void ofApp::addSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
vector<ofVec2f> vertices; |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, 0.0f)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth(), (float)ofGetHeight())); |
|||
vertices.push_back(ofVec2f(0.0f, (float)ofGetHeight())); |
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(0.5f, 0.0f)); |
|||
texCoords.push_back(ofVec2f(1.0f, 1.0f)); |
|||
texCoords.push_back(ofVec2f(0.0f, 1.0f)); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
} |
|||
|
|||
void ofApp::setFboAsTexture() |
|||
{ |
|||
surfaceManager.getSurface(0)->setTexture( &fbo->getTextureReference() ); |
|||
void ofApp::setFboAsTexture() { |
|||
surfaceManager.getSurface(0)->setTexture(&fbo->getTextureReference()); |
|||
} |
@ -1,104 +1,72 @@ |
|||
#include "BaseJoint.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
BaseJoint::BaseJoint() |
|||
{ |
|||
setDefaultColors(); |
|||
setDefaultProperties(); |
|||
registerMouseEvents(); |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
BaseJoint::~BaseJoint() |
|||
{ |
|||
unregisterMouseEvents(); |
|||
BaseJoint::BaseJoint() { |
|||
setDefaultColors(); |
|||
setDefaultProperties(); |
|||
registerMouseEvents(); |
|||
} |
|||
|
|||
void BaseJoint::registerMouseEvents() |
|||
{ |
|||
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); |
|||
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); |
|||
} |
|||
BaseJoint::~BaseJoint() { unregisterMouseEvents(); } |
|||
|
|||
void BaseJoint::unregisterMouseEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); |
|||
void BaseJoint::registerMouseEvents() { |
|||
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); |
|||
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); |
|||
} |
|||
|
|||
void BaseJoint::mousePressed(ofMouseEventArgs& args) |
|||
{ |
|||
if ( hitTest(ofVec2f(args.x, args.y)) ) { |
|||
//selected = true;
|
|||
clickDistance = position - ofVec2f(args.x, args.y); |
|||
//startDrag();
|
|||
} |
|||
void BaseJoint::unregisterMouseEvents() { |
|||
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); |
|||
} |
|||
|
|||
void BaseJoint::mouseReleased(int x, int y, int button) |
|||
{ |
|||
stopDrag(); |
|||
void BaseJoint::mousePressed(ofMouseEventArgs& args) { |
|||
if (hitTest(ofVec2f(args.x, args.y))) { |
|||
// selected = true;
|
|||
clickDistance = position - ofVec2f(args.x, args.y); |
|||
// startDrag();
|
|||
} |
|||
} |
|||
|
|||
void BaseJoint::mouseDragged(ofMouseEventArgs& args) |
|||
{ |
|||
if ( !bDrag ) return; |
|||
position = ofVec2f(args.x, args.y) + clickDistance; |
|||
} |
|||
void BaseJoint::mouseReleased(int x, int y, int button) { stopDrag(); } |
|||
|
|||
void BaseJoint::startDrag() |
|||
{ |
|||
bDrag = true; |
|||
void BaseJoint::mouseDragged(ofMouseEventArgs& args) { |
|||
if (!bDrag) return; |
|||
position = ofVec2f(args.x, args.y) + clickDistance; |
|||
} |
|||
|
|||
void BaseJoint::stopDrag() |
|||
{ |
|||
bDrag = false; |
|||
} |
|||
void BaseJoint::startDrag() { bDrag = true; } |
|||
|
|||
void BaseJoint::select() |
|||
{ |
|||
selected = true; |
|||
} |
|||
void BaseJoint::stopDrag() { bDrag = false; } |
|||
|
|||
void BaseJoint::unselect() |
|||
{ |
|||
selected = false; |
|||
} |
|||
void BaseJoint::select() { selected = true; } |
|||
|
|||
void BaseJoint::setClickDistance(ofVec2f newClickDistance) |
|||
{ |
|||
clickDistance = newClickDistance; |
|||
} |
|||
void BaseJoint::unselect() { selected = false; } |
|||
|
|||
bool BaseJoint::isDragged() |
|||
{ |
|||
return bDrag; |
|||
void BaseJoint::setClickDistance(ofVec2f newClickDistance) { |
|||
clickDistance = newClickDistance; |
|||
} |
|||
|
|||
bool BaseJoint::isSelected() |
|||
{ |
|||
return selected; |
|||
} |
|||
bool BaseJoint::isDragged() { return bDrag; } |
|||
|
|||
void BaseJoint::setDefaultColors() |
|||
{ |
|||
fillColor = ofColor(0, 255, 255, 0); |
|||
strokeColor = ofColor(255, 255, 255); |
|||
fillColorSelected = ofColor(255, 255, 0, 0); |
|||
strokeColorSelected = ofColor(255, 0, 0); |
|||
bool BaseJoint::isSelected() { return selected; } |
|||
|
|||
void BaseJoint::setDefaultColors() { |
|||
fillColor = ofColor(0, 255, 255, 0); |
|||
strokeColor = ofColor(255, 255, 255); |
|||
fillColorSelected = ofColor(255, 255, 0, 0); |
|||
strokeColorSelected = ofColor(255, 0, 0); |
|||
} |
|||
|
|||
void BaseJoint::setDefaultProperties() |
|||
{ |
|||
enabled = true; |
|||
visible = true; |
|||
position = ofVec2f(20.0f, 20.0f); |
|||
clickDistance = ofVec2f(0.0f, 0.0f); |
|||
bDrag = false; |
|||
selected = false; |
|||
strokeWidth = 1.5f; |
|||
void BaseJoint::setDefaultProperties() { |
|||
enabled = true; |
|||
visible = true; |
|||
position = ofVec2f(20.0f, 20.0f); |
|||
clickDistance = ofVec2f(0.0f, 0.0f); |
|||
bDrag = false; |
|||
selected = false; |
|||
strokeWidth = 1.5f; |
|||
} |
|||
} |
|||
|
|||
}} |
|||
} |
@ -1,77 +1,70 @@ |
|||
#include "BaseSurface.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
BaseSurface::BaseSurface() |
|||
{ |
|||
ofEnableNormalizedTexCoords(); |
|||
createDefaultTexture(); |
|||
BaseSurface::BaseSurface() { |
|||
ofEnableNormalizedTexCoords(); |
|||
createDefaultTexture(); |
|||
} |
|||
|
|||
void BaseSurface::createDefaultTexture() |
|||
{ |
|||
ofPixels pixels; |
|||
pixels.allocate(500, 500, 1); |
|||
for ( int i=0; i<pixels.size(); i++ ) { |
|||
pixels[i] = 255; |
|||
} |
|||
int squareSize = 10; // size of each test pattern square
|
|||
bool sy = false; |
|||
for ( int y=0; y<pixels.getWidth(); y+=squareSize ) { |
|||
bool sx = false; |
|||
for ( int x=0; x<pixels.getHeight(); x+=squareSize ) { |
|||
for ( int yi=0; yi<squareSize; yi++ ) { |
|||
for ( int xi=0; xi<squareSize; xi++ ){ |
|||
if ( sx && sy ) pixels[(y+yi)*pixels.getWidth()+x+xi] = 255; |
|||
else if ( sx && !sy ) 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; |
|||
void BaseSurface::createDefaultTexture() { |
|||
ofPixels pixels; |
|||
pixels.allocate(500, 500, 1); |
|||
for (int i = 0; i < pixels.size(); i++) { |
|||
pixels[i] = 255; |
|||
} |
|||
int squareSize = 10; // size of each test pattern square
|
|||
bool sy = false; |
|||
for (int y = 0; y < pixels.getWidth(); y += squareSize) { |
|||
bool sx = false; |
|||
for (int x = 0; x < pixels.getHeight(); x += squareSize) { |
|||
for (int yi = 0; yi < squareSize; yi++) { |
|||
for (int xi = 0; xi < squareSize; xi++) { |
|||
if (sx && sy) |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
|||
else if (sx && !sy) |
|||
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; |
|||
} |
|||
sy = !sy; |
|||
} |
|||
sx = !sx; |
|||
} |
|||
|
|||
// load pixels into texture
|
|||
defaultTexture.loadData(pixels); |
|||
|
|||
// Assign default texture to texture pointer
|
|||
texture = &defaultTexture; |
|||
} |
|||
sy = !sy; |
|||
} |
|||
|
|||
void BaseSurface::drawTexture(ofVec2f position) |
|||
{ |
|||
ofMesh texMesh; |
|||
texMesh.addVertex(position); |
|||
texMesh.addVertex(position + ofVec2f(texture->getWidth(), 0.0f)); |
|||
texMesh.addVertex(position + ofVec2f(texture->getWidth(), texture->getHeight())); |
|||
texMesh.addVertex(position + ofVec2f(0.0f, texture->getHeight())); |
|||
texMesh.addTriangle(0, 2, 3); |
|||
texMesh.addTriangle(0, 1, 2); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); |
|||
texture->bind(); |
|||
texMesh.draw(); |
|||
texture->unbind(); |
|||
} |
|||
// load pixels into texture
|
|||
defaultTexture.loadData(pixels); |
|||
|
|||
void BaseSurface::setTexture(ofTexture *texturePtr) |
|||
{ |
|||
texture = texturePtr; |
|||
// Assign default texture to texture pointer
|
|||
texture = &defaultTexture; |
|||
} |
|||
|
|||
ofTexture* BaseSurface::getTexture() |
|||
{ |
|||
return texture; |
|||
void BaseSurface::drawTexture(ofVec2f position) { |
|||
ofMesh texMesh; |
|||
texMesh.addVertex(position); |
|||
texMesh.addVertex(position + ofVec2f(texture->getWidth(), 0.0f)); |
|||
texMesh.addVertex(position + |
|||
ofVec2f(texture->getWidth(), texture->getHeight())); |
|||
texMesh.addVertex(position + ofVec2f(0.0f, texture->getHeight())); |
|||
texMesh.addTriangle(0, 2, 3); |
|||
texMesh.addTriangle(0, 1, 2); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); |
|||
texture->bind(); |
|||
texMesh.draw(); |
|||
texture->unbind(); |
|||
} |
|||
|
|||
ofTexture* BaseSurface::getDefaultTexture() |
|||
{ |
|||
return &defaultTexture; |
|||
} |
|||
void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; } |
|||
|
|||
ofTexture* BaseSurface::getTexture() { return texture; } |
|||
|
|||
}} |
|||
ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; } |
|||
} |
|||
} |
@ -1,56 +1,49 @@ |
|||
#include "CircleJoint.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
CircleJoint::CircleJoint() |
|||
{ |
|||
setDefaultProperties(); |
|||
} |
|||
CircleJoint::CircleJoint() { setDefaultProperties(); } |
|||
|
|||
void CircleJoint::update() |
|||
{ |
|||
if (!enabled) return; |
|||
void CircleJoint::update() { |
|||
if (!enabled) return; |
|||
} |
|||
|
|||
void CircleJoint::draw() |
|||
{ |
|||
if (!visible) return; |
|||
if (!enabled) return; |
|||
|
|||
ofPushStyle(); |
|||
ofFill(); |
|||
|
|||
if ( selected ) { |
|||
ofSetColor(fillColorSelected); |
|||
} else { |
|||
ofSetColor(fillColor); |
|||
} |
|||
|
|||
ofCircle(position.x, position.y, radius); |
|||
ofNoFill(); |
|||
|
|||
if ( selected ) { |
|||
ofSetColor(strokeColorSelected); |
|||
} else { |
|||
ofSetColor(strokeColor); |
|||
} |
|||
|
|||
ofSetLineWidth(strokeWidth); |
|||
ofCircle(position.x, position.y, radius); |
|||
ofPopStyle(); |
|||
} |
|||
void CircleJoint::draw() { |
|||
if (!visible) return; |
|||
if (!enabled) return; |
|||
|
|||
void CircleJoint::setDefaultProperties() |
|||
{ |
|||
radius = 10.0f; |
|||
} |
|||
ofPushStyle(); |
|||
ofFill(); |
|||
|
|||
if (selected) { |
|||
ofSetColor(fillColorSelected); |
|||
} else { |
|||
ofSetColor(fillColor); |
|||
} |
|||
|
|||
ofCircle(position.x, position.y, radius); |
|||
ofNoFill(); |
|||
|
|||
bool CircleJoint::hitTest(ofVec2f pos) |
|||
{ |
|||
float distance = position.distance(pos); |
|||
if ( distance < radius ) return true; |
|||
else return false; |
|||
if (selected) { |
|||
ofSetColor(strokeColorSelected); |
|||
} else { |
|||
ofSetColor(strokeColor); |
|||
} |
|||
|
|||
ofSetLineWidth(strokeWidth); |
|||
ofCircle(position.x, position.y, radius); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
}} |
|||
void CircleJoint::setDefaultProperties() { radius = 10.0f; } |
|||
|
|||
bool CircleJoint::hitTest(ofVec2f pos) { |
|||
float distance = position.distance(pos); |
|||
if (distance < radius) |
|||
return true; |
|||
else |
|||
return false; |
|||
} |
|||
} |
|||
} |
@ -1,13 +1,9 @@ |
|||
#pragma once |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
struct EditorType |
|||
{ |
|||
enum { |
|||
TEXTURE, |
|||
PROJECTION |
|||
}; |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
struct EditorType { |
|||
enum { TEXTURE, PROJECTION }; |
|||
}; |
|||
|
|||
}} |
|||
} |
|||
} |
@ -1,14 +1,9 @@ |
|||
#pragma once |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
struct GuiMode |
|||
{ |
|||
enum { |
|||
NONE, |
|||
TEXTURE_MAPPING, |
|||
PROJECTION_MAPPING, |
|||
SOURCE_SELECTION |
|||
}; |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
struct GuiMode { |
|||
enum { NONE, TEXTURE_MAPPING, PROJECTION_MAPPING, SOURCE_SELECTION }; |
|||
}; |
|||
}} |
|||
} |
|||
} |
@ -1,270 +1,263 @@ |
|||
#include "ProjectionEditor.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
ProjectionEditor::ProjectionEditor() |
|||
{ |
|||
surfaceManager = NULL; |
|||
bShiftKeyDown = false; |
|||
fSnapDistance = 10.0f; |
|||
enable(); |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
ProjectionEditor::ProjectionEditor() { |
|||
surfaceManager = NULL; |
|||
bShiftKeyDown = false; |
|||
fSnapDistance = 10.0f; |
|||
enable(); |
|||
} |
|||
|
|||
ProjectionEditor::~ProjectionEditor() |
|||
{ |
|||
clearJoints(); |
|||
surfaceManager = NULL; |
|||
disable(); |
|||
ProjectionEditor::~ProjectionEditor() { |
|||
clearJoints(); |
|||
surfaceManager = NULL; |
|||
disable(); |
|||
} |
|||
|
|||
void ProjectionEditor::registerAppEvents() |
|||
{ |
|||
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|||
void ProjectionEditor::registerAppEvents() { |
|||
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterAppEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofRemoveListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|||
void ProjectionEditor::unregisterAppEvents() { |
|||
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofRemoveListener(ofEvents().messageEvent, this, |
|||
&ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::registerMouseEvents() |
|||
{ |
|||
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|||
void ProjectionEditor::registerMouseEvents() { |
|||
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterMouseEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|||
void ProjectionEditor::unregisterMouseEvents() { |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::registerKeyEvents() |
|||
{ |
|||
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|||
void ProjectionEditor::registerKeyEvents() { |
|||
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterKeyEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|||
void ProjectionEditor::unregisterKeyEvents() { |
|||
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, |
|||
&ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::enable() |
|||
{ |
|||
registerAppEvents(); |
|||
registerMouseEvents(); |
|||
registerKeyEvents(); |
|||
void ProjectionEditor::enable() { |
|||
registerAppEvents(); |
|||
registerMouseEvents(); |
|||
registerKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::disable() |
|||
{ |
|||
unregisterAppEvents(); |
|||
unregisterMouseEvents(); |
|||
unregisterKeyEvents(); |
|||
void ProjectionEditor::disable() { |
|||
unregisterAppEvents(); |
|||
unregisterMouseEvents(); |
|||
unregisterKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::update(ofEventArgs &args) |
|||
{ |
|||
// update surface if one of the joints is being dragged
|
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if ( joints[i]->isDragged() || joints[i]->isSelected() ) { |
|||
|
|||
if ( surfaceManager->getSelectedSurface() != NULL ) { |
|||
// update vertex to new location
|
|||
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); |
|||
} else { |
|||
// clear joints if there is no surface selected
|
|||
// as the remove selected surface in the surface manager
|
|||
// is not supposed to access joints here
|
|||
joints.clear(); |
|||
} |
|||
break; |
|||
} |
|||
void ProjectionEditor::update(ofEventArgs& args) { |
|||
// update surface if one of the joints is being dragged
|
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isDragged() || joints[i]->isSelected()) { |
|||
if (surfaceManager->getSelectedSurface() != NULL) { |
|||
// update vertex to new location
|
|||
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); |
|||
} else { |
|||
// clear joints if there is no surface selected
|
|||
// as the remove selected surface in the surface manager
|
|||
// is not supposed to access joints here
|
|||
joints.clear(); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::draw() |
|||
{ |
|||
if ( surfaceManager == NULL ) return; |
|||
if ( surfaceManager->getSelectedSurface() == NULL ) return; |
|||
if ( joints.size() <= 0 ) createJoints(); |
|||
drawJoints(); |
|||
void ProjectionEditor::draw() { |
|||
if (surfaceManager == NULL) return; |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
if (joints.size() <= 0) createJoints(); |
|||
drawJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::mouseDragged(ofMouseEventArgs &args) |
|||
{ |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
|
|||
// Collect all vertices of the projection surfaces
|
|||
vector<ofVec3f*> 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
|
|||
} |
|||
for ( int j=0; j<surface->getVertices().size(); j++ ) { |
|||
allVertices.push_back(&surface->getVertices()[j]); |
|||
} |
|||
void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
|
|||
// Collect all vertices of the projection surfaces
|
|||
vector<ofVec3f*> 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
|
|||
} |
|||
for (int j = 0; j < surface->getVertices().size(); j++) { |
|||
allVertices.push_back(&surface->getVertices()[j]); |
|||
} |
|||
|
|||
// Snap currently dragged joint to nearest vertex
|
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if ( joints[i]->isDragged() ) { |
|||
// Snap it!
|
|||
for ( int j=0; j<allVertices.size(); j++ ) { |
|||
float distance = mousePosition.distance(*allVertices[j]); |
|||
//cout << "distance: " << distance << endl;
|
|||
if ( distance < fSnapDistance ) { |
|||
joints[i]->position = *allVertices[j]; |
|||
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); |
|||
joints[i]->setClickDistance(clickDistance); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// Snap currently dragged joint to nearest vertex
|
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isDragged()) { |
|||
// Snap it!
|
|||
for (int j = 0; j < allVertices.size(); j++) { |
|||
float distance = mousePosition.distance(*allVertices[j]); |
|||
// cout << "distance: " << distance << endl;
|
|||
if (distance < fSnapDistance) { |
|||
joints[i]->position = *allVertices[j]; |
|||
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); |
|||
joints[i]->setClickDistance(clickDistance); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::keyPressed(ofKeyEventArgs &args) |
|||
{ |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if (bShiftKeyDown) moveStep = 10.0f; |
|||
else moveStep = 0.5f; |
|||
|
|||
switch (key) { |
|||
case OF_KEY_LEFT: moveSelection(ofVec2f(-moveStep,0.0f)); break; |
|||
case OF_KEY_RIGHT: 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::keyPressed(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if (bShiftKeyDown) |
|||
moveStep = 10.0f; |
|||
else |
|||
moveStep = 0.5f; |
|||
|
|||
switch (key) { |
|||
case OF_KEY_LEFT: |
|||
moveSelection(ofVec2f(-moveStep, 0.0f)); |
|||
break; |
|||
case OF_KEY_RIGHT: |
|||
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) |
|||
{ |
|||
int key = args.key; |
|||
switch (key) { |
|||
case OF_KEY_SHIFT: bShiftKeyDown = false; break; |
|||
} |
|||
void ProjectionEditor::keyReleased(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
switch (key) { |
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = false; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::gotMessage(ofMessage& msg) |
|||
{ |
|||
if (msg.message == "surfaceSelected") { |
|||
// refresh gui
|
|||
clearJoints(); |
|||
createJoints(); |
|||
} |
|||
void ProjectionEditor::gotMessage(ofMessage& msg) { |
|||
if (msg.message == "surfaceSelected") { |
|||
// refresh gui
|
|||
clearJoints(); |
|||
createJoints(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSurfaceManager(SurfaceManager *newSurfaceManager) |
|||
{ |
|||
surfaceManager = newSurfaceManager; |
|||
void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|||
surfaceManager = newSurfaceManager; |
|||
} |
|||
|
|||
void ProjectionEditor::clearJoints() |
|||
{ |
|||
while ( joints.size() ) { |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
void ProjectionEditor::clearJoints() { |
|||
while (joints.size()) { |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::createJoints() |
|||
{ |
|||
if ( surfaceManager == NULL ) return; |
|||
clearJoints(); |
|||
|
|||
if ( surfaceManager->getSelectedSurface() == NULL ) { |
|||
ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected."); |
|||
return; |
|||
} |
|||
|
|||
vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices(); |
|||
|
|||
for ( int i=0; i<vertices.size(); i++ ) { |
|||
joints.push_back( new CircleJoint() ); |
|||
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
void ProjectionEditor::createJoints() { |
|||
if (surfaceManager == NULL) return; |
|||
clearJoints(); |
|||
|
|||
if (surfaceManager->getSelectedSurface() == NULL) { |
|||
ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected."); |
|||
return; |
|||
} |
|||
|
|||
vector<ofVec3f>& vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
|
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
joints.push_back(new CircleJoint()); |
|||
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::updateJoints() |
|||
{ |
|||
vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices(); |
|||
for ( int i=0; i<vertices.size(); i++ ) { |
|||
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
void ProjectionEditor::updateJoints() { |
|||
vector<ofVec3f>& vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::unselectAllJoints() |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
joints[i]->unselect(); |
|||
} |
|||
void ProjectionEditor::unselectAllJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->unselect(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelectedSurface(ofVec2f by) |
|||
{ |
|||
if ( surfaceManager == NULL ) return; |
|||
if ( surfaceManager->getSelectedSurface() == NULL ) return; |
|||
surfaceManager->getSelectedSurface()->moveBy(by); |
|||
/*vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices();
|
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += by; |
|||
}*/ |
|||
updateJoints(); |
|||
void ProjectionEditor::moveSelectedSurface(ofVec2f by) { |
|||
if (surfaceManager == NULL) return; |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
surfaceManager->getSelectedSurface()->moveBy(by); |
|||
/*vector<ofVec3f>& vertices =
|
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += by; |
|||
}*/ |
|||
updateJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::stopDragJoints() |
|||
{ |
|||
for (int i=0; i<joints.size(); i++){ |
|||
joints[i]->stopDrag(); |
|||
} |
|||
void ProjectionEditor::stopDragJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->stopDrag(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelection(ofVec2f by) |
|||
{ |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint* selectedJoint; |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if (joints[i]->isSelected()) { |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if ( bJointSelected ) { |
|||
selectedJoint->position += by; |
|||
} else { |
|||
moveSelectedSurface(by); |
|||
void ProjectionEditor::moveSelection(ofVec2f by) { |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint* selectedJoint; |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isSelected()) { |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (bJointSelected) { |
|||
selectedJoint->position += by; |
|||
} else { |
|||
moveSelectedSurface(by); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSnapDistance(float newSnapDistance) |
|||
{ |
|||
fSnapDistance = newSnapDistance; |
|||
void ProjectionEditor::setSnapDistance(float newSnapDistance) { |
|||
fSnapDistance = newSnapDistance; |
|||
} |
|||
|
|||
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if ( joints[i]->hitTest(pos) ){ |
|||
return joints[i]; |
|||
} |
|||
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->hitTest(pos)) { |
|||
return joints[i]; |
|||
} |
|||
return NULL; |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
void ProjectionEditor::drawJoints() |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
joints[i]->draw(); |
|||
} |
|||
void ProjectionEditor::drawJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->draw(); |
|||
} |
|||
} |
|||
} |
|||
}} |
|||
} |
@ -1,266 +1,243 @@ |
|||
#include "QuadSurface.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
QuadSurface::QuadSurface() |
|||
{ |
|||
cout << "QuadSurface constructor." << endl; |
|||
setup(); |
|||
} |
|||
|
|||
QuadSurface::~QuadSurface() |
|||
{ |
|||
cout << "QuadSurface destructor." << endl; |
|||
} |
|||
|
|||
void QuadSurface::setup() |
|||
{ |
|||
// Create 4 points for the 2 triangles
|
|||
ofVec2f p1 = ofVec2f(0, 0); |
|||
ofVec2f p2 = ofVec2f(0, ofGetHeight()); |
|||
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); |
|||
ofVec2f p4 = ofVec2f(ofGetWidth(), 0); |
|||
|
|||
// Create 4 point for the texture coordinates
|
|||
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); |
|||
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); |
|||
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); |
|||
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); |
|||
|
|||
setup( p1, p2, p3, p4, t1, t2, t3, t4, texture ); |
|||
} |
|||
|
|||
void QuadSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, |
|||
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, ofTexture* texturePtr ) |
|||
{ |
|||
// Assign texture
|
|||
texture = texturePtr; |
|||
|
|||
// Clear mesh
|
|||
mesh.clear(); |
|||
|
|||
// Create a surface with the points
|
|||
mesh.addVertex( p1 ); |
|||
mesh.addVertex( p2 ); |
|||
mesh.addVertex( p3 ); |
|||
mesh.addVertex( p4 ); |
|||
|
|||
// Add 2 triangles
|
|||
mesh.addTriangle(0, 2, 3); |
|||
mesh.addTriangle(0, 1, 2); |
|||
|
|||
// Add texture coordinates
|
|||
mesh.addTexCoord(t1); |
|||
mesh.addTexCoord(t2); |
|||
mesh.addTexCoord(t3); |
|||
mesh.addTexCoord(t4); |
|||
|
|||
// Pure GL setup
|
|||
// indices
|
|||
quadIndices[0] = 0; |
|||
quadIndices[1] = 1; |
|||
quadIndices[2] = 2; |
|||
quadIndices[3] = 0; |
|||
quadIndices[4] = 2; |
|||
quadIndices[5] = 3; |
|||
//tex coords (those are alway 0)
|
|||
quadTexCoordinates[2] = 0; |
|||
quadTexCoordinates[6] = 0; |
|||
quadTexCoordinates[10] = 0; |
|||
quadTexCoordinates[14] = 0; |
|||
|
|||
calculate4dTextureCoords(); |
|||
} |
|||
|
|||
void QuadSurface::draw() |
|||
{ |
|||
/*if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
|
|||
calculate4dTextureCoords(); |
|||
}*/ |
|||
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|||
glTexCoordPointer(4, GL_FLOAT, 0, quadTexCoordinates); |
|||
glVertexPointer(3, GL_FLOAT, 0, quadVertices); |
|||
|
|||
texture->bind(); |
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, quadIndices); |
|||
texture->unbind(); |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
QuadSurface::QuadSurface() { |
|||
cout << "QuadSurface constructor." << endl; |
|||
setup(); |
|||
} |
|||
|
|||
QuadSurface::~QuadSurface() { cout << "QuadSurface destructor." << endl; } |
|||
|
|||
void QuadSurface::setup() { |
|||
// Create 4 points for the 2 triangles
|
|||
ofVec2f p1 = ofVec2f(0, 0); |
|||
ofVec2f p2 = ofVec2f(0, ofGetHeight()); |
|||
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); |
|||
ofVec2f p4 = ofVec2f(ofGetWidth(), 0); |
|||
|
|||
// Create 4 point for the texture coordinates
|
|||
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); |
|||
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); |
|||
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); |
|||
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); |
|||
|
|||
void QuadSurface::setVertex(int index, ofVec2f p) |
|||
{ |
|||
if ( index > 3 ) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setVertex(index, p); |
|||
calculate4dTextureCoords(); |
|||
} |
|||
setup(p1, p2, p3, p4, t1, t2, t3, t4, texture); |
|||
} |
|||
|
|||
void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, |
|||
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, |
|||
ofTexture* texturePtr) { |
|||
// Assign texture
|
|||
texture = texturePtr; |
|||
|
|||
void QuadSurface::setTexCoord(int index, ofVec2f t) |
|||
{ |
|||
if ( index > 3 ) { |
|||
ofLog() << "Texture coordinate with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setTexCoord(index, t); |
|||
calculate4dTextureCoords(); |
|||
} |
|||
// Clear mesh
|
|||
mesh.clear(); |
|||
|
|||
void QuadSurface::moveBy(ofVec2f v) |
|||
{ |
|||
vector<ofVec3f>& vertices = getVertices(); |
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += v; |
|||
} |
|||
calculate4dTextureCoords(); |
|||
} |
|||
// Create a surface with the points
|
|||
mesh.addVertex(p1); |
|||
mesh.addVertex(p2); |
|||
mesh.addVertex(p3); |
|||
mesh.addVertex(p4); |
|||
|
|||
int QuadSurface::getType() |
|||
{ |
|||
return SurfaceType::QUAD_SURFACE; |
|||
} |
|||
// Add 2 triangles
|
|||
mesh.addTriangle(0, 2, 3); |
|||
mesh.addTriangle(0, 1, 2); |
|||
|
|||
bool QuadSurface::hitTest(ofVec2f p) |
|||
{ |
|||
// Construct ofPolyline from vertices
|
|||
ofPolyline line = getHitArea(); |
|||
|
|||
if ( line.inside(p.x, p.y) ) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
// Add texture coordinates
|
|||
mesh.addTexCoord(t1); |
|||
mesh.addTexCoord(t2); |
|||
mesh.addTexCoord(t3); |
|||
mesh.addTexCoord(t4); |
|||
|
|||
ofVec2f QuadSurface::getVertex(int index) |
|||
{ |
|||
if ( index > 3 ) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
throw std::runtime_error("Vertex index out of bounds."); |
|||
} |
|||
|
|||
ofVec3f vert = mesh.getVertex(index); |
|||
return ofVec2f(vert.x, vert.y); |
|||
} |
|||
// Pure GL setup
|
|||
// indices
|
|||
quadIndices[0] = 0; |
|||
quadIndices[1] = 1; |
|||
quadIndices[2] = 2; |
|||
quadIndices[3] = 0; |
|||
quadIndices[4] = 2; |
|||
quadIndices[5] = 3; |
|||
// tex coords (those are alway 0)
|
|||
quadTexCoordinates[2] = 0; |
|||
quadTexCoordinates[6] = 0; |
|||
quadTexCoordinates[10] = 0; |
|||
quadTexCoordinates[14] = 0; |
|||
|
|||
ofVec2f QuadSurface::getTexCoord(int index) |
|||
{ |
|||
if (index > 3) { |
|||
throw std::runtime_error("Texture coordinate index out of bounds."); |
|||
} |
|||
|
|||
return mesh.getTexCoord(index); |
|||
calculate4dTextureCoords(); |
|||
} |
|||
|
|||
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 ) ); |
|||
line.addVertex( ofPoint( mesh.getVertex(3).x, mesh.getVertex(3).y ) ); |
|||
line.close(); |
|||
|
|||
return line; |
|||
} |
|||
void QuadSurface::draw() { |
|||
/*if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){
|
|||
calculate4dTextureCoords(); |
|||
}*/ |
|||
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|||
glTexCoordPointer(4, GL_FLOAT, 0, quadTexCoordinates); |
|||
glVertexPointer(3, GL_FLOAT, 0, quadVertices); |
|||
|
|||
ofPolyline QuadSurface::getTextureHitArea() |
|||
{ |
|||
ofPolyline line; |
|||
vector<ofVec2f>& texCoords = mesh.getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); |
|||
for ( int i=0; i<texCoords.size(); i++ ) { |
|||
line.addVertex( ofPoint( texCoords[i] * textureSize ) ); |
|||
} |
|||
line.close(); |
|||
|
|||
return line; |
|||
texture->bind(); |
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, quadIndices); |
|||
texture->unbind(); |
|||
} |
|||
|
|||
vector<ofVec3f>& QuadSurface::getVertices() |
|||
{ |
|||
// return only joint vertices
|
|||
return mesh.getVertices(); |
|||
} |
|||
void QuadSurface::setVertex(int index, ofVec2f p) { |
|||
if (index > 3) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
vector<ofVec2f>& QuadSurface::getTexCoords() |
|||
{ |
|||
|
|||
return mesh.getTexCoords(); |
|||
mesh.setVertex(index, p); |
|||
calculate4dTextureCoords(); |
|||
} |
|||
|
|||
void QuadSurface::calculate4dTextureCoords() |
|||
{ |
|||
// Perspective Warping with OpenGL Fixed Pipeline and q coordinates
|
|||
// see:
|
|||
// http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/
|
|||
// for information on the technique
|
|||
// Pue OpenGL is used because the ofMesh sadly doesn't support ofVec4f as
|
|||
// texture coordinates.
|
|||
// calculate intersection point
|
|||
ofVec3f p0 = mesh.getVertex(0); |
|||
ofVec3f p1 = mesh.getVertex(1); |
|||
ofVec3f p2 = mesh.getVertex(2); |
|||
ofVec3f p3 = mesh.getVertex(3); |
|||
|
|||
ofVec3f t0 = mesh.getTexCoord(0); |
|||
ofVec3f t1 = mesh.getTexCoord(1); |
|||
ofVec3f t2 = mesh.getTexCoord(2); |
|||
ofVec3f t3 = mesh.getTexCoord(3); |
|||
|
|||
ofPoint interSect; |
|||
ofLineSegmentIntersection(ofPoint(p0.x, p0.y), ofPoint(p2.x, p2.y), |
|||
ofPoint(p1.x, p1.y), ofPoint(p3.x, p3.y), |
|||
interSect); |
|||
ofVec3f interSecVec = ofVec3f(interSect.x, interSect.y, 0); |
|||
|
|||
// calculate distances to intersection point
|
|||
float d0 = interSecVec.distance(p0); |
|||
float d1 = interSecVec.distance(p1); |
|||
float d2 = interSecVec.distance(p2); |
|||
float d3 = interSecVec.distance(p3); |
|||
|
|||
// vertices
|
|||
// top left corner
|
|||
quadVertices[0] = p0.x; |
|||
quadVertices[1] = p0.y; |
|||
quadVertices[2] = 0; |
|||
// top right corner
|
|||
quadVertices[3] = p1.x; |
|||
quadVertices[4] = p1.y; |
|||
quadVertices[5] = 0; |
|||
// bottom right corner
|
|||
quadVertices[6] = p2.x; |
|||
quadVertices[7] = p2.y; |
|||
quadVertices[8] = 0; |
|||
// bottom left corner
|
|||
quadVertices[9] = p3.x; |
|||
quadVertices[10] = p3.y; |
|||
quadVertices[11] = 0; |
|||
|
|||
float q0 = (d0 + d2) / (d2); |
|||
float q1 = (d1 + d3) / (d3); |
|||
float q2 = (d2 + d0) / (d0); |
|||
float q3 = (d3 + d1) / (d1); |
|||
|
|||
quadTexCoordinates[0] = t0.x; |
|||
quadTexCoordinates[1] = t0.y; |
|||
quadTexCoordinates[3] = q0; |
|||
|
|||
quadTexCoordinates[4] = t1.x * q1; |
|||
quadTexCoordinates[5] = t1.y; |
|||
quadTexCoordinates[7] = q1; |
|||
|
|||
quadTexCoordinates[8] = t2.x * q2; |
|||
quadTexCoordinates[9] = t2.y * q2; |
|||
quadTexCoordinates[11] = q2; |
|||
|
|||
quadTexCoordinates[12] = t3.x; |
|||
quadTexCoordinates[13] = t3.y * q3; |
|||
quadTexCoordinates[15] = q3; |
|||
|
|||
} |
|||
void QuadSurface::setTexCoord(int index, ofVec2f t) { |
|||
if (index > 3) { |
|||
ofLog() << "Texture coordinate with this index does not exist: " << index |
|||
<< endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setTexCoord(index, t); |
|||
calculate4dTextureCoords(); |
|||
} |
|||
|
|||
void QuadSurface::moveBy(ofVec2f v) { |
|||
vector<ofVec3f>& vertices = getVertices(); |
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
vertices[i] += v; |
|||
} |
|||
calculate4dTextureCoords(); |
|||
} |
|||
|
|||
int QuadSurface::getType() { return SurfaceType::QUAD_SURFACE; } |
|||
|
|||
bool QuadSurface::hitTest(ofVec2f p) { |
|||
// Construct ofPolyline from vertices
|
|||
ofPolyline line = getHitArea(); |
|||
|
|||
if (line.inside(p.x, p.y)) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
ofVec2f QuadSurface::getVertex(int index) { |
|||
if (index > 3) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
throw std::runtime_error("Vertex index out of bounds."); |
|||
} |
|||
|
|||
ofVec3f vert = mesh.getVertex(index); |
|||
return ofVec2f(vert.x, vert.y); |
|||
} |
|||
|
|||
ofVec2f QuadSurface::getTexCoord(int index) { |
|||
if (index > 3) { |
|||
throw std::runtime_error("Texture coordinate index out of bounds."); |
|||
} |
|||
|
|||
return mesh.getTexCoord(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)); |
|||
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y)); |
|||
line.close(); |
|||
|
|||
return line; |
|||
} |
|||
|
|||
ofPolyline QuadSurface::getTextureHitArea() { |
|||
ofPolyline line; |
|||
vector<ofVec2f>& texCoords = mesh.getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); |
|||
for (int i = 0; i < texCoords.size(); i++) { |
|||
line.addVertex(ofPoint(texCoords[i] * textureSize)); |
|||
} |
|||
line.close(); |
|||
|
|||
return line; |
|||
} |
|||
|
|||
}} |
|||
vector<ofVec3f>& QuadSurface::getVertices() { |
|||
// return only joint vertices
|
|||
return mesh.getVertices(); |
|||
} |
|||
|
|||
vector<ofVec2f>& QuadSurface::getTexCoords() { return mesh.getTexCoords(); } |
|||
|
|||
void QuadSurface::calculate4dTextureCoords() { |
|||
// Perspective Warping with OpenGL Fixed Pipeline and q coordinates
|
|||
// see:
|
|||
// http://www.reedbeta.com/blog/2012/05/26/quadrilateral-interpolation-part-1/
|
|||
// for information on the technique
|
|||
// Pue OpenGL is used because the ofMesh sadly doesn't support ofVec4f as
|
|||
// texture coordinates.
|
|||
// calculate intersection point
|
|||
ofVec3f p0 = mesh.getVertex(0); |
|||
ofVec3f p1 = mesh.getVertex(1); |
|||
ofVec3f p2 = mesh.getVertex(2); |
|||
ofVec3f p3 = mesh.getVertex(3); |
|||
|
|||
ofVec3f t0 = mesh.getTexCoord(0); |
|||
ofVec3f t1 = mesh.getTexCoord(1); |
|||
ofVec3f t2 = mesh.getTexCoord(2); |
|||
ofVec3f t3 = mesh.getTexCoord(3); |
|||
|
|||
ofPoint interSect; |
|||
ofLineSegmentIntersection(ofPoint(p0.x, p0.y), ofPoint(p2.x, p2.y), |
|||
ofPoint(p1.x, p1.y), ofPoint(p3.x, p3.y), |
|||
interSect); |
|||
ofVec3f interSecVec = ofVec3f(interSect.x, interSect.y, 0); |
|||
|
|||
// calculate distances to intersection point
|
|||
float d0 = interSecVec.distance(p0); |
|||
float d1 = interSecVec.distance(p1); |
|||
float d2 = interSecVec.distance(p2); |
|||
float d3 = interSecVec.distance(p3); |
|||
|
|||
// vertices
|
|||
// top left corner
|
|||
quadVertices[0] = p0.x; |
|||
quadVertices[1] = p0.y; |
|||
quadVertices[2] = 0; |
|||
// top right corner
|
|||
quadVertices[3] = p1.x; |
|||
quadVertices[4] = p1.y; |
|||
quadVertices[5] = 0; |
|||
// bottom right corner
|
|||
quadVertices[6] = p2.x; |
|||
quadVertices[7] = p2.y; |
|||
quadVertices[8] = 0; |
|||
// bottom left corner
|
|||
quadVertices[9] = p3.x; |
|||
quadVertices[10] = p3.y; |
|||
quadVertices[11] = 0; |
|||
|
|||
float q0 = (d0 + d2) / (d2); |
|||
float q1 = (d1 + d3) / (d3); |
|||
float q2 = (d2 + d0) / (d0); |
|||
float q3 = (d3 + d1) / (d1); |
|||
|
|||
quadTexCoordinates[0] = t0.x; |
|||
quadTexCoordinates[1] = t0.y; |
|||
quadTexCoordinates[3] = q0; |
|||
|
|||
quadTexCoordinates[4] = t1.x * q1; |
|||
quadTexCoordinates[5] = t1.y; |
|||
quadTexCoordinates[7] = q1; |
|||
|
|||
quadTexCoordinates[8] = t2.x * q2; |
|||
quadTexCoordinates[9] = t2.y * q2; |
|||
quadTexCoordinates[11] = q2; |
|||
|
|||
quadTexCoordinates[12] = t3.x; |
|||
quadTexCoordinates[13] = t3.y * q3; |
|||
quadTexCoordinates[15] = q3; |
|||
} |
|||
} |
|||
} |
@ -1,139 +1,121 @@ |
|||
#include "SourcesEditor.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
SourcesEditor::SourcesEditor() |
|||
{ |
|||
defImgDir = DEFAULT_IMAGES_DIR; |
|||
registerAppEvents(); |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
SourcesEditor::SourcesEditor() { |
|||
defImgDir = DEFAULT_IMAGES_DIR; |
|||
registerAppEvents(); |
|||
} |
|||
|
|||
SourcesEditor::~SourcesEditor() |
|||
{ |
|||
unregisterAppEvents(); |
|||
delete gui; |
|||
while ( images.size() ) { |
|||
delete images.back(); |
|||
images.pop_back(); |
|||
} |
|||
SourcesEditor::~SourcesEditor() { |
|||
unregisterAppEvents(); |
|||
delete gui; |
|||
while (images.size()) { |
|||
delete images.back(); |
|||
images.pop_back(); |
|||
} |
|||
} |
|||
|
|||
void SourcesEditor::registerAppEvents() |
|||
{ |
|||
ofAddListener(ofEvents().setup, this, &SourcesEditor::setup); |
|||
void SourcesEditor::registerAppEvents() { |
|||
ofAddListener(ofEvents().setup, this, &SourcesEditor::setup); |
|||
} |
|||
|
|||
void SourcesEditor::unregisterAppEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); |
|||
void SourcesEditor::unregisterAppEvents() { |
|||
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); |
|||
} |
|||
|
|||
void SourcesEditor::setup(ofEventArgs& args) |
|||
{ |
|||
gui = new RadioList(); |
|||
|
|||
// read directory contents
|
|||
ofDirectory imgDir; |
|||
imgDir.listDir(defImgDir); |
|||
imgDir.sort(); |
|||
|
|||
vector<string> vnames; |
|||
|
|||
for(int i = 0; i < (int)imgDir.size(); i++){ |
|||
//images[i].loadImage(imgDir.getPath(i));
|
|||
vnames.push_back(imgDir.getName(i)); |
|||
} |
|||
|
|||
gui->setup("Images", vnames); |
|||
gui->setPosition(20, 20); |
|||
ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent); |
|||
} |
|||
void SourcesEditor::setup(ofEventArgs& args) { |
|||
gui = new RadioList(); |
|||
|
|||
void SourcesEditor::draw() |
|||
{ |
|||
// Don't draw if there is no source selected
|
|||
if ( surfaceManager->getSelectedSurface() == NULL ) { |
|||
return; |
|||
} |
|||
|
|||
gui->draw(); |
|||
// read directory contents
|
|||
ofDirectory imgDir; |
|||
imgDir.listDir(defImgDir); |
|||
imgDir.sort(); |
|||
|
|||
vector<string> vnames; |
|||
|
|||
for (int i = 0; i < (int)imgDir.size(); i++) { |
|||
// images[i].loadImage(imgDir.getPath(i));
|
|||
vnames.push_back(imgDir.getName(i)); |
|||
} |
|||
|
|||
gui->setup("Images", vnames); |
|||
gui->setPosition(20, 20); |
|||
ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent); |
|||
} |
|||
|
|||
void SourcesEditor::loadImage( string name, string path ) |
|||
{ |
|||
images.push_back(new ofImage()); |
|||
images.back()->loadImage(path); |
|||
|
|||
imageNames.push_back(name); |
|||
|
|||
ofSendMessage("imageLoaded"); |
|||
void SourcesEditor::draw() { |
|||
// Don't draw if there is no source selected
|
|||
if (surfaceManager->getSelectedSurface() == NULL) { |
|||
return; |
|||
} |
|||
|
|||
gui->draw(); |
|||
} |
|||
|
|||
void SourcesEditor::disable() |
|||
{ |
|||
gui->disable(); |
|||
void SourcesEditor::loadImage(string name, string path) { |
|||
images.push_back(new ofImage()); |
|||
images.back()->loadImage(path); |
|||
|
|||
imageNames.push_back(name); |
|||
|
|||
ofSendMessage("imageLoaded"); |
|||
} |
|||
|
|||
void SourcesEditor::enable() |
|||
{ |
|||
// Don't enable if there is no surface selected
|
|||
if ( surfaceManager->getSelectedSurface() == NULL ) { |
|||
cout << "No surface selected. Not enable()ing source list." << endl; |
|||
return; |
|||
} |
|||
|
|||
gui->enable(); |
|||
void SourcesEditor::disable() { gui->disable(); } |
|||
|
|||
void SourcesEditor::enable() { |
|||
// Don't enable if there is no surface selected
|
|||
if (surfaceManager->getSelectedSurface() == NULL) { |
|||
cout << "No surface selected. Not enable()ing source list." << endl; |
|||
return; |
|||
} |
|||
|
|||
gui->enable(); |
|||
} |
|||
|
|||
void SourcesEditor::setSurfaceManager(SurfaceManager *newSurfaceManager) |
|||
{ |
|||
surfaceManager = newSurfaceManager; |
|||
void SourcesEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|||
surfaceManager = newSurfaceManager; |
|||
} |
|||
|
|||
void SourcesEditor::selectImageSourceRadioButton(string name) |
|||
{ |
|||
if (name == "none") { |
|||
gui->unselectAll(); |
|||
void SourcesEditor::selectImageSourceRadioButton(string name) { |
|||
if (name == "none") { |
|||
gui->unselectAll(); |
|||
return; |
|||
} else { |
|||
int i; |
|||
for (i = 0; i < gui->size(); i++) { |
|||
if (gui->getItemName(i) == name) { |
|||
gui->selectItem(i); |
|||
return; |
|||
} else { |
|||
int i; |
|||
for (i = 0; i < gui->size(); i++) { |
|||
if (gui->getItemName(i) == name) { |
|||
gui->selectItem(i); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
int SourcesEditor::getLoadedTexCount() |
|||
{ |
|||
return images.size(); |
|||
} |
|||
int SourcesEditor::getLoadedTexCount() { return images.size(); } |
|||
|
|||
ofTexture* SourcesEditor::getTexture(int index) |
|||
{ |
|||
if (index >= images.size()){ |
|||
throw std::runtime_error("Texture index out of bounds."); |
|||
} |
|||
|
|||
return &images[index]->getTextureReference(); |
|||
} |
|||
ofTexture* SourcesEditor::getTexture(int index) { |
|||
if (index >= images.size()) { |
|||
throw std::runtime_error("Texture index out of bounds."); |
|||
} |
|||
|
|||
void SourcesEditor::guiEvent(string &imageName) |
|||
{ |
|||
string name = imageName; |
|||
|
|||
if ( surfaceManager->getSelectedSurface() == NULL ) { |
|||
return; |
|||
} |
|||
|
|||
stringstream ss; |
|||
ss << defImgDir << name; |
|||
cout << "attempt to load image: " << ss.str() << endl; |
|||
ofTexture* texture = surfaceManager->loadImageSource(name, ss.str()); |
|||
surfaceManager->getSelectedSurface()->setTexture(texture); |
|||
surfaceManager->manageMemory(); |
|||
return &images[index]->getTextureReference(); |
|||
} |
|||
|
|||
}} |
|||
void SourcesEditor::guiEvent(string& imageName) { |
|||
string name = imageName; |
|||
|
|||
if (surfaceManager->getSelectedSurface() == NULL) { |
|||
return; |
|||
} |
|||
|
|||
stringstream ss; |
|||
ss << defImgDir << name; |
|||
cout << "attempt to load image: " << ss.str() << endl; |
|||
ofTexture* texture = surfaceManager->loadImageSource(name, ss.str()); |
|||
surfaceManager->getSelectedSurface()->setTexture(texture); |
|||
surfaceManager->manageMemory(); |
|||
} |
|||
} |
|||
} |
@ -1,258 +1,243 @@ |
|||
#include "SurfaceManagerGui.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
SurfaceManagerGui::SurfaceManagerGui() |
|||
{ |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
SurfaceManagerGui::SurfaceManagerGui() { |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
} |
|||
|
|||
SurfaceManagerGui::~SurfaceManagerGui() |
|||
{ |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
SurfaceManagerGui::~SurfaceManagerGui() { |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
} |
|||
|
|||
void SurfaceManagerGui::registerMouseEvents() |
|||
{ |
|||
ofAddListener(ofEvents().mousePressed, this, &SurfaceManagerGui::mousePressed); |
|||
ofAddListener(ofEvents().mouseReleased, this, &SurfaceManagerGui::mouseReleased); |
|||
ofAddListener(ofEvents().mouseDragged, this, &SurfaceManagerGui::mouseDragged); |
|||
void SurfaceManagerGui::registerMouseEvents() { |
|||
ofAddListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofAddListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofAddListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::unregisterMouseEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().mousePressed, this, &SurfaceManagerGui::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseReleased, this, &SurfaceManagerGui::mouseReleased); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, &SurfaceManagerGui::mouseDragged); |
|||
void SurfaceManagerGui::unregisterMouseEvents() { |
|||
ofRemoveListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::draw() |
|||
{ |
|||
if ( surfaceManager == NULL ) return; |
|||
|
|||
if ( guiMode == GuiMode::NONE ) { |
|||
surfaceManager->draw(); |
|||
} else if ( guiMode == GuiMode::TEXTURE_MAPPING ) { |
|||
|
|||
// draw the texture of the selected surface
|
|||
if ( surfaceManager->getSelectedSurface() != NULL ) { |
|||
surfaceManager->getSelectedSurface()->drawTexture( ofVec2f(0,0) ); |
|||
} |
|||
|
|||
// draw surfaces with opacity
|
|||
ofPushStyle(); |
|||
ofSetColor(255, 255, 255, 200); |
|||
surfaceManager->draw(); |
|||
ofPopStyle(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// hilight selected surface texture
|
|||
drawSelectedSurfaceTextureHighlight(); |
|||
|
|||
// draw texture editing GUI on top
|
|||
textureEditor.draw(); |
|||
|
|||
} else if ( guiMode == GuiMode::PROJECTION_MAPPING ) { |
|||
|
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// draw projection mapping editing gui
|
|||
projectionEditor.draw(); |
|||
|
|||
} else if ( guiMode == GuiMode::SOURCE_SELECTION ) { |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
sourcesEditor.draw(); |
|||
} |
|||
} |
|||
void SurfaceManagerGui::draw() { |
|||
if (surfaceManager == NULL) return; |
|||
|
|||
void SurfaceManagerGui::mousePressed(ofMouseEventArgs &args) |
|||
{ |
|||
if ( guiMode == GuiMode::NONE ) { |
|||
return; |
|||
} else if ( guiMode == GuiMode::TEXTURE_MAPPING ) { |
|||
|
|||
bool bSurfaceSelected = false; |
|||
|
|||
CircleJoint* hitJoint = textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if ( hitJoint != NULL ) { |
|||
textureEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
} else { |
|||
textureEditor.unselectAllJoints(); |
|||
} |
|||
|
|||
if ( surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected ) { |
|||
// hittest texture area to see if we are hitting the texture surface
|
|||
if ( surfaceManager->getSelectedSurface()->getTextureHitArea().inside(args.x, args.y) ) { |
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
} |
|||
|
|||
} else if ( guiMode == GuiMode::PROJECTION_MAPPING ) { |
|||
|
|||
bool bSurfaceSelected = false; |
|||
|
|||
CircleJoint* hitJoint = projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if ( hitJoint != NULL ) { |
|||
projectionEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
} |
|||
|
|||
// attempt to select surface, loop from end to beginning
|
|||
if ( !bSurfaceSelected ){ |
|||
for ( int i=surfaceManager->size()-1; i>=0; i-- ) { |
|||
if ( surfaceManager->getSurface(i)->hitTest( ofVec2f(args.x, args.y) ) ) { |
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->selectSurface(i); |
|||
projectionEditor.createJoints(); |
|||
bSurfaceSelected = true; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if ( bSurfaceSelected && hitJoint == NULL ) { |
|||
// if not hitting the joints, start drag only if we have a selected surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
|
|||
if ( !bSurfaceSelected ) { |
|||
// unselect if no surface selected
|
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->deselectSurface(); |
|||
} |
|||
} else if ( guiMode == GuiMode::SOURCE_SELECTION ) { |
|||
|
|||
if (guiMode == GuiMode::NONE) { |
|||
surfaceManager->draw(); |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
// draw the texture of the selected surface
|
|||
if (surfaceManager->getSelectedSurface() != NULL) { |
|||
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs &args) |
|||
{ |
|||
stopDrag(); |
|||
projectionEditor.stopDragJoints(); |
|||
textureEditor.stopDragJoints(); |
|||
// draw surfaces with opacity
|
|||
ofPushStyle(); |
|||
ofSetColor(255, 255, 255, 200); |
|||
surfaceManager->draw(); |
|||
ofPopStyle(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// hilight selected surface texture
|
|||
drawSelectedSurfaceTextureHighlight(); |
|||
|
|||
// draw texture editing GUI on top
|
|||
textureEditor.draw(); |
|||
|
|||
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// draw projection mapping editing gui
|
|||
projectionEditor.draw(); |
|||
|
|||
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
sourcesEditor.draw(); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs &args) |
|||
{ |
|||
if (bDrag) { |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
ofVec2f distance = mousePosition - clickPosition; |
|||
|
|||
if ( guiMode == GuiMode::PROJECTION_MAPPING ) { |
|||
// add this distance to all vertices in surface
|
|||
projectionEditor.moveSelectedSurface(distance); |
|||
} else if ( guiMode == GuiMode::TEXTURE_MAPPING ) { |
|||
textureEditor.moveTexCoords(distance); |
|||
} |
|||
clickPosition = mousePosition; |
|||
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|||
if (guiMode == GuiMode::NONE) { |
|||
return; |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
bool bSurfaceSelected = false; |
|||
|
|||
CircleJoint* hitJoint = |
|||
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if (hitJoint != NULL) { |
|||
textureEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
} else { |
|||
textureEditor.unselectAllJoints(); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) |
|||
{ |
|||
surfaceManager = newSurfaceManager; |
|||
projectionEditor.setSurfaceManager( surfaceManager ); |
|||
sourcesEditor.setSurfaceManager( surfaceManager ); |
|||
} |
|||
if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { |
|||
// hittest texture area to see if we are hitting the texture surface
|
|||
if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside( |
|||
args.x, args.y)) { |
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
} |
|||
|
|||
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
bool bSurfaceSelected = false; |
|||
|
|||
void SurfaceManagerGui::setMode(int newGuiMode) |
|||
{ |
|||
if (newGuiMode != GuiMode::NONE && |
|||
newGuiMode != GuiMode::TEXTURE_MAPPING && |
|||
newGuiMode != GuiMode::PROJECTION_MAPPING && |
|||
newGuiMode != GuiMode::SOURCE_SELECTION) { |
|||
throw std::runtime_error("Trying to set invalid mode."); |
|||
CircleJoint* hitJoint = |
|||
projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if (hitJoint != NULL) { |
|||
projectionEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
} |
|||
|
|||
if ( newGuiMode == GuiMode::NONE ) { |
|||
ofHideCursor(); |
|||
} else { |
|||
ofShowCursor(); |
|||
|
|||
// attempt to select surface, loop from end to beginning
|
|||
if (!bSurfaceSelected) { |
|||
for (int i = surfaceManager->size() - 1; i >= 0; i--) { |
|||
if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) { |
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->selectSurface(i); |
|||
projectionEditor.createJoints(); |
|||
bSurfaceSelected = true; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
guiMode = newGuiMode; |
|||
|
|||
if ( guiMode == GuiMode::SOURCE_SELECTION ) { |
|||
sourcesEditor.enable(); |
|||
string sourceName = surfaceManager->getSelectedSurfaceSourceName(); |
|||
sourcesEditor.selectImageSourceRadioButton(sourceName); |
|||
} else { |
|||
sourcesEditor.disable(); |
|||
|
|||
if (bSurfaceSelected && hitJoint == NULL) { |
|||
// if not hitting the joints, start drag only if we have a selected
|
|||
// surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
|
|||
if ( guiMode == GuiMode::TEXTURE_MAPPING ) { |
|||
textureEditor.enable(); |
|||
// refresh texture editor surface reference
|
|||
textureEditor.setSurface(surfaceManager->getSelectedSurface()); |
|||
} else { |
|||
textureEditor.disable(); |
|||
|
|||
if (!bSurfaceSelected) { |
|||
// unselect if no surface selected
|
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->deselectSurface(); |
|||
} |
|||
|
|||
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { |
|||
stopDrag(); |
|||
projectionEditor.stopDragJoints(); |
|||
textureEditor.stopDragJoints(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { |
|||
if (bDrag) { |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
ofVec2f distance = mousePosition - clickPosition; |
|||
|
|||
if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
projectionEditor.enable(); |
|||
} else { |
|||
projectionEditor.disable(); |
|||
// add this distance to all vertices in surface
|
|||
projectionEditor.moveSelectedSurface(distance); |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
textureEditor.moveTexCoords(distance); |
|||
} |
|||
clickPosition = mousePosition; |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceHighlight() |
|||
{ |
|||
if ( surfaceManager->getSelectedSurface() == NULL ) return; |
|||
|
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); |
|||
|
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 255, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|||
surfaceManager = newSurfaceManager; |
|||
projectionEditor.setSurfaceManager(surfaceManager); |
|||
sourcesEditor.setSurfaceManager(surfaceManager); |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() |
|||
{ |
|||
if ( surfaceManager->getSelectedSurface() == NULL ) return; |
|||
|
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); |
|||
|
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 0, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
void SurfaceManagerGui::setMode(int newGuiMode) { |
|||
if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && |
|||
newGuiMode != GuiMode::PROJECTION_MAPPING && |
|||
newGuiMode != GuiMode::SOURCE_SELECTION) { |
|||
throw std::runtime_error("Trying to set invalid mode."); |
|||
} |
|||
|
|||
if (newGuiMode == GuiMode::NONE) { |
|||
ofHideCursor(); |
|||
} else { |
|||
ofShowCursor(); |
|||
} |
|||
|
|||
guiMode = newGuiMode; |
|||
|
|||
if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
sourcesEditor.enable(); |
|||
string sourceName = surfaceManager->getSelectedSurfaceSourceName(); |
|||
sourcesEditor.selectImageSourceRadioButton(sourceName); |
|||
} else { |
|||
sourcesEditor.disable(); |
|||
} |
|||
|
|||
if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
textureEditor.enable(); |
|||
// refresh texture editor surface reference
|
|||
textureEditor.setSurface(surfaceManager->getSelectedSurface()); |
|||
} else { |
|||
textureEditor.disable(); |
|||
} |
|||
|
|||
if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
projectionEditor.enable(); |
|||
} else { |
|||
projectionEditor.disable(); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::startDrag() |
|||
{ |
|||
bDrag = true; |
|||
void SurfaceManagerGui::drawSelectedSurfaceHighlight() { |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
|
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); |
|||
|
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 255, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::stopDrag() |
|||
{ |
|||
bDrag = false; |
|||
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() { |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
|
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); |
|||
|
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 0, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
}} |
|||
void SurfaceManagerGui::startDrag() { bDrag = true; } |
|||
|
|||
void SurfaceManagerGui::stopDrag() { bDrag = false; } |
|||
} |
|||
} |
@ -1,13 +1,9 @@ |
|||
#pragma once |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
struct SurfaceType |
|||
{ |
|||
enum { |
|||
TRIANGLE_SURFACE, |
|||
QUAD_SURFACE |
|||
}; |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
struct SurfaceType { |
|||
enum { TRIANGLE_SURFACE, QUAD_SURFACE }; |
|||
}; |
|||
|
|||
}} |
|||
} |
|||
} |
@ -1,195 +1,189 @@ |
|||
#include "TextureEditor.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
TextureEditor::TextureEditor() |
|||
{ |
|||
clear(); |
|||
enable(); |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
TextureEditor::TextureEditor() { |
|||
clear(); |
|||
enable(); |
|||
} |
|||
|
|||
TextureEditor::~TextureEditor() |
|||
{ |
|||
clear(); |
|||
disable(); |
|||
TextureEditor::~TextureEditor() { |
|||
clear(); |
|||
disable(); |
|||
} |
|||
|
|||
void TextureEditor::registerAppEvents() |
|||
{ |
|||
ofAddListener(ofEvents().update, this, &TextureEditor::update); |
|||
void TextureEditor::registerAppEvents() { |
|||
ofAddListener(ofEvents().update, this, &TextureEditor::update); |
|||
} |
|||
|
|||
void TextureEditor::unregisterAppEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().update, this, &TextureEditor::update); |
|||
void TextureEditor::unregisterAppEvents() { |
|||
ofRemoveListener(ofEvents().update, this, &TextureEditor::update); |
|||
} |
|||
|
|||
void TextureEditor::registerKeyEvents() |
|||
{ |
|||
ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); |
|||
void TextureEditor::registerKeyEvents() { |
|||
ofAddListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); |
|||
} |
|||
|
|||
void TextureEditor::unregisterKeyEvents() |
|||
{ |
|||
ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); |
|||
void TextureEditor::unregisterKeyEvents() { |
|||
ofRemoveListener(ofEvents().keyPressed, this, &TextureEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, &TextureEditor::keyReleased); |
|||
} |
|||
|
|||
void TextureEditor::enable() |
|||
{ |
|||
registerAppEvents(); |
|||
registerKeyEvents(); |
|||
bShiftKeyDown = false; |
|||
void TextureEditor::enable() { |
|||
registerAppEvents(); |
|||
registerKeyEvents(); |
|||
bShiftKeyDown = false; |
|||
} |
|||
|
|||
void TextureEditor::disable() |
|||
{ |
|||
unregisterAppEvents(); |
|||
unregisterKeyEvents(); |
|||
void TextureEditor::disable() { |
|||
unregisterAppEvents(); |
|||
unregisterKeyEvents(); |
|||
} |
|||
|
|||
void TextureEditor::update(ofEventArgs &args) |
|||
{ |
|||
if ( surface == NULL ) return; |
|||
|
|||
// update surface if one of the joints is being dragged
|
|||
ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() ); |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if ( joints[i]->isDragged() || joints[i]->isSelected() ) { |
|||
// update vertex to new location
|
|||
surface->setTexCoord(i, joints[i]->position / textureSize); |
|||
break; |
|||
} |
|||
void TextureEditor::update(ofEventArgs& args) { |
|||
if (surface == NULL) return; |
|||
|
|||
// update surface if one of the joints is being dragged
|
|||
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), |
|||
surface->getTexture()->getHeight()); |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isDragged() || joints[i]->isSelected()) { |
|||
// update vertex to new location
|
|||
surface->setTexCoord(i, joints[i]->position / textureSize); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::keyPressed(ofKeyEventArgs &args) |
|||
{ |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if (bShiftKeyDown) moveStep = 10.0f; |
|||
else moveStep = 0.5f; |
|||
|
|||
switch (key) { |
|||
case OF_KEY_LEFT: moveSelection(ofVec2f(-moveStep,0.0f)); break; |
|||
case OF_KEY_RIGHT: 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::keyPressed(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if (bShiftKeyDown) |
|||
moveStep = 10.0f; |
|||
else |
|||
moveStep = 0.5f; |
|||
|
|||
switch (key) { |
|||
case OF_KEY_LEFT: |
|||
moveSelection(ofVec2f(-moveStep, 0.0f)); |
|||
break; |
|||
case OF_KEY_RIGHT: |
|||
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) |
|||
{ |
|||
int key = args.key; |
|||
switch (key) { |
|||
case OF_KEY_SHIFT: bShiftKeyDown = false; break; |
|||
} |
|||
void TextureEditor::keyReleased(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
switch (key) { |
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = false; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::draw() { |
|||
if (surface == NULL) return; |
|||
|
|||
void TextureEditor::draw() |
|||
{ |
|||
if (surface == NULL) return; |
|||
|
|||
drawJoints(); |
|||
drawJoints(); |
|||
} |
|||
|
|||
void TextureEditor::drawJoints() |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
joints[i]->draw(); |
|||
} |
|||
void TextureEditor::drawJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->draw(); |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::setSurface(BaseSurface* newSurface) |
|||
{ |
|||
surface = newSurface; |
|||
createJoints(); |
|||
void TextureEditor::setSurface(BaseSurface* newSurface) { |
|||
surface = newSurface; |
|||
createJoints(); |
|||
} |
|||
|
|||
void TextureEditor::clear() |
|||
{ |
|||
surface = NULL; |
|||
clearJoints(); |
|||
void TextureEditor::clear() { |
|||
surface = NULL; |
|||
clearJoints(); |
|||
} |
|||
|
|||
void TextureEditor::createJoints() |
|||
{ |
|||
if ( surface == NULL ) return; |
|||
clearJoints(); |
|||
vector<ofVec2f>& texCoords = surface->getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), surface->getTexture()->getHeight()); |
|||
|
|||
for ( int i=0; i<texCoords.size(); i++ ) { |
|||
joints.push_back(new CircleJoint()); |
|||
joints.back()->position = texCoords[i] * textureSize; |
|||
} |
|||
} |
|||
void TextureEditor::createJoints() { |
|||
if (surface == NULL) return; |
|||
clearJoints(); |
|||
vector<ofVec2f>& texCoords = surface->getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), |
|||
surface->getTexture()->getHeight()); |
|||
|
|||
void TextureEditor::clearJoints() |
|||
{ |
|||
while ( joints.size() ) { |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
for (int i = 0; i < texCoords.size(); i++) { |
|||
joints.push_back(new CircleJoint()); |
|||
joints.back()->position = texCoords[i] * textureSize; |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::unselectAllJoints() |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
joints[i]->unselect(); |
|||
} |
|||
void TextureEditor::clearJoints() { |
|||
while (joints.size()) { |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::moveTexCoords(ofVec2f by) |
|||
{ |
|||
if ( surface == NULL ) return; |
|||
vector<ofVec2f>& texCoords = surface->getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() ); |
|||
for (int i=0; i<texCoords.size(); i++) { |
|||
joints[i]->position += by; |
|||
texCoords[i] = joints[i]->position / textureSize; |
|||
} |
|||
void TextureEditor::unselectAllJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->unselect(); |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::stopDragJoints() |
|||
{ |
|||
for (int i=0; i<joints.size(); i++){ |
|||
joints[i]->stopDrag(); |
|||
} |
|||
void TextureEditor::moveTexCoords(ofVec2f by) { |
|||
if (surface == NULL) return; |
|||
vector<ofVec2f>& texCoords = surface->getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), |
|||
surface->getTexture()->getHeight()); |
|||
for (int i = 0; i < texCoords.size(); i++) { |
|||
joints[i]->position += by; |
|||
texCoords[i] = joints[i]->position / textureSize; |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::moveSelection(ofVec2f by) |
|||
{ |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint* selectedJoint; |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if (joints[i]->isSelected()) { |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if ( bJointSelected ) { |
|||
selectedJoint->position += by; |
|||
} else { |
|||
moveTexCoords(by); |
|||
void TextureEditor::stopDragJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->stopDrag(); |
|||
} |
|||
} |
|||
|
|||
void TextureEditor::moveSelection(ofVec2f by) { |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint* selectedJoint; |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isSelected()) { |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (bJointSelected) { |
|||
selectedJoint->position += by; |
|||
} else { |
|||
moveTexCoords(by); |
|||
} |
|||
} |
|||
|
|||
CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos) |
|||
{ |
|||
for ( int i=0; i<joints.size(); i++ ) { |
|||
if ( joints[i]->hitTest(pos) ){ |
|||
return joints[i]; |
|||
} |
|||
CircleJoint* TextureEditor::hitTestJoints(ofVec2f pos) { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->hitTest(pos)) { |
|||
return joints[i]; |
|||
} |
|||
return NULL; |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
}} |
|||
} |
|||
} |
@ -1,158 +1,139 @@ |
|||
#include "TriangleSurface.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
TriangleSurface::TriangleSurface() |
|||
{ |
|||
cout << "TriangleSurface constructor." << endl; |
|||
setup(); |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
TriangleSurface::TriangleSurface() { |
|||
cout << "TriangleSurface constructor." << endl; |
|||
setup(); |
|||
} |
|||
|
|||
TriangleSurface::~TriangleSurface() |
|||
{ |
|||
cout << "TriangleSurface destructor." << endl; |
|||
TriangleSurface::~TriangleSurface() { |
|||
cout << "TriangleSurface destructor." << endl; |
|||
} |
|||
|
|||
void TriangleSurface::setup() |
|||
{ |
|||
// Create 3 points for the triangle
|
|||
ofVec2f p1 = ofVec2f(ofGetWidth()/2.0f, 0); |
|||
ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); |
|||
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); |
|||
|
|||
// Create 3 point for the texture coordinates
|
|||
ofVec2f t1 = ofVec2f(0.5f, 0); |
|||
ofVec2f t2 = ofVec2f(0, 1.0f); |
|||
ofVec2f t3 = ofVec2f(1, 1.0f); |
|||
|
|||
setup( p1, p2, p3, t1, t2, t3, texture ); |
|||
} |
|||
void TriangleSurface::setup() { |
|||
// Create 3 points for the triangle
|
|||
ofVec2f p1 = ofVec2f(ofGetWidth() / 2.0f, 0); |
|||
ofVec2f p2 = ofVec2f(ofVec2f(0, ofGetHeight())); |
|||
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); |
|||
|
|||
void TriangleSurface::setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr ) |
|||
{ |
|||
// Assign texture
|
|||
texture = texturePtr; |
|||
|
|||
// Clear mesh
|
|||
mesh.clear(); |
|||
|
|||
// Create a surface with the points
|
|||
mesh.addVertex( p1 ); |
|||
mesh.addVertex( p2 ); |
|||
mesh.addVertex( p3 ); |
|||
|
|||
// Add texture coordinates
|
|||
mesh.addTexCoord(t1); |
|||
mesh.addTexCoord(t2); |
|||
mesh.addTexCoord(t3); |
|||
} |
|||
// Create 3 point for the texture coordinates
|
|||
ofVec2f t1 = ofVec2f(0.5f, 0); |
|||
ofVec2f t2 = ofVec2f(0, 1.0f); |
|||
ofVec2f t3 = ofVec2f(1, 1.0f); |
|||
|
|||
void TriangleSurface::draw() |
|||
{ |
|||
texture->bind(); |
|||
mesh.draw(); |
|||
texture->unbind(); |
|||
setup(p1, p2, p3, t1, t2, t3, texture); |
|||
} |
|||
|
|||
void TriangleSurface::setVertex(int index, ofVec2f p) |
|||
{ |
|||
if ( index > 2 ) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setVertex(index, p); |
|||
void TriangleSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, |
|||
ofVec2f t2, ofVec2f t3, ofTexture* texturePtr) { |
|||
// Assign texture
|
|||
texture = texturePtr; |
|||
|
|||
// Clear mesh
|
|||
mesh.clear(); |
|||
|
|||
// Create a surface with the points
|
|||
mesh.addVertex(p1); |
|||
mesh.addVertex(p2); |
|||
mesh.addVertex(p3); |
|||
|
|||
// Add texture coordinates
|
|||
mesh.addTexCoord(t1); |
|||
mesh.addTexCoord(t2); |
|||
mesh.addTexCoord(t3); |
|||
} |
|||
|
|||
void TriangleSurface::setTexCoord(int index, ofVec2f t) |
|||
{ |
|||
if ( index > 2 ) { |
|||
ofLog() << "Texture coordinate with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setTexCoord(index, t); |
|||
void TriangleSurface::draw() { |
|||
texture->bind(); |
|||
mesh.draw(); |
|||
texture->unbind(); |
|||
} |
|||
|
|||
void TriangleSurface::moveBy(ofVec2f v) |
|||
{ |
|||
vector<ofVec3f>& vertices = getVertices(); |
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += v; |
|||
} |
|||
void TriangleSurface::setVertex(int index, ofVec2f p) { |
|||
if (index > 2) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setVertex(index, p); |
|||
} |
|||
|
|||
int TriangleSurface::getType() |
|||
{ |
|||
return SurfaceType::TRIANGLE_SURFACE; |
|||
void TriangleSurface::setTexCoord(int index, ofVec2f t) { |
|||
if (index > 2) { |
|||
ofLog() << "Texture coordinate with this index does not exist: " << index |
|||
<< endl; |
|||
return; |
|||
} |
|||
|
|||
mesh.setTexCoord(index, t); |
|||
} |
|||
|
|||
bool TriangleSurface::hitTest(ofVec2f p) |
|||
{ |
|||
// Construct ofPolyline from vertices
|
|||
ofPolyline line = getHitArea(); |
|||
|
|||
if ( line.inside(p.x, p.y) ) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
void TriangleSurface::moveBy(ofVec2f v) { |
|||
vector<ofVec3f>& vertices = getVertices(); |
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
vertices[i] += v; |
|||
} |
|||
} |
|||
|
|||
ofVec2f TriangleSurface::getVertex(int index) |
|||
{ |
|||
if ( index > 2 ) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
throw std::runtime_error("Vertex index out of bounds."); |
|||
} |
|||
|
|||
ofVec3f vert = mesh.getVertex(index); |
|||
return ofVec2f(vert.x, vert.y); |
|||
int TriangleSurface::getType() { return SurfaceType::TRIANGLE_SURFACE; } |
|||
|
|||
bool TriangleSurface::hitTest(ofVec2f p) { |
|||
// Construct ofPolyline from vertices
|
|||
ofPolyline line = getHitArea(); |
|||
|
|||
if (line.inside(p.x, p.y)) { |
|||
return true; |
|||
} else { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
ofVec2f TriangleSurface::getTexCoord(int index) |
|||
{ |
|||
if (index > 2) { |
|||
throw std::runtime_error("Texture coordinate index out of bounds."); |
|||
} |
|||
|
|||
return mesh.getTexCoord(index); |
|||
ofVec2f TriangleSurface::getVertex(int index) { |
|||
if (index > 2) { |
|||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
|||
throw std::runtime_error("Vertex index out of bounds."); |
|||
} |
|||
|
|||
ofVec3f vert = mesh.getVertex(index); |
|||
return ofVec2f(vert.x, vert.y); |
|||
} |
|||
|
|||
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 ) ); |
|||
line.close(); |
|||
|
|||
return line; |
|||
ofVec2f TriangleSurface::getTexCoord(int index) { |
|||
if (index > 2) { |
|||
throw std::runtime_error("Texture coordinate index out of bounds."); |
|||
} |
|||
|
|||
return mesh.getTexCoord(index); |
|||
} |
|||
|
|||
ofPolyline TriangleSurface::getTextureHitArea() |
|||
{ |
|||
ofPolyline line; |
|||
vector<ofVec2f>& texCoords = mesh.getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); |
|||
for ( int i=0; i<texCoords.size(); i++ ) { |
|||
line.addVertex( ofPoint( texCoords[i] * textureSize ) ); |
|||
} |
|||
line.close(); |
|||
|
|||
return line; |
|||
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)); |
|||
line.close(); |
|||
|
|||
return line; |
|||
} |
|||
|
|||
vector<ofVec3f>& TriangleSurface::getVertices() |
|||
{ |
|||
// return only joint vertices
|
|||
return mesh.getVertices(); |
|||
ofPolyline TriangleSurface::getTextureHitArea() { |
|||
ofPolyline line; |
|||
vector<ofVec2f>& texCoords = mesh.getTexCoords(); |
|||
ofVec2f textureSize = ofVec2f(texture->getWidth(), texture->getHeight()); |
|||
for (int i = 0; i < texCoords.size(); i++) { |
|||
line.addVertex(ofPoint(texCoords[i] * textureSize)); |
|||
} |
|||
line.close(); |
|||
|
|||
return line; |
|||
} |
|||
|
|||
vector<ofVec2f>& TriangleSurface::getTexCoords() |
|||
{ |
|||
|
|||
return mesh.getTexCoords(); |
|||
vector<ofVec3f>& TriangleSurface::getVertices() { |
|||
// return only joint vertices
|
|||
return mesh.getVertices(); |
|||
} |
|||
|
|||
}} |
|||
vector<ofVec2f>& TriangleSurface::getTexCoords() { return mesh.getTexCoords(); } |
|||
} |
|||
} |
Loading…
Reference in new issue