Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- InitializeMatlabOpenGL;
- dots.nDots = 100; % number of dots
- dots.color = [255,255,255]; % color of the dots
- dots.size = 10; % size of dots (pixels)
- dots.center = [0,0,0]; % center of the field of dots (x,y,z)
- dots.apertureSize = [12,12,60]; % size of rectangular aperture [w,h,depth] in degrees*
- dots.x = (rand(1,dots.nDots))*dots.apertureSize(1) + dots.center(1); %'rand(dots.nDots,1)' generates a vector dots.nDots long of random numbers between 0 and 1.
- dots.y = (rand(1,dots.nDots))*dots.apertureSize(2) + dots.center(2); % To change that range to fit the aperture we multiply them by the aperture size, and add the center offset.
- dots.z = (rand(1,dots.nDots))*dots.apertureSize(3) + dots.center(3);
- tmp = Screen('Resolution',0); % (1) Screen's 'Resolution' function determine the screen resolution.
- display.resolution = [tmp.width,tmp.height];
- display.width = 30; % (2) Width of the screen in cm (with a ruler).
- display.dist = 50; % (3) Distance of the screen from the observer in cm.
- % This generates pixel positions, but they're centered at [0,0], which is the top left corner
- pixpos.x = angle2pix(display,dots.x); % Convert the x position of the dots from visual angle to pixel.
- pixpos.y = angle2pix(display,dots.y); % Convert the y position of the dots from visual angle to pixel.
- pixpos.z = angle2pix(display,dots.z); % Convert the z position of the dots from visual angle to pixel.
- dots.speed = 3; %degrees/second
- dots.duration = 5; %seconds
- dots.theta_deg = 30; %degrees
- dots.phi_deg = 100; %degrees
- dots.theta_rad = dots.theta_deg * pi /180; % direction converted to radians
- dots.phi_rad = dots.phi_deg * pi /180; % direction converted to radians
- dx = dots.speed* sin(-dots.phi_rad-dots.theta_rad)/display.frameRate;
- dy = -dots.speed* cos(dots.phi_rad + dots.theta_rad)/display.frameRate;
- dz = -dots.speed*cos(dots.theta_rad)/display.frameRate;
- nFrames = secs2frames(display,dots.duration);
- l = dots.center(1)-dots.apertureSize(1)/2;
- r = dots.center(1)+dots.apertureSize(1)/2;
- b = dots.center(2)-dots.apertureSize(2)/2;
- t = dots.center(2)+dots.apertureSize(2)/2;
- d_forward = dots.center(3)- dots.apertureSize(3)/2;
- d_backward = dots.center(3)+ dots.apertureSize(3)/2;
- dots.x = (rand(1,dots.nDots))*dots.apertureSize(1) + dots.center(1);
- dots.y = (rand(1,dots.nDots))*dots.apertureSize(2) + dots.center(2);
- dots.z = (rand(1,dots.nDots))*dots.apertureSize(3) + dots.center(3);
- try
- for i=1:nFrames
- %convert from degrees to screen pixels
- pixpos.x = angle2pix(display,dots.x)+ display.resolution(1)/2;
- pixpos.y = angle2pix(display,dots.y)+ display.resolution(2)/2;
- pixpos.z = angle2pix(display,dots.z)+ 150;
- % Screen('DrawDots',display.windowPtr,[pixpos.x;pixpos.y], dots.size, dots.color,[0,0],1);
- % Screen('DrawDots',display.windowPtr,[pixpos.x;pixpos.z], dots.size, dots.color,[0,0],1);
- moglDrawDots3D(display.windowPtr, [pixpos.x;pixpos.y;pixpos.z],dots.size, dots.color, dots.center);
- %update the dot position
- dots.x = dots.x + dx;
- dots.y = dots.y + dy;
- dots.z = dots.z + dz;
- %move the dots that are outside the aperture back one aperture
- %width.
- dots.x(dots.x<l) = dots.x(dots.x<l) + dots.apertureSize(1);
- dots.x(dots.x>r) = dots.x(dots.x>r) - dots.apertureSize(1);
- dots.y(dots.y<b) = dots.y(dots.y<b) + dots.apertureSize(2);
- dots.y(dots.y>t) = dots.y(dots.y>t) - dots.apertureSize(2);
- dots.z(dots.z<d_forward) = dots.z(dots.z<d_forward) + dots.apertureSize(3);
- dots.z(dots.z>d_backward) = dots.z(dots.z>d_backward) -dots.apertureSize(3);
- Screen('Flip',display.windowPtr);
- end
- catch ME
- Screen('CloseAll');
- rethrow(ME)
- end
- Screen('CloseAll');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement