Browse Source

Fix non updating surface joint locations after custom surface setup as well as texture and projection area updates

master
Krisjanis Rijnieks 11 years ago
parent
commit
b5c318adf9
  1. 57
      src/ofxSurfaceGui.cpp
  2. 7
      src/ofxSurfaceGui.h
  3. 2
      src/ofxSurfaceManager.cpp

57
src/ofxSurfaceGui.cpp

@ -213,6 +213,45 @@ void ofxSurfaceGui::unselect()
bSelected = false; bSelected = false;
} }
void ofxSurfaceGui::updateTextureHitarea()
{
textureHitarea.clear();
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureHitarea.addVertex( ofPoint(textureMappingJoints[i].position.x,
textureMappingJoints[i].position.y) );
}
}
void ofxSurfaceGui::updateProjectionHitarea()
{
projectionHitarea.clear();
for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionHitarea.addVertex( ofPoint(projectionMappingJoints[i].position.x,
projectionMappingJoints[i].position.y) );
}
}
void ofxSurfaceGui::updateHitarea()
{
updateProjectionHitarea();
updateTextureHitarea();
}
void ofxSurfaceGui::updateJoints()
{
// move joints to their positions
for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].position = surface->getVertex(i);
}
updateProjectionHitarea();
ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), surface->getTexture()->getHeight());
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].position = surface->getTexCoord(i) * textureSize;
}
updateTextureHitarea();
}
bool ofxSurfaceGui::hitTest(float x, float y) bool ofxSurfaceGui::hitTest(float x, float y)
{ {
if (mode == PROJECTION_MAPPING){ if (mode == PROJECTION_MAPPING){
@ -300,24 +339,6 @@ void ofxSurfaceGui::addNumTextureMappingJoints(int num)
} }
} }
void ofxSurfaceGui::updateTextureHitarea()
{
textureHitarea.clear();
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureHitarea.addVertex( ofPoint(textureMappingJoints[i].position.x,
textureMappingJoints[i].position.y) );
}
}
void ofxSurfaceGui::updateProjectionHitarea()
{
projectionHitarea.clear();
for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionHitarea.addVertex( ofPoint(projectionMappingJoints[i].position.x,
projectionMappingJoints[i].position.y) );
}
}
void ofxSurfaceGui::dragTextureArea() void ofxSurfaceGui::dragTextureArea()
{ {
bTextureDragging = true; bTextureDragging = true;

7
src/ofxSurfaceGui.h

@ -26,6 +26,11 @@ public:
void setMode(editMode newMode); void setMode(editMode newMode);
void select(); void select();
void unselect(); void unselect();
void updateTextureHitarea();
void updateProjectionHitarea();
void updateHitarea(); // update both
void updateJoints();
bool hitTest(float x, float y); bool hitTest(float x, float y);
bool hitTestTextureArea(float x, float y); bool hitTestTextureArea(float x, float y);
bool hitTestProjectionArea(float x, float y); bool hitTestProjectionArea(float x, float y);
@ -58,8 +63,6 @@ private:
void addNumProjectionMappingJoints(int num); void addNumProjectionMappingJoints(int num);
void addTextureMappingJoint(); void addTextureMappingJoint();
void addNumTextureMappingJoints(int num); void addNumTextureMappingJoints(int num);
void updateTextureHitarea();
void updateProjectionHitarea();
void dragTextureArea(); void dragTextureArea();
void dragProjectionArea(); void dragProjectionArea();
void stopDrag(); void stopDrag();

2
src/ofxSurfaceManager.cpp

@ -184,10 +184,12 @@ void ofxSurfaceManager::addTriangleSurface(ofVec2f v1, ofVec2f v2, ofVec2f v3, o
{ {
addTriangleSurface(); addTriangleSurface();
triangleSurfaces.back()->setup(v1, v2, v3, t1, t2, t3, triangleSurfaces.back()->getTexture()); triangleSurfaces.back()->setup(v1, v2, v3, t1, t2, t3, triangleSurfaces.back()->getTexture());
surfaceGuis.back()->updateJoints();
} }
void ofxSurfaceManager::addTriangleSurface(ofVec2f v1, ofVec2f v2, ofVec2f v3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr) void ofxSurfaceManager::addTriangleSurface(ofVec2f v1, ofVec2f v2, ofVec2f v3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr)
{ {
addTriangleSurface(); addTriangleSurface();
triangleSurfaces.back()->setup(v1, v2, v3, t1, t2, t3, texturePtr); triangleSurfaces.back()->setup(v1, v2, v3, t1, t2, t3, texturePtr);
surfaceGuis.back()->updateJoints();
} }
Loading…
Cancel
Save