bool MaskFrame::getIntersection(int maskFrameX, int maskFrameY, MaskPoint* maskPoint1, MaskPoint* maskPoint2, MaskPoint* intersection){ ofPoint maskPointLineStart, maskPointLineEnd; maskPointLineStart.x = maskPoint1->getX(); maskPointLineStart.y = maskPoint1->getY(); maskPointLineEnd.x = maskPoint2->getX(); maskPointLineEnd.y = maskPoint2->getY(); ofPoint mouseCursorWithXMarginStart, mouseCursorWithXMarginEnd, xIntersection; mouseCursorWithXMarginStart.x = maskFrameX - round(cursorMargin / 2); mouseCursorWithXMarginStart.y = maskFrameY; mouseCursorWithXMarginEnd.x = mouseCursorWithXMarginStart.x + cursorMargin; mouseCursorWithXMarginEnd.y = maskFrameY; ofPoint mouseCursorWithYMarginStart, mouseCursorWithYMarginEnd, yIntersection; mouseCursorWithYMarginStart.x = maskFrameX; mouseCursorWithYMarginStart.y = maskFrameY - round(cursorMargin / 2); mouseCursorWithYMarginEnd.x = maskFrameX; mouseCursorWithYMarginEnd.y = mouseCursorWithYMarginStart.y + cursorMargin; bool xIntersects = ofLineSegmentIntersection(mouseCursorWithXMarginStart, mouseCursorWithXMarginEnd, maskPointLineStart, maskPointLineEnd, xIntersection); bool yIntersects = ofLineSegmentIntersection(mouseCursorWithYMarginStart, mouseCursorWithYMarginEnd, maskPointLineStart, maskPointLineEnd, yIntersection); if(xIntersects){ intersection->setPosition(xIntersection.x, xIntersection.y); }else if(yIntersects){ intersection->setPosition(yIntersection.x, yIntersection.y); } return xIntersects || yIntersects; }
//---------------------------------------------------------- bool ofRectangle::intersects(const ofPoint& p0, const ofPoint& p1) const { // check for a line intersection ofPoint p; ofPoint topLeft = getTopLeft(); ofPoint topRight = getTopRight(); ofPoint bottomRight = getBottomRight(); ofPoint bottomLeft = getBottomLeft(); return inside(p0) || // check end inside inside(p1) || // check end inside ofLineSegmentIntersection(p0, p1, topLeft, topRight, p) || // cross top ofLineSegmentIntersection(p0, p1, topRight, bottomRight, p) || // cross right ofLineSegmentIntersection(p0, p1, bottomRight, bottomLeft, p) || // cross bottom ofLineSegmentIntersection(p0, p1, bottomLeft, topLeft, p); // cross left }
/*computing the potential particle positions along the specified path for the given microphone position*/ void locCloud::calcParticlePositions(int numBuddies, float buddyDist, float buddyShrink) { ofPoint interSec; ofPoint endDir; float angRes; ofPoint tmpP; ofVec2f tmpV1; ofVec2f tmpV2; bool hit = 0; angRes = 360/numParticles; vector<ofPoint> pathVertices; pathVertices = cloudPath.getVertices(); for (int i=0; i<numParticles; i++) { particles[i].repAngle = i*angRes; endDir.x = micPosition.x + 800*cos(ofDegToRad(i*angRes)); endDir.y = micPosition.y - 800*sin(ofDegToRad(i*angRes)); for (int jj=0; jj<numPathLines; jj++) { hit = ofLineSegmentIntersection(micPosition,endDir,pathVertices[jj],pathVertices[jj+1], interSec); if (hit) { particles[i].pos.x = interSec.x; particles[i].pos.y = interSec.y; particles[i].visible = 1; particles[i].buddyDistance = buddyDist; tmpP = pathVertices[jj] - pathVertices[jj+1]; tmpV1.set(tmpP.x,tmpP.y); tmpV2 = tmpV1.getPerpendicular(); particles[i].buddyNormVec.set(tmpV2.x,tmpV2.y); particles[i].numberOfBuddies = numBuddies; particles[i].buddyShrink = buddyShrink; } } } }