Пример #1
0
void menu::interaccion_point(ofVec2f ptF, bool isNeg) {
	float minDis = ofGetHeight()/3.0;// (isNeg)? 400 : 200;
	
	float minDis2 = minDis*minDis;
	
	float ff = 1.0;

	float fFuerza = 45.0;
	if(ptF.distance(centro)<distConf) {
//	if(ptF.squareDistance(centro)<distConf) {
		if(isNeg) {
			// Atrae circulos y repele boxes
			for(int i=0; i<circles.size(); i++) {
//				float dis = ptF.distance(circles[i].get()->getPosition());
				float dis2 = ptF.squareDistance(circles[i].get()->getPosition());
//				if(dis < minDis) 
//				if(dis2 < minDis2) 
//					circles[i].get()->addRepulsionForce(ptF, ff*1.4f*fFuerza/dis2);//3, 9);
//				else 
//					circles[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
				
				circles[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
				
			}
			for(int i=0; i<boxes.size(); i++) {
				float dis = ptF.distance(boxes[i].get()->getPosition());
				float dis2 = dis*dis;//ptF.squareDistance(boxes[i].get()->getPosition());
//				if(dis < minDis) 
//				if(dis2 < minDis2) 
//					boxes[i].get()->addAttractionPoint(ptF, ff*1.2*fFuerza/dis2);
//				else 
//					boxes[i].get()->addRepulsionForce(ptF, ff*0.8*fFuerza/dis2);//4.0);
				boxes[i].get()->addRepulsionForce(ptF, ff*0.9*fFuerza/dis2);//4.0);
			}
		}
		else {
			// Mouse Pressed
			// Atrae boxes y repele circulos
			for(int i=0; i<circles.size(); i++) {
//				float dis = ptF.distance(circles[i].get()->getPosition());
				float dis2 = ptF.squareDistance(circles[i].get()->getPosition());
//				if(dis < minDis) 
//				if(dis2 < minDis2) 
//					circles[i].get()->addAttractionPoint(ptF, ff*1.2*fFuerza/dis2);//3, 9);
//				else 
					circles[i].get()->addRepulsionForce(ptF, ff*0.8*fFuerza/dis2);//4.0);
			}
			for(int i=0; i<boxes.size(); i++) {
				float dis = ptF.distance(boxes[i].get()->getPosition());
				float dis2 = ptF.squareDistance(boxes[i].get()->getPosition());
//				if(dis < minDis) 
				if(dis2 < minDis2) 
//					boxes[i].get()->addRepulsionForce(ptF, ff*1.4*fFuerza/dis);
//				else 
					boxes[i].get()->addAttractionPoint(ptF, ff*2.2*fFuerza/dis2);//4.0);
			}
		}
	}

}
Пример #2
0
 //-------------------------------------------------------------------
 static float getTriangleRadius(ofVec2f v1, ofVec2f v2, ofVec2f v3) {
     
     float a = v1.distance(v2);
     float b = v2.distance(v3);
     float c = v3.distance(v1);
     
     float k = 0.5 * (a+b+c);
     
     float r = sqrt( k * ((k-a)*(k-b)*(k-c)) ) / k;
     return r;
 }
Пример #3
0
 //-------------------------------------------------------------------
 static ofVec2f getTriangleCenter(ofVec2f v1, ofVec2f v2, ofVec2f v3) {
     
     float a = v2.distance(v3);
     float b = v1.distance(v3);
     float c = v1.distance(v2);
     float d = a+b+c;
     
     float ix = ((a * v1.x) + (b * v2.x) + (c * v3.x)) / d;
     float iy = ((a * v1.y) + (b * v2.y) + (c * v3.y)) / d;
     
     return ofVec2f(ix, iy);
 }
Пример #4
0
int BSpline::GetControlPointAtPosition(ofVec2f position)
{
	for (int i = 0; i < controlPoints.size(); ++i) {
		if (position.distance(controlPoints[i]) < 10)
			return i;
	}
	return -1;
}
Пример #5
0
bool TriangleBrush::checkAngle(ofVec2f p1, ofVec2f p2, ofVec2f p3){
            float dist1 = p1.distance(p2);
            float dist2 = p1.distance(p3);
            if (dist2 < dist1) {
                return true;
            }else{
                return false;
            }
}
Пример #6
0
float getNearestVertex(const ofMesh& mesh, const ofVec2f& target, int& vertexIndex) {
	float bestDistance = 0;
	for(int i = 0; i < mesh.getNumVertices(); i++) {
		float distance = target.distance(mesh.getVertex(i));
		if(distance < bestDistance || i == 0) {
			bestDistance = distance;
			vertexIndex = i;
		}
	}
	return bestDistance;
}
Пример #7
0
vector<ofVec2f> PyramidBrush::sortClosest(ofVec2f p, vector<ofVec2f> coords){
    vector<ofVec2f> pos;
    float maxDist = ofGetWidth();
    int closestIndex = 0;
    for (int i = 0; i < coords.size(); i++) {
        float dist = p.distance(coords[i]);
        if (dist < maxDist){
            maxDist = dist;
            pos.push_back(coords[i]);
        }
    }
    return pos;
}
Пример #8
0
ofVec2f Simple3DTracker::_predictNextPosition(ofVec2f currentPosition, float* minCost)
{
    int bestx = currentPosition.x, besty = currentPosition.y;
    float bestcost = 9999999, cost, distance;
    const float alpha = _weightedMatchingCoefficient;

    if(!_template || !_tmp || !_tmp2)
        return currentPosition;

    // template matching
    IplImage* haystack = _cameraImage();
    cvMatchTemplate(haystack, _template->getCvImage(), _tmp2, CV_TM_CCOEFF);
    cvNormalize(_tmp2, _tmp2, 1.0, 0.0, CV_MINMAX);

    // find the best match
    for(int y = 0; y < _tmp2->height; y++) {
        const float *src = (const float*)(_tmp2->imageData + y * _tmp2->widthStep);
        unsigned char *dst = (unsigned char*)(_tmp->getCvImage()->imageData + y * _tmp->getCvImage()->widthStep);
        for(int x = 0; x < _tmp2->width; x++) {
            dst[x] = (unsigned char)(src[x] * 255.0f);
            distance = currentPosition.distance(ofVec2f(x, y));
            if(distance <= _lookupRadius) {
                cost = (alpha * (1.0f - src[x])) + ((1.0f - alpha) * distance / _lookupRadius);
                if(cost <= bestcost) { // weighted matching
                    bestx = x;
                    besty = y;
                    bestcost = cost;
                }
            }
        }
    }
    _tmp->flagImageChanged();

    // get the resulting position...
    ofVec2f result(bestx + _template->width/2, besty + _template->height/2);

    // return the min cost?
    if(minCost)
        *minCost = bestcost;

    // update the template?
    if(result.distance(currentPosition) >= UPDATETPL_MINDIST)
        _setTemplate(result);

    // done!
    return result;
}
Пример #9
0
dt_dial_ui_mode dt_dial_ui::touch_test( ofVec2f &t ){

	// Hit ?
	if( parent && parent->data.bShowUI ){
		for( int i=0; i< ui_elem_pos.size(); i++ ){
			float dist = t.distance( ui_elem_pos[i] );
			if( dist <= button_radius ){
				// hit!!
				mode = (dt_dial_ui_mode)i;
				return mode;
				break;
			}
		}
	}

	return DT_DIAL_UI_NONE;
}
Пример #10
0
bool select_point(ofVec2f f, ofVec2f t, float r)
{
	if ( f.distance(t) < r ) return true;
	else					 return false;
}
Пример #11
0
bool Sphere::isPointOverCenter(ofVec2f p, float radiusMultiply)
{
    return p.distance(center) < SphereTones::sphereRadius * radiusMultiply;
}
Пример #12
0
//----------------------------------
float PointGroup::getDistanceToCenter(ofVec2f _loc) {
    return (_loc.distance(mCenter));
}
Пример #13
0
bool handle::getIsPointInside(ofVec2f t_mouse) {
    return t_mouse.distance(m_posC) <= m_radius;
}
Пример #14
0
int Neuron::checkClick(ofVec2f mouse) {
    float dist = mouse.distance(loc);
    if (dist < r) return ID;
    else return -1;
}
Пример #15
0
bool TriangleBrush::isDistanceBigger(ofVec2f a, ofVec2f b, float distance){
            return a.distance(b) > distance? true : false;
}
Пример #16
0
//--------------------------------------------------------------
void drawingCanvas::makeLine(ofVec2f mouse){
	int intersect=0;
	vector< ofPoint > points = myPolyline->getVertices();
	int size = points.size();

	if(mouse.distance(lastMouse) > 3){
		//check for intersection first!!
		if(size > 10){
			//check lines on the ofPolyline
			if(drawDummy==false){
				for(int i=0; i< myPolyline->size()-2; i ++){
					//only check if line is close to mouse
					//if((points[i].x > mouse.x-6) && (points[i].x < mouse.x+6)){
					//	if((points[i].y > mouse.y-6) && (points[i].y < mouse.y+6)){
							intersect = intersection(points[i],points[i+1],lastMouse,mouse);
							if(intersect == 2){
								//intersection found
								i = myPolyline->size();//escape for loop
							}
					//	}
					//}
				}
				if(intersect == 0){
					//no intersection
					myPolyline->addVertex(mouse);
					//fix offset of point since they are in in the "middle" of the screen
					//they have to be where the slicing takes place
					myPolyline2->addVertex(ofVec2f(mouse.x-posCanvas.x,mouse.y-posCanvas.y));
					drawDummy = false;
				}else if(intersect == 2){
					//YES intersection
					//draw the segment to the mouse but not saving it into the polyline
					drawDummy = true;
					myDummyLine = new ofPolyline();//////////////////////////////////////////////////////////////remember to dlete this *memory
					myDummyLine->addVertex(points[points.size()-1]);
					myDummyLine->addVertex(mouse);

					//dummyA = points[points.size()-1];
					//dummyB = mouse;
				}
			}else{
				//do comparison wih dummyline, until there is no intersection with dummy line, there is no more adition to the real polyline
				/*intersect = intersection(,lastMouse,mouse);*/
				vector< ofPoint > pointsDummy = myDummyLine->getVertices();
				for(int i=0; i< myPolyline->size()-2; i ++){
					//only check if line is close to mouse
					intersect = intersection(points[i],points[i+1],pointsDummy[0],pointsDummy[1]);
					if(intersect == 2){
						//intersection found
						i = myPolyline->size();//escape for loop
					}
				}
				if(intersect == 2){
					//YES intersection
					//draw the segment to the mouse but not saving it into the polyline
					drawDummy = true;
					myDummyLine->clear();
					myDummyLine->addVertex(points[points.size()-1]);
					myDummyLine->addVertex(mouse);

					//dummyA = points[points.size()-1];
					//dummyB = mouse;

				}else{
					//no intersection
					//return to real polyline
					drawDummy = false;
					myDummyLine->clear();
				}
			}
		}else{
			//not looking for intersection
			myPolyline->addVertex(mouse);
			//fix offset of point since they are in in the "middle" of the screen
			//they have to be where the slicing takes place
			myPolyline2->addVertex(ofVec2f(mouse.x-posCanvas.x,mouse.y-posCanvas.y));
			drawDummy = false;
		}
	}
}