JA_Object_Movement.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. function [Ob, Par] = JA_Object_Movement(Par, Ob, arg)
  2. %% trial starts --> ball falls down --> when touches the table_CF it
  3. %% set parameters
  4. player = arg.player;
  5. distanceY = arg.distanceY;
  6. distanceX = arg.distanceX;
  7. % object to be moved
  8. target_object = 'ball';
  9. % create an internal variable and call it tobj
  10. tobj = Ob.(target_object);
  11. % % how long does it takes for the ball to land
  12. if isfield(arg, 'duration')
  13. duration = arg.duration;
  14. else
  15. duration = 0.5;
  16. end
  17. %% transform displacement into pixels
  18. distance_tmp = JA_prop2dim(Par.screen_dimensions, 0, distanceX);
  19. distanceX = distance_tmp(2);
  20. clear distance_ball_tmp;
  21. distance_tmp = JA_prop2dim(Par.screen_dimensions, 0, distanceY);
  22. distanceY = distance_tmp(2);
  23. clear distance_ball_tmp;
  24. %%
  25. [ifi_af,...
  26. ifi_as,...
  27. ifi_nf,...
  28. ifi_ns] = JA_frames_function(Par.ifi, Par.ifi);
  29. %% trasform in nominal and actual frames
  30. [ball_tw_actual_frames,...
  31. ball_tw_actual_seconds,...
  32. ball_tw_nominal_frames,...
  33. ball_tw_nominal_seconds] = JA_frames_function(duration, Par.ifi);
  34. %% set the step
  35. step_vert = distanceY/ball_tw_nominal_frames;
  36. step_lat = distanceX/ball_tw_nominal_frames;
  37. %% start falling for 'ball_tw_nominal_frames'
  38. for t = 1:ball_tw_nominal_frames
  39. %% increment displacement of the step specified
  40. tmp = tobj.dimension;
  41. tobj.dimension = ([tmp(1)+step_lat,...
  42. tmp(2)+step_vert,...
  43. tmp(3)+step_lat,...
  44. tmp(4)+step_vert]);
  45. tobj.centered_square = [tobj.centered_square(1)+step_lat, tobj.centered_square(2)+step_vert];
  46. % return the tobj value to the Ob, so that it could be
  47. % returned as output.
  48. Ob.(target_object) = tobj;
  49. % display the displacement on the screen (load all the objects in the screen)
  50. [Ob, Par] = JA_Load_Obj_On_Screen(Par, Ob);
  51. [Par.VBL] = Screen(Par.window, 'Flip', Par.VBL+ifi_as);
  52. if (t == 1)
  53. switch player
  54. case 'CF'
  55. Par.VBL_ball_falls_CF{Par.tr} = Par.VBL;
  56. case 'SBJ'
  57. Par.VBL_ball_falls_SBJ{Par.tr} = Par.VBL;
  58. end
  59. end
  60. % if the number of frames has reached the limit
  61. if (t == ball_tw_nominal_frames)
  62. switch player
  63. case 'CF'
  64. Par.VBL_ball_landed_on_table_CF{Par.tr} = Par.VBL;
  65. case 'SBJ'
  66. Par.VBL_ball_landed_on_table_SBJ{Par.tr} = Par.VBL;
  67. end
  68. end
  69. end
  70. end
  71. %[cell2mat(Par.VBL_ball_landed_on_table_CF) - cell2mat(Par.VBL_first_frame)]