//---------------------------------------------------- bool guiQuad::selectPoint(float x, float y, float offsetX, float offsetY, float width, float height, float hitArea){ //make sure selected is -1 unless we really find a point selected = -1; if(width == 0 || height == 0 || x < offsetX || x > offsetX + width || y < offsetY || y > offsetY + height){ //then we are out of our possible quad area //so we ignore :) return false; } //lets get it in range x(0 - width) y(0 - height) float px = x - offsetX; float py = y - offsetY; //now get in 0-1 range px /= width; py /= height; hitArea /= width; //we want to store the smallest distance found //because in the case when two points are in the //hit area we want to pick the closet float storeDist = 9999999.0; for(int i = 0; i < 4; i++){ float dx = floatAbs(px - srcZeroToOne[i].x); float dy = floatAbs(py - srcZeroToOne[i].y); float dist = sqrt(dx*dx + dy*dy); if(dist > hitArea)continue; if(dist < storeDist){ selected = i; storeDist = dist; } } if(selected != -1){ srcZeroToOne[selected].x = px; srcZeroToOne[selected].y = py; srcScaled[selected].x = px; srcScaled[selected].y = py; if(selected == 0)setCommonText("status: Quad - Top Left"); else if(selected == 1)setCommonText("status: Quad - Top Right"); else if(selected == 2)setCommonText("status: Quad - Bottom Right"); else if(selected == 3)setCommonText("status: Quad - Bottom Left"); return true; } return false; }
//----------------------------------------------------- bool guiQuad::selectPoint(float x, float y, float offsetX, float offsetY, float width, float height, float hitArea){ //make sure selected is -1 unless we really find a point selected = -1; if(width == 0 || height == 0 || x < offsetX || x > offsetX + width || y < offsetY || y > offsetY + height){ //then we are out of our possible quad area //so we ignore :) return false; } //lets get it in range x(0 - width) y(0 - height) float px = x - offsetX; float py = y - offsetY; //now get in 0-1 range px /= width; py /= height; hitArea /= width; //we want to store the smallest distance found //because in the case when two points are in the //hit area we want to pick the closet float storeDist = 9999999.0; for(int i = 0; i < 4; i++){ float dx = fabs(px - srcZeroToOne[i].x); float dy = fabs(py - srcZeroToOne[i].y); float dist = sqrt(dx*dx + dy*dy); if(dist > hitArea)continue; if(dist < storeDist){ selected = i; storeDist = dist; } } if(selected != -1){ getScaledQuadPoints(width, height); if ((srcScaled[selected].x - srcScaled[oppVertex(selected)].x) != 0) { diag_a = (srcScaled[selected].y - srcScaled[oppVertex(selected)].y) / (srcScaled[selected].x - srcScaled[oppVertex(selected)].x); diag_b = srcScaled[selected].y - (diag_a * srcScaled[selected].x); diag_v = false; } else { diag_v = true; } // side A if (srcScaled[0].x - srcScaled[1].x != 0) { sideA_m = (srcScaled[0].y - srcScaled[1].y) / (srcScaled[0].x - srcScaled[1].x); cout << "sideA_m = " << sideA_m << endl; sideA_b = srcScaled[0].y - (sideA_m * srcScaled[0].x); cout << "sideA_b = " << sideA_b << endl; sideA_v = -1; } else { sideA_m = 0; sideA_b = 0; sideA_v = srcScaled[0].x; cout << "sideA is vertical" << endl; cout << "sideA_v = " << sideA_v << endl; } // side B if (srcScaled[1].x - srcScaled[2].x != 0) { sideB_m = (srcScaled[1].y - srcScaled[2].y) / (srcScaled[1].x - srcScaled[2].x); cout << "sideB_m = " << sideB_m << endl; sideB_b = srcScaled[1].y - (sideB_m * srcScaled[1].x); cout << "sideB_b = " << sideB_b << endl; sideB_v = -1; } else { sideB_m = 0; sideB_b = 0; sideB_v = srcScaled[1].x; cout << "sideB is vertical" << endl; cout << "sideB_v = " << sideB_v << endl; } // side C if (srcScaled[2].x - srcScaled[3].x != 0) { sideC_m = (srcScaled[2].y - srcScaled[3].y) / (srcScaled[2].x - srcScaled[3].x); cout << "sideC_m = " << sideC_m << endl; sideC_b = srcScaled[2].y - (sideC_m * srcScaled[2].x); cout << "sideC_b = " << sideC_b << endl; sideC_v = -1; } else { sideC_m = 0; sideC_b = 0; sideC_v = srcScaled[2].x; cout << "sideC is vertical" << endl; cout << "sideC_v = " << sideC_v << endl; } // side D if (srcScaled[3].x - srcScaled[0].x != 0) { sideD_m = (srcScaled[3].y - srcScaled[0].y) / (srcScaled[3].x - srcScaled[0].x); cout << "srcScaled[3].x = " << srcScaled[3].x << endl; cout << "srcScaled[3].y = " << srcScaled[3].y << endl; cout << "srcScaled[0].x = " << srcScaled[0].x << endl; cout << "srcScaled[0].y = " << srcScaled[0].y << endl; cout << "sideD_m = " << sideD_m << endl; sideD_b = srcScaled[3].y - (sideD_m * srcScaled[3].x); cout << "sideD_b = " << sideD_b << endl; sideD_v = -1; } else { sideD_m = 0; sideD_b = 0; sideD_v = srcScaled[3].x; cout << "sideD is vertical" << endl; cout << "sideD_v = " << sideD_v << endl; } srcZeroToOne[selected].x = px; srcZeroToOne[selected].y = py; srcZeroToOne[selected].x = px; srcZeroToOne[selected].y = py; srcScaled[selected].x = px; srcScaled[selected].y = py; if(selected == 0)setCommonText("status: Quad - Top Left"); else if(selected == 1)setCommonText("status: Quad - Top Right"); else if(selected == 2)setCommonText("status: Quad - Bottom Right"); else if(selected == 3)setCommonText("status: Quad - Bottom Left"); return true; } return false; }