Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. InitializeMatlabOpenGL;
  2.  
  3. dots.nDots = 100; % number of dots
  4. dots.color = [255,255,255]; % color of the dots
  5. dots.size = 10; % size of dots (pixels)
  6. dots.center = [0,0,0]; % center of the field of dots (x,y,z)
  7. dots.apertureSize = [12,12,60]; % size of rectangular aperture [w,h,depth] in degrees*
  8.  
  9. 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.
  10. 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.
  11. dots.z = (rand(1,dots.nDots))*dots.apertureSize(3) + dots.center(3);
  12.  
  13. tmp = Screen('Resolution',0); % (1) Screen's 'Resolution' function determine the screen resolution.
  14. display.resolution = [tmp.width,tmp.height];
  15.  
  16. display.width = 30; % (2) Width of the screen in cm (with a ruler).
  17. display.dist = 50; % (3) Distance of the screen from the observer in cm.
  18.  
  19. % This generates pixel positions, but they're centered at [0,0], which is the top left corner
  20.  
  21. pixpos.x = angle2pix(display,dots.x); % Convert the x position of the dots from visual angle to pixel.
  22. pixpos.y = angle2pix(display,dots.y); % Convert the y position of the dots from visual angle to pixel.
  23. pixpos.z = angle2pix(display,dots.z); % Convert the z position of the dots from visual angle to pixel.
  24.  
  25. dots.speed = 3; %degrees/second
  26. dots.duration = 5; %seconds
  27. dots.theta_deg = 30; %degrees
  28. dots.phi_deg = 100; %degrees
  29. dots.theta_rad = dots.theta_deg * pi /180; % direction converted to radians
  30. dots.phi_rad = dots.phi_deg * pi /180; % direction converted to radians
  31.  
  32. dx = dots.speed* sin(-dots.phi_rad-dots.theta_rad)/display.frameRate;
  33. dy = -dots.speed* cos(dots.phi_rad + dots.theta_rad)/display.frameRate;
  34. dz = -dots.speed*cos(dots.theta_rad)/display.frameRate;
  35.  
  36. nFrames = secs2frames(display,dots.duration);
  37.  
  38. l = dots.center(1)-dots.apertureSize(1)/2;
  39. r = dots.center(1)+dots.apertureSize(1)/2;
  40. b = dots.center(2)-dots.apertureSize(2)/2;
  41. t = dots.center(2)+dots.apertureSize(2)/2;
  42. d_forward = dots.center(3)- dots.apertureSize(3)/2;
  43. d_backward = dots.center(3)+ dots.apertureSize(3)/2;
  44.  
  45. dots.x = (rand(1,dots.nDots))*dots.apertureSize(1) + dots.center(1);
  46. dots.y = (rand(1,dots.nDots))*dots.apertureSize(2) + dots.center(2);
  47. dots.z = (rand(1,dots.nDots))*dots.apertureSize(3) + dots.center(3);
  48.  
  49. try
  50. for i=1:nFrames
  51. %convert from degrees to screen pixels
  52. pixpos.x = angle2pix(display,dots.x)+ display.resolution(1)/2;
  53. pixpos.y = angle2pix(display,dots.y)+ display.resolution(2)/2;
  54. pixpos.z = angle2pix(display,dots.z)+ 150;
  55.  
  56. % Screen('DrawDots',display.windowPtr,[pixpos.x;pixpos.y], dots.size, dots.color,[0,0],1);
  57. % Screen('DrawDots',display.windowPtr,[pixpos.x;pixpos.z], dots.size, dots.color,[0,0],1);
  58.  
  59. moglDrawDots3D(display.windowPtr, [pixpos.x;pixpos.y;pixpos.z],dots.size, dots.color, dots.center);
  60.  
  61.  
  62. %update the dot position
  63. dots.x = dots.x + dx;
  64. dots.y = dots.y + dy;
  65. dots.z = dots.z + dz;
  66.  
  67. %move the dots that are outside the aperture back one aperture
  68. %width.
  69. dots.x(dots.x<l) = dots.x(dots.x<l) + dots.apertureSize(1);
  70. dots.x(dots.x>r) = dots.x(dots.x>r) - dots.apertureSize(1);
  71. dots.y(dots.y<b) = dots.y(dots.y<b) + dots.apertureSize(2);
  72. dots.y(dots.y>t) = dots.y(dots.y>t) - dots.apertureSize(2);
  73. dots.z(dots.z<d_forward) = dots.z(dots.z<d_forward) + dots.apertureSize(3);
  74. dots.z(dots.z>d_backward) = dots.z(dots.z>d_backward) -dots.apertureSize(3);
  75.  
  76. Screen('Flip',display.windowPtr);
  77. end
  78. catch ME
  79. Screen('CloseAll');
  80. rethrow(ME)
  81. end
  82. Screen('CloseAll');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement