Browse Source

Add projection mappint and texture mapping working code to the surface GUI

master
Krisjanis Rijnieks 11 years ago
parent
commit
7c169203a6
  1. 5
      src/ofxBaseSurface.cpp
  2. 2
      src/ofxBaseSurface.h
  3. 65
      src/ofxSurfaceGui.cpp
  4. 2
      src/ofxSurfaceGui.h

5
src/ofxBaseSurface.cpp

@ -36,4 +36,9 @@ void ofxBaseSurface::createDefaultTexture()
// Assign default texture to texture pointer // Assign default texture to texture pointer
texture = &defaultTexture; texture = &defaultTexture;
}
ofTexture* ofxBaseSurface::getTexture()
{
return texture;
} }

2
src/ofxBaseSurface.h

@ -12,6 +12,8 @@ public:
virtual void setVertex(int index, ofVec2f p){}; virtual void setVertex(int index, ofVec2f p){};
virtual void setTexCoord(int index, ofVec2f t){}; virtual void setTexCoord(int index, ofVec2f t){};
ofTexture* getTexture();
protected: protected:
ofMesh mesh; ofMesh mesh;
ofTexture* texture; ofTexture* texture;

65
src/ofxSurfaceGui.cpp

@ -3,7 +3,7 @@
ofxSurfaceGui::ofxSurfaceGui() ofxSurfaceGui::ofxSurfaceGui()
{ {
surface = NULL; surface = NULL;
mode = PROJECTION_MAPPING; mode = TEXTURE_MAPPING;
} }
ofxSurfaceGui::~ofxSurfaceGui() ofxSurfaceGui::~ofxSurfaceGui()
@ -23,8 +23,14 @@ void ofxSurfaceGui::update()
if (surface == NULL) return; if (surface == NULL) return;
if (mode == NONE) return; if (mode == NONE) return;
for ( int i=0; i<projectionMappingJoints.size(); i++ ) { if (mode == PROJECTION_MAPPING) {
projectionMappingJoints[i].update(); for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].update();
}
} else if (mode == TEXTURE_MAPPING) {
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].update();
}
} }
} }
@ -33,8 +39,14 @@ void ofxSurfaceGui::draw()
if (surface == NULL) return; if (surface == NULL) return;
if (mode == NONE) return; if (mode == NONE) return;
for ( int i=0; i<projectionMappingJoints.size(); i++ ) { if (mode == PROJECTION_MAPPING) {
projectionMappingJoints[i].draw(); for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].draw();
}
} else if (mode == TEXTURE_MAPPING) {
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].draw();
}
} }
} }
@ -43,8 +55,14 @@ void ofxSurfaceGui::mousePressed(int x, int y, int button)
if (surface == NULL) return; if (surface == NULL) return;
if (mode == NONE) return; if (mode == NONE) return;
for ( int i=0; i<projectionMappingJoints.size(); i++ ) { if (mode == PROJECTION_MAPPING) {
projectionMappingJoints[i].mousePressed(x, y, button); for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].mousePressed(x, y, button);
}
} else if (mode == TEXTURE_MAPPING) {
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].mousePressed(x, y, button);
}
} }
} }
@ -53,8 +71,14 @@ void ofxSurfaceGui::mouseReleased(int x, int y, int button)
if (surface == NULL) return; if (surface == NULL) return;
if (mode == NONE) return; if (mode == NONE) return;
for ( int i=0; i<projectionMappingJoints.size(); i++ ) { if (mode == PROJECTION_MAPPING) {
projectionMappingJoints[i].mouseReleased(x, y, button); for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
projectionMappingJoints[i].mouseReleased(x, y, button);
}
} else if (mode == TEXTURE_MAPPING) {
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].mouseReleased(x, y, button);
}
} }
} }
@ -63,10 +87,20 @@ void ofxSurfaceGui::mouseDragged(int x, int y, int button)
if (surface == NULL) return; if (surface == NULL) return;
if (mode == NONE) return; if (mode == NONE) return;
for ( int i=0; i<projectionMappingJoints.size(); i++ ) { if (mode == PROJECTION_MAPPING) {
projectionMappingJoints[i].mouseDragged(x, y, button); for ( int i=0; i<projectionMappingJoints.size(); i++ ) {
if ( projectionMappingJoints[i].isDragged() ) { projectionMappingJoints[i].mouseDragged(x, y, button);
surface->setVertex(i, projectionMappingJoints[i].position); if ( projectionMappingJoints[i].isDragged() ) {
surface->setVertex(i, projectionMappingJoints[i].position);
}
}
} else if (mode == TEXTURE_MAPPING) {
ofVec2f textureSize = ofVec2f( surface->getTexture()->getWidth(), surface->getTexture()->getHeight() );
for ( int i=0; i<textureMappingJoints.size(); i++ ) {
textureMappingJoints[i].mouseDragged(x, y, button);
if ( textureMappingJoints[i].isDragged() ) {
surface->setTexCoord(i, textureMappingJoints[i].position/textureSize);
}
} }
} }
} }
@ -100,8 +134,9 @@ void ofxSurfaceGui::addNumProjectionMappingJoints(int num)
void ofxSurfaceGui::addTextureMappingJoint() void ofxSurfaceGui::addTextureMappingJoint()
{ {
textureMappingJoings.push_back(ofxCircleJoint()); textureMappingJoints.push_back(ofxCircleJoint());
//textureMappingJoings.back().position = surface->getTex ofVec2f textureSize = ofVec2f(surface->getTexture()->getWidth(), surface->getTexture()->getHeight());
textureMappingJoints.back().position = surface->getTexCoord(textureMappingJoints.size()-1) * textureSize;
} }
void ofxSurfaceGui::addNumTextureMappingJoints(int num) void ofxSurfaceGui::addNumTextureMappingJoints(int num)

2
src/ofxSurfaceGui.h

@ -32,7 +32,7 @@ private:
ofxTriangleSurface* surface; ofxTriangleSurface* surface;
vector<ofxCircleJoint> projectionMappingJoints; vector<ofxCircleJoint> projectionMappingJoints;
vector<ofxCircleJoint> textureMappingJoings; vector<ofxCircleJoint> textureMappingJoints;
void addProjectionMappingJoint(); void addProjectionMappingJoint();
void addNumProjectionMappingJoints(int num); void addNumProjectionMappingJoints(int num);

Loading…
Cancel
Save