Browse Source

Add posibility to move surfaces again

master
Krisjanis Rijnieks 11 years ago
parent
commit
4d813b38a3
  1. 8
      src/ofxProjectionEditor.cpp
  2. 1
      src/ofxProjectionEditor.h
  3. 43
      src/ofxSurfaceManagerGui.cpp
  4. 6
      src/ofxSurfaceManagerGui.h

8
src/ofxProjectionEditor.cpp

@ -51,6 +51,14 @@ void ofxProjectionEditor::createJoints()
}
}
void ofxProjectionEditor::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);
}
}
bool ofxProjectionEditor::hitTestJoints(ofVec2f pos)
{
for ( int i=0; i<joints.size(); i++ ) {

1
src/ofxProjectionEditor.h

@ -14,6 +14,7 @@ public:
void setSurfaceManager(ofxSurfaceManager* newSurfaceManager);
void clearJoints();
void createJoints();
void updateJoints();
bool hitTestJoints(ofVec2f pos);
private:

43
src/ofxSurfaceManagerGui.cpp

@ -4,6 +4,7 @@ ofxSurfaceManagerGui::ofxSurfaceManagerGui()
{
surfaceManager = NULL;
guiMode = ofxGuiMode::NONE;
bDrag = false;
registerMouseEvents();
}
@ -16,11 +17,15 @@ ofxSurfaceManagerGui::~ofxSurfaceManagerGui()
void ofxSurfaceManagerGui::registerMouseEvents()
{
ofAddListener(ofEvents().mousePressed, this, &ofxSurfaceManagerGui::mousePressed);
ofAddListener(ofEvents().mouseReleased, this, &ofxSurfaceManagerGui::mouseReleased);
ofAddListener(ofEvents().mouseDragged, this, &ofxSurfaceManagerGui::mouseDragged);
}
void ofxSurfaceManagerGui::unregisterMouseEvents()
{
ofRemoveListener(ofEvents().mousePressed, this, &ofxSurfaceManagerGui::mousePressed);
ofRemoveListener(ofEvents().mouseReleased, this, &ofxSurfaceManagerGui::mouseReleased);
ofRemoveListener(ofEvents().mouseDragged, this, &ofxSurfaceManagerGui::mouseDragged);
}
void ofxSurfaceManagerGui::draw()
@ -67,7 +72,7 @@ void ofxSurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
if ( guiMode == ofxGuiMode::NONE ) {
return;
} else if ( guiMode == ofxGuiMode::TEXTURE_MAPPING ) {
return;
} else if ( guiMode == ofxGuiMode::PROJECTION_MAPPING ) {
// attempt to select surface, loop from end to beginning
bool bSurfaceSelected = false;
@ -81,9 +86,13 @@ void ofxSurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
}
}
// Check if hitting one of the joints as that also couts as hit when surface is selected
// Check if hitting one of the joints as that also counts as hit when surface is selected
if ( projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)) ) {
bSurfaceSelected = true;
} else if ( bSurfaceSelected ) {
// if not hitting the joints, start drag only if we have a selected surface
clickPosition = ofVec2f(args.x, args.y);
startDrag();
}
if ( !bSurfaceSelected ) {
@ -94,6 +103,26 @@ void ofxSurfaceManagerGui::mousePressed(ofMouseEventArgs &args)
}
}
void ofxSurfaceManagerGui::mouseReleased(ofMouseEventArgs &args)
{
stopDrag();
}
void ofxSurfaceManagerGui::mouseDragged(ofMouseEventArgs &args)
{
if (bDrag) {
ofVec2f mousePosition = ofVec2f(args.x, args.y);
ofVec2f distance = mousePosition - clickPosition;
// add this distance to all vertices in surface
vector<ofVec3f>& vertices = surfaceManager->getSelectedSurface()->getVertices();
for ( int i=0; i<vertices.size(); i++ ) {
vertices[i] += distance;
}
projectionEditor.updateJoints();
clickPosition = mousePosition;
}
}
void ofxSurfaceManagerGui::setSurfaceManager(ofxSurfaceManager* newSurfaceManager)
{
surfaceManager = newSurfaceManager;
@ -122,4 +151,14 @@ void ofxSurfaceManagerGui::drawSelectedSurfaceHighlight()
ofSetColor(255, 255, 255, 255);
line.draw();
ofPopStyle();
}
void ofxSurfaceManagerGui::startDrag()
{
bDrag = true;
}
void ofxSurfaceManagerGui::stopDrag()
{
bDrag = false;
}

6
src/ofxSurfaceManagerGui.h

@ -18,15 +18,21 @@ public:
void draw();
void mousePressed(ofMouseEventArgs& args);
void mouseReleased(ofMouseEventArgs& args);
void mouseDragged(ofMouseEventArgs& args);
void setSurfaceManager(ofxSurfaceManager* newSurfaceManager);
void setMode(int newGuiMode);
void drawSelectedSurfaceHighlight();
void startDrag();
void stopDrag();
private:
ofxSurfaceManager* surfaceManager;
ofxTextureEditor textureEditor;
ofxProjectionEditor projectionEditor;
int guiMode;
bool bDrag;
ofVec2f clickPosition;
};
#endif
Loading…
Cancel
Save