|
|
|
|
|
|
|
|
ofSetColor(color); |
|
|
ofSetColor(color); |
|
|
ofDrawRectangle(webcam.getWidth(), 0, 128, 128); |
|
|
ofDrawRectangle(webcam.getWidth(), 0, 128, 128); |
|
|
if (color_picked == 1 && key_pressed == 0) { |
|
|
if (color_picked == 1 && key_pressed == 0) { |
|
|
SetCursorPos((center.x - x_offset) * x_scale, (center.y - y_offset) * y_scale); |
|
|
|
|
|
|
|
|
scaleTrapeze(); |
|
|
|
|
|
scaleRectangel(); |
|
|
|
|
|
SetCursorPos(cp_cursor_position.x, cp_cursor_position.y); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (calibrated == 4) { |
|
|
if (calibrated == 4) { |
|
|
color = webcam.getPixels().getColor(x, y); |
|
|
color = webcam.getPixels().getColor(x, y); |
|
|
printf("%i, %i, %i\n", color.r, color.g, color.b); |
|
|
printf("%i, %i, %i\n", color.r, color.g, color.b); |
|
|
|
|
|
printf("%f, %f, %f, %f \n", y_offset, y_scale, x_offset, x_scale); |
|
|
color_picked = 1; |
|
|
color_picked = 1; |
|
|
} |
|
|
} |
|
|
if (calibrated != 4) { |
|
|
|
|
|
|
|
|
if (calibrated != 4 && key_pressed == 0) { |
|
|
if (calibrated == 0) { |
|
|
if (calibrated == 0) { |
|
|
GetCursorPos(&cp_top_left); |
|
|
GetCursorPos(&cp_top_left); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (calibrated == 3) { |
|
|
if (calibrated == 3) { |
|
|
GetCursorPos(&cp_bottom_left); |
|
|
GetCursorPos(&cp_bottom_left); |
|
|
y_offset = (cp_top_left.y + cp_top_right.y) / 2.0; |
|
|
|
|
|
|
|
|
|
|
|
y_scale = 1080 / ((cp_bottom_left.y + cp_bottom_right.y) / 2.0); |
|
|
|
|
|
|
|
|
|
|
|
x_offset = (cp_top_left.x + cp_bottom_left.x) / 2.0; |
|
|
x_offset = (cp_top_left.x + cp_bottom_left.x) / 2.0; |
|
|
|
|
|
|
|
|
x_scale = 1920 / ((cp_top_right.x + cp_bottom_right.x) / 2.0); |
|
|
|
|
|
|
|
|
x_scale = ofGetScreenWidth() / (cp_bottom_right.x - x_offset); |
|
|
|
|
|
|
|
|
|
|
|
y_offset = (cp_top_left.y + cp_top_right.y) / 2.0; |
|
|
|
|
|
|
|
|
|
|
|
y_scale = ofGetScreenHeight() / ((cp_bottom_left.y + cp_bottom_right.y) / 2.0 - y_offset); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
calibrated++; |
|
|
calibrated++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ofApp::dragEvent(ofDragInfo dragInfo){ |
|
|
void ofApp::dragEvent(ofDragInfo dragInfo){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ofApp::scaleTrapeze(void) { |
|
|
|
|
|
left_pitch = (cp_top_left.y - cp_bottom_left.y) / (cp_top_left.x - cp_bottom_left.x); |
|
|
|
|
|
right_pitch = (cp_top_right.y - cp_bottom_right.y) / (cp_top_right.x - cp_bottom_right.x); |
|
|
|
|
|
middle = cp_top_right.x - cp_top_left.x; |
|
|
|
|
|
|
|
|
|
|
|
if (center.x > middle) { |
|
|
|
|
|
center.x = center.x + (((center.y - cp_top_right.y) / right_pitch) * ((cp_bottom_right.x - middle) - ((center.y - cp_top_right.y) / right_pitch)) / (center.x - middle)); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
center.x = center.x + (((center.y - cp_top_left.y) / left_pitch) * ((middle - cp_bottom_left.x) - ((center.y - cp_top_left.y) / left_pitch)) / (middle - center.x)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ofApp::scaleRectangel(void) { |
|
|
|
|
|
cp_cursor_position.x = center.x * x_scale - x_offset; |
|
|
|
|
|
cp_cursor_position.y = center.y * y_scale - y_offset; |
|
|
|
|
|
} |