function [touchFlag,x,y] = detectTouch_opti(touch_plane_info,distToTouch,data)

%always needs a screen
%defaultCoord will function as a place on the screen you DO NOT expect
%participants to touch.
%tolerance will be pixel distance (in x or y) around defaultCoord that 
%WILL NOT result in touch detected

%CHECK THAT SETMOUSE DOES NOT SCALE FOR MULTI-MONITOR!!!!

% if nargin == 1
%     window = varargin{1};
%     defaultCoord = [0 0];
%     tolerance = 10;
% elseif nargin == 2
%     window = varargin{1};
%     defaultCoord = varargin{2};
%     tolerance = 10;
% else
%     window = varargin{1};
%     defaultCoord = varargin{2};
%     tolerance = varargin{3};
% end

curLocation = [data.OtherMarkers(1).x data.OtherMarkers(1).z data.OtherMarkers(1).y];
curLocation=transform4(touch_plane_info.T_opto_plane, curLocation);

mmPerPixel = touch_plane_info.mmPerPixel/1000;
x = double(round(curLocation(1)/mmPerPixel));
y = max(touch_plane_info.pixel_rect(:,2))-double(round(curLocation(2)/mmPerPixel)); %assumes reaches from bottom of screen

touchFlag = 0;
if x > 0 & x < max(touch_plane_info.pixel_rect(:,1)) & y > 0 & y < max(touch_plane_info.pixel_rect(:,2)) & curLocation(3) > distToTouch %if you are in the x/y pixel space and the correct distance away
    touchFlag = 1;
end



