# Gaze Dependent Display

**URL:** <https://psychtoolbox.discourse.group/t/gaze-dependent-display/2007>\
**Category:** Uncategorized\
**Created:** [September 19, 2008, 2:26pm UTC](https://psychtoolbox.discourse.group/t/gaze-dependent-display/2007 "2008-09-19T14:26:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.hegenloh](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@michael.hegenloh](https://psychtoolbox.discourse.group/u/michael.hegenloh)\
**Post date:** [September 19, 2008, 2:26pm UTC](https://psychtoolbox.discourse.group/t/gaze-dependent-display/2007/1 "2008-09-19T14:26:24Z")

</div>

Hello,  
  
I have a question concerning a Matlab code for a gaze dependent  
display. I adapted some code which was in the forum, but mine does not  
seem to work properly. The display just switches to another screen  
after sometime. I pasted the code beneath. Could anyone help me with  
this!   
Thanks a lot.  
  
Michael  
  
function breaktrial = gazedependentdisplay(calltime, begintime,  
endtime, xpos, ypos, reqFixTime, maxFCDur, fixTolerance)  
  
global VSGET\_eye\_used;  
global VSGET\_ts;  
global VSGET\_mx;  
global VSGET\_my;  
  
breaktrial = 0;  
  
% verify fixation stability for a particular amount of time  
% Eyelink('message', 'Check Fixation Start' );  
% disp('Check Fixation Start');  
  
[h]=crsGetScreenHeight();  
fixTolerancePix=round(fixTolerance/100\*h);  
%movThresholdPix=round((par.stimRadius(trial)/100)\*h/2);  
  
tfcEnd=GetSecs+maxFCDur; %max time fixation check may take before we  
enforce driftcorrection  
  
errorp=Eyelink('CheckRecording');  
if(errorp~=0)  
 error('Eyelink CheckRecording returned %d', errorp);  
end  
  
if Eyelink('NewFloatSampleAvailable') \> 0  
 % get the sample in the form of an event structure  
 evt = Eyelink('NewestFloatSample');  
 if VSGET\_eye\_used ~= -1 % do we know which eye to use yet?  
 % if we do, get current gaze position from sample  
 x = evt.gx(VSGET\_eye\_used+1); % +1 as we're accessing MATLAB array  
 y = evt.gy(VSGET\_eye\_used+1);  
 % do we have valid data and is the pupil visible?  
 if x~=el.MISSING\_DATA && y~=el.MISSING\_DATA &&  
evt.pa(VSGET\_eye\_used+1)\>0  
 VSGET\_mx=x;  
 VSGET\_my=y;  
 end  
 end  
end  
  
d=sqrt((VSGET\_mx-xpos)^2+(VSGET\_my-ypos)^2);  
if d\<fixTolerancePix  
 if VSGET\_ts\<0  
 VSGET\_ts=GetSecs;  
 elseif (GetSecs-VSGET\_ts) \> reqFixTime  
 fprintf('fixation point fixated long enough\n');  
 Eyelink('message', 'Check Fixation End' );  
 breaktrial = 1;  
 end  
else  
 VSGET\_ts=-1;  
end  
  
if GetSecs \> tfcEnd  
 Eyelink('message', 'Enforcing driftcorrection: no accurate  
fixation after %f secs', maxFCDur );  
 EyelinkDoDriftCorrection(el);  
end

---

<div class="post-metadata">

**Author:** ![franswcornelissen](https://avatars.discourse-cdn.com/v4/letter/f/df705f/32.png) [@franswcornelissen](https://psychtoolbox.discourse.group/u/franswcornelissen)\
**Post date:** [September 24, 2008, 6:55pm UTC](https://psychtoolbox.discourse.group/t/gaze-dependent-display/2007/2 "2008-09-24T18:55:50Z")

</div>

Michael,  
Did you try out the gaze-dependent display example (and other examples)  
in the eyelinktoolbox directory of the PTB? Does this work okay?  
If so, maybe you can start from there.  
Gr.  
Frans  
  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "michael.hegenloh" \<mhegenloh@...\> wrote:  
> \>  
> \> Hello,  
> \>   
> \> I have a question concerning a Matlab code for a gaze dependent  
> \> display. I adapted some code which was in the forum, but mine does not  
> \> seem to work properly. The display just switches to another screen  
> \> after sometime. I pasted the code beneath. Could anyone help me with  
> \> this!   
> \> Thanks a lot.  
> \>   
> \> Michael  
> \>   
> \> function breaktrial = gazedependentdisplay(calltime, begintime,  
> \> endtime, xpos, ypos, reqFixTime, maxFCDur, fixTolerance)  
> \>   
> \> global VSGET\_eye\_used;  
> \> global VSGET\_ts;  
> \> global VSGET\_mx;  
> \> global VSGET\_my;  
> \>   
> \> breaktrial = 0;  
> \>   
> \> % verify fixation stability for a particular amount of time  
> \> % Eyelink('message', 'Check Fixation Start' );  
> \> % disp('Check Fixation Start');  
> \>   
> \> [h]=crsGetScreenHeight();  
> \> fixTolerancePix=round(fixTolerance/100\*h);  
> \> %movThresholdPix=round((par.stimRadius(trial)/100)\*h/2);  
> \>   
> \> tfcEnd=GetSecs+maxFCDur; %max time fixation check may take before we  
> \> enforce driftcorrection  
> \>   
> \> errorp=Eyelink('CheckRecording');  
> \> if(errorp~=0)  
> \> error('Eyelink CheckRecording returned %d', errorp);  
> \> end  
> \>   
> \> if Eyelink('NewFloatSampleAvailable') \> 0  
> \> % get the sample in the form of an event structure  
> \> evt = Eyelink('NewestFloatSample');  
> \> if VSGET\_eye\_used ~= -1 % do we know which eye to use yet?  
> \> % if we do, get current gaze position from sample  
> \> x = evt.gx(VSGET\_eye\_used+1); % +1 as we're accessing MATLAB array  
> \> y = evt.gy(VSGET\_eye\_used+1);  
> \> % do we have valid data and is the pupil visible?  
> \> if x~=el.MISSING\_DATA && y~=el.MISSING\_DATA &&  
> \> evt.pa(VSGET\_eye\_used+1)\>0  
> \> VSGET\_mx=x;  
> \> VSGET\_my=y;  
> \> end  
> \> end  
> \> end  
> \>   
> \> d=sqrt((VSGET\_mx-xpos)^2+(VSGET\_my-ypos)^2);  
> \> if d\<fixTolerancePix  
> \> if VSGET\_ts\<0  
> \> VSGET\_ts=GetSecs;  
> \> elseif (GetSecs-VSGET\_ts) \> reqFixTime  
> \> fprintf('fixation point fixated long enough\n');  
> \> Eyelink('message', 'Check Fixation End' );  
> \> breaktrial = 1;  
> \> end  
> \> else  
> \> VSGET\_ts=-1;  
> \> end  
> \>   
> \> if GetSecs \> tfcEnd  
> \> Eyelink('message', 'Enforcing driftcorrection: no accurate  
> \> fixation after %f secs', maxFCDur );  
> \> EyelinkDoDriftCorrection(el);  
> \> end  
> \>
