void ttRopeBasic::update(ofPoint AccFrc,ofPoint StartPos){ accFrc = AccFrc; startPos = StartPos; endPos = StartPos; if(num_char == 0){ if (accFrc.y<-0.15){ endPos.y += ofMap(accFrc.y, -0.15, -0.6, 0, 1024-endPos.y, true); length = StartPos.distance(endPos); bFixedMove = true; }else{ endPos.y = StartPos.y; length = StartPos.distance(endPos); bFixedMove = false; } } if (num_char == 1) { if (accFrc.y>0.15) { endPos.y -= ofMap(accFrc.y, 0.15, 0.6, 0, endPos.y,true); length = StartPos.distance(endPos); bFixedMove = true; }else{ endPos.y = StartPos.y; length = StartPos.distance(endPos); bFixedMove = false; } } getPos = startPos; getLength = length; }
//-------- void ofApp::getLineEndPoints(ofxCvBlob blob, ofPoint &start, ofPoint &end) { start = blob.pts[0]; end = blob.pts[1]; float maxDist = start.distance(end); for(int i=0; i < blob.nPts; i++){ if(blob.pts[i].distance(start) > maxDist) { end = blob.pts[i]; maxDist = start.distance(end); } } }
void mousePressed(int x, int y, int button) { x /= globalScale; y /= globalScale; canvas.mousePressed(x, y, button); side.mousePressed(x, y, button); // cout << btnHelpPos.distance(ofPoint(x,y)) << endl; if (btnHelpPos.distance(ofPoint(x,y))<btnHelp.width/2) showHelp(); if (btnNew.hitTest(x,y)) { files.cur=-1; canvas.clear(); files.unloadFile(); } if (btnSave.hitTest(x,y)) files.save(); if (btnLoadPrevious.hitTest(x,y)) files.loadPrevious(); if (btnLoadNext.hitTest(x,y)) files.loadNext(); if (btnPrint.hitTest(x,y)) print(); if (btnStop.hitTest(x,y)) stop(); if (btnOops.hitTest(x,y)) { btnOops.selected=true; } if (btnZoomIn.hitTest(x,y)) btnZoomIn.selected=true; if (btnZoomOut.hitTest(x,y)) btnZoomOut.selected=true; if (btnHigher.hitTest(x,y)) btnHigher.selected=true; if (btnLower.hitTest(x,y)) btnLower.selected=true; if (btnTwistLeft.hitTest(x,y)) btnTwistLeft.selected=true; if (btnTwistRight.hitTest(x,y)) btnTwistRight.selected=true; if (shapeButtons.inside(x,y)) { int index = ofNormalize(x,shapeButtons.x,shapeButtons.x+shapeButtons.width) * shapeString.size(); side.setShape(shapeString.at(index)); } }
ofPoint SuperGlyph::getGetClosePath(ofPoint _pos){ ofPoint normal; ofPoint target; float minDist = 1000000; for (int i = 0; i < insidePath.getVertices().size()-1; i++) { ofPoint a = insidePath.getVertices()[i]; ofPoint b = insidePath.getVertices()[i+1]; ofPoint normalPoint = getNormalPoint(_pos, a, b); if (normalPoint.x < a.x || normalPoint.x > b.x) { normalPoint = b; } float distance = _pos.distance(normalPoint); if (distance < minDist) { minDist = distance; normal = normalPoint; ofPoint dir = b - a; dir.normalize(); dir *= 10; target = normalPoint; target += dir; } } return target; }
void Communitas::addParticle(ofPoint _pos, int _n) { if ( universe.inside( _pos ) ){ timer = 0; int nLnk = 0; for (int i = pAct.size()-1; i >= 0 ; i--){ if (nLnk == 0) if (pAct[i]->idN == _n) nLnk = i; if ( _pos.distance(pAct[i]->loc) <= 40) pAct[i]->alpha = 255; } LineDot * dot = new LineDot(_n, &universe, _pos ,false); if ( nLnk > 0) dot->setLnk(pAct[nLnk]); pAct.push_back(dot); } }
bool ofxDraggableNode::isInside(ofPoint p) const { ofPoint screenCenter = cam->worldToScreen(this->getGlobalPosition()); ofPoint screenCenterRadius = cam->worldToScreen(this->getGlobalPosition() + cam->getUpDir() * radius); float r = screenCenter.distance(screenCenterRadius); //radius on screen return p.distance(screenCenter) < r; }