Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
%_______________________________________________________________________
%
% screenInfo = openExperiment(monWidth, viewDist, curScreen)
%_______________________________________________________________________
%
% openExperiment initialize screen settings for new experiment
%_______________________________________________________________________
%
% This function opens new screen, sets the random number generator, gets
% the refresh rate, determines the center and ppd, and stops the update
% process. This function is used by both dot code and touch code.
%_______________________________________________________________________
%
% Input
%
% monWidth | viewing width of monitor (cm),
% viewDist | distance from the center of the subject's eyes
% to the monitor(cm)
% curScreen | screen number for experiment, by default 0.
%_______________________________________________________________________
%
% Output
%
% screenInfo | canvas configuration (struct)
%_______________________________________________________________________
%
% (c) 2006 MKMK
% (c) 2013 Jian Wang
%_______________________________________________________________________
%
function screenInfo = openExperiment(monWidth, viewDist, curScreen)
%monWidth=38;
%viewDist=50;
%curScreen=1;
if nargin < 3
curScreen = 0;
end
AssertOpenGL;
rseed = sum(100*clock); % Seed random number generator
rng(rseed,'v5uniform'); % v5 random generator
%rng(rseed,'twister'); % new default generator
screenInfo = struct('rseed',rseed);
% Open screen, make stuff behave itself in OS X with multiple monitors
Screen('Preference', 'VisualDebugLevel',2);
% Set the background color to the default background value - black
screenInfo.bckgnd = 0;
[screenInfo.curWindow, screenInfo.screenRect] = Screen('OpenWindow',curScreen,...
screenInfo.bckgnd,[],32,2);
% 0 for clear drawing, 1 for incremental drawing (does not clear buffer after flip)
screenInfo.dontclear = 0;
% Get the refresh rate of the screen
screenInfo.frameDur = Screen('GetFlipInterval',screenInfo.curWindow);
screenInfo.monRefresh = 1 / screenInfo.frameDur;
% Get screen center coordinates (pixels)
screenInfo.center = [screenInfo.screenRect(3), screenInfo.screenRect(4)]/2;
% Determine pixels per degree (ppd), which unit is derived as
% (pix/screen) * (screen/rad) * (rad/deg) = (pixels per degree)
screenInfo.ppd = pi * screenInfo.screenRect(3) / atan(monWidth/viewDist/2) / 360;
%HideCursor;
% If reward system is hooked up, rewardOn = 1, otherwise rewardOn = 0;
screenInfo.rewardOn = 0;
%screenInfo.rewardOn = 1;
% Get reward system ready
%screenInfo.daq = DaqDeviceIndex;