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; ofPolyline line;
vector <ofVec2f> & texCoords = mesh.getTexCoords(); vector <ofVec2f> & texCoords = mesh.getTexCoords();
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); 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(); line.close();
return line; return line;

6
src/UserInterface/TextureEditor.cpp

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

Loading…
Cancel
Save