Browse Source

Implement `moveTexCoords` for `GridWarpSurface` textures

master
Krisjanis Rijnieks 9 years ago
parent
commit
feb2f7442b
  1. 16
      src/Surfaces/GridWarpSurface.cpp
  2. 6
      src/UserInterface/TextureEditor.cpp

16
src/Surfaces/GridWarpSurface.cpp

@ -107,9 +107,19 @@ ofPolyline GridWarpSurface::getTextureHitArea(){
ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight());
for(int i = 0; i < texCoords.size(); i++){
line.addVertex(ofPoint(texCoords[i] * textureSize));
}
int vertsPerRow = _gridCols + 1;
int vertsPerCol = _gridRows + 1;
int a = 0;
int b = _gridCols;
int c = (_gridRows * vertsPerRow) + (vertsPerRow - 1);
int d = (_gridRows * vertsPerRow);
line.addVertex(ofPoint(texCoords[a] * textureSize));
line.addVertex(ofPoint(texCoords[b] * textureSize));
line.addVertex(ofPoint(texCoords[c] * textureSize));
line.addVertex(ofPoint(texCoords[d] * textureSize));
line.close();
return line;

6
src/UserInterface/TextureEditor.cpp

@ -242,10 +242,15 @@ void TextureEditor::moveTexCoords(ofVec2f by){
if(surface == 0){
return;
}
vector <ofVec2f> & texCoords = surface->getTexCoords();
ofVec2f textureSize = ofVec2f(surface->getSource()->getTexture()->getWidth(),
surface->getSource()->getTexture()->getHeight());
for(int i = 0; i < joints.size(); i++){
joints[i]->position += by;
}
if(surface->getType() == SurfaceType::GRID_WARP_SURFACE){
GridWarpSurface * s = (GridWarpSurface *)surface;
@ -281,7 +286,6 @@ void TextureEditor::moveTexCoords(ofVec2f by){
}
}else{
for(int i = 0; i < texCoords.size(); i++){
joints[i]->position += by;
surface->setTexCoord(i, joints[i]->position / textureSize);
}
}

Loading…
Cancel
Save