Browse Source

Add first non-crashing `hitTest` and `getHitArea` to `GridWarpSurface`

master
Krisjanis Rijnieks 9 years ago
parent
commit
3e34e40a51
  1. 74
      src/Surfaces/GridWarpSurface.cpp

74
src/Surfaces/GridWarpSurface.cpp

@ -42,31 +42,63 @@ int GridWarpSurface::getType(){
} }
bool GridWarpSurface::hitTest(ofVec2f p){ bool GridWarpSurface::hitTest(ofVec2f p){
return false; ofPolyline pl;
/* int vertsPerCol = _gridRows + 1;
ofPolyline line = getHitArea(); int vertsPerRow = _gridCols + 1;
if(line.inside(p.x, p.y)){ for(int iy = 0; iy < _gridRows; ++iy){
return true; for(int ix = 0; ix < _gridCols; ++ix){
}else{ int a = (iy * vertsPerRow) + ix;
return false; int b = (iy * vertsPerRow) + ix + 1;
int c = ((iy + 1) * vertsPerRow) + ix + 1;
int d = ((iy + 1) * vertsPerRow) + ix;
pl.clear();
pl.addVertex(mesh.getVertex(a));
pl.addVertex(mesh.getVertex(b));
pl.addVertex(mesh.getVertex(c));
pl.addVertex(mesh.getVertex(d));
pl.close();
if(pl.inside(p)){
return true;
}
}
} }
*/
return false;
} }
ofPolyline GridWarpSurface::getHitArea(){ ofPolyline GridWarpSurface::getHitArea(){
ofPolyline line; ofPolyline pl;
return line; int vertsPerCol = _gridRows + 1;
/* int vertsPerRow = _gridCols + 1;
ofPolyline line;
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); // Get the top border
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); for(int ix = 0; ix <= _gridCols; ++ix){
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); pl.addVertex(mesh.getVertex(ix));
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y)); }
line.close();
// Get right border from top down
return line; for(int iy = 1; iy <= _gridRows; ++iy){
*/ int i = iy * vertsPerRow + vertsPerRow - 1;
pl.addVertex(mesh.getVertex(i));
}
// Get bottom border from right to left
for(int ix = _gridCols; ix >= 0; --ix){
int i = _gridRows * vertsPerRow + vertsPerRow - 2;
pl.addVertex(mesh.getVertex(i));
}
// Get left border from bottom to top
for(int iy = _gridRows; iy > 0; --iy){
int i = iy * vertsPerRow;
pl.addVertex(mesh.getVertex(i));
}
pl.close();
return pl;
} }
ofPolyline GridWarpSurface::getTextureHitArea(){ ofPolyline GridWarpSurface::getTextureHitArea(){

Loading…
Cancel
Save