Browse Source

Add setTexCoord method to triangle surface to be able to control texture coordinates of each triangle vertex

master
Krisjanis Rijnieks 11 years ago
parent
commit
ee49f3b80f
  1. 7
      example/src/ofApp.cpp
  2. 1
      src/ofxBaseSurface.h
  3. 10
      src/ofxTriangleSurface.cpp
  4. 1
      src/ofxTriangleSurface.h

7
example/src/ofApp.cpp

@ -16,7 +16,12 @@ void ofApp::update()
ofVec2f p;
p.x = ofRandomWidth();
p.y = ofRandomHeight();
triangleSurface.setVertex(0, p);
//triangleSurface.setVertex(0, p);
ofVec2f t;
t.x = ofRandomuf();
t.y = ofRandomuf();
triangleSurface.setTexCoord(0, t);
}
void ofApp::draw()

1
src/ofxBaseSurface.h

@ -10,6 +10,7 @@ public:
virtual void setup(){};
virtual void draw(){};
virtual void setVertex(int index, ofVec2f p){};
virtual void setTexCoord(int index, ofVec2f t){};
protected:
ofMesh mesh;

10
src/ofxTriangleSurface.cpp

@ -60,4 +60,14 @@ void ofxTriangleSurface::setVertex(int index, ofVec2f p)
}
mesh.setVertex(index, p);
}
void ofxTriangleSurface::setTexCoord(int index, ofVec2f t)
{
if ( index > 2 ) {
ofLog() << "Texture coordinate with this index does not exist: " << index << endl;
return;
}
mesh.setTexCoord(index, t);
}

1
src/ofxTriangleSurface.h

@ -14,6 +14,7 @@ public:
void setup( ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2, ofVec2f t3, ofTexture* texturePtr );
void draw();
void setVertex( int index, ofVec2f p );
void setTexCoord( int index, ofVec2f t );
};
#endif
Loading…
Cancel
Save