JA_Initialise_Shapes.m 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. function [Ob, Par] = JA_Initialise_Shapes(Par)
  2. % it produces the initial position of every object on the screen
  3. % every measure is taken as a ratio of the screen_dimensions, so it could be
  4. % easily adapted (thanks to JA_dim2prop and JA_prop2dim)
  5. % get window and screen dimensions
  6. window = Par.window;
  7. screen_dimensions = Par.screen_dimensions;
  8. %% create ball object
  9. % It spits pixel number corresponding to 0.08 of the current x axis and 0 of the Y axis (rounded);
  10. [dimB] = JA_prop2dim(screen_dimensions, 0.08 , 0);
  11. [posB] = JA_prop2dim(screen_dimensions, 0.65, 0.0);
  12. ball = [];
  13. ball.name = 'ball';
  14. ball.type = 'circle';
  15. ball.window = window;
  16. ball.centered_square = [posB(1) posB(2)]; % initial ball position
  17. ball.diameter = dimB(1); % %diameter of the ball
  18. ball.color = [0.5 0.5 0.5]; % grey color
  19. % it centers the ball up and right on the screen
  20. baseRect = [0 0 ball.diameter ball.diameter];
  21. ball.dimension = CenterRectOnPoint(baseRect, ball.centered_square(1),...
  22. ball.centered_square(2));
  23. %% this obj will not be loaded, but it provides distances for piston_CF and table_CF
  24. ball_distance_in_propY = 0.4;
  25. [posB_final_CF] = JA_prop2dim(screen_dimensions, 0.65, ball_distance_in_propY);
  26. ball_final_CF = [];
  27. ball_final_CF.name = 'ball';
  28. ball_final_CF.type = 'circle';
  29. ball_final_CF.window = window;
  30. ball_final_CF.centered_square = [posB_final_CF(1), posB_final_CF(2)];
  31. ball_final_CF.diameter = dimB(1);
  32. ball_final_CF.color = [0.5 0.5 0.5];
  33. baseRect_final_CF = [0 0 ball.diameter ball.diameter];
  34. ball_final_CF.dimension = CenterRectOnPoint(baseRect_final_CF, ball_final_CF.centered_square(1),...
  35. ball_final_CF.centered_square(2));
  36. %% this obj will not be loaded, but it provides distances for piston_SBJ and table_SBJ
  37. posB_final_SBJ(1) = posB_final_CF(1) - posB_final_CF(2);%0.8*(posB_final_CF(1) - posB_final_CF(2));
  38. posB_final_SBJ(2) = posB_final_CF(2);
  39. ball_final_SBJ = [];
  40. ball_final_SBJ.name = 'ball';
  41. ball_final_SBJ.type = 'circle';
  42. ball_final_SBJ.window = window;
  43. ball_final_SBJ.centered_square = [posB_final_SBJ(1), posB_final_SBJ(2)];
  44. ball_final_SBJ.diameter = dimB(1);
  45. ball_final_SBJ.color = [0.5 0.5 0.5];
  46. baseRect_final_SBJ = [0 0 ball.diameter ball.diameter];
  47. ball_final_SBJ.dimension = CenterRectOnPoint(baseRect_final_SBJ, ball_final_SBJ.centered_square(1),...
  48. ball_final_SBJ.centered_square(2));
  49. %% creates the flat horizontal line onto the ball lands after falling in the CF turn
  50. % length and thickness in pixels
  51. [dim_table] = JA_prop2dim(screen_dimensions, 0.15, 0.005);
  52. % position of the center of the table on the screen in pixels
  53. [pos] = JA_prop2dim(screen_dimensions, 0.65, 0.5667);
  54. table_CF = [];
  55. table_CF.name = 'table_CF';
  56. table_CF.type = 'square';
  57. table_CF.window = window;
  58. table_CF.centered_square = [pos(1) pos(2)];
  59. table_CF.length = dim_table(1);
  60. table_CF.height = dim_table(2);
  61. table_CF.position = [0 0 table_CF.length table_CF.height];
  62. table_CF.color = [1 1 1];
  63. table_CF.dimension = ...
  64. CenterRectOnPoint(table_CF.position, table_CF.centered_square(1),...
  65. table_CF.centered_square(2));
  66. table_CF.dimension(2) = ball_final_CF.dimension(4);
  67. table_CF.dimension(4) = table_CF.dimension(2)+table_CF.height;
  68. %% create Piston for CF
  69. [dimP1] = JA_prop2dim(screen_dimensions, 0.25, 0.1);
  70. [posPCF] = JA_prop2dim(screen_dimensions, 0.84, 0.5);
  71. piston_CF = [];
  72. piston_CF.name = 'piston_CF';
  73. piston_CF.type = 'square';
  74. piston_CF.window = window;
  75. piston_CF.centered_square = [posPCF(1) ball_final_CF.centered_square(2)];
  76. piston_CF.length = dimP1(1);
  77. piston_CF.height = dimP1(2);
  78. piston_CF.position = [0 0 piston_CF.length piston_CF.height];
  79. piston_CF.color = [0.5 0.5 0.5];
  80. piston_CF.dimension = ...
  81. CenterRectOnPoint(piston_CF.position, piston_CF.centered_square(1),...
  82. piston_CF.centered_square(2));
  83. piston_CF.dimension(1) = table_CF.dimension(3);
  84. piston_CF.dimension(3) = piston_CF.dimension(1)+ piston_CF.length;
  85. %% creates the vertical line onto the ball lands after the ball has been pushed by CF
  86. [dim_table] = JA_prop2dim(screen_dimensions, 0.15, 0.005);
  87. table_SBJ = [];
  88. table_SBJ.name = 'table_SBJ';
  89. table_SBJ.type = 'square';
  90. table_SBJ.window = window;
  91. table_SBJ.centered_square = [0 ball_final_CF.centered_square(2)];
  92. table_SBJ.length = dim_table(2);
  93. table_SBJ.height = dim_table(1);
  94. table_SBJ.position = [0 0 table_SBJ.length table_SBJ.height];
  95. table_SBJ.color = [1 1 1];
  96. table_SBJ.dimension = ...
  97. CenterRectOnPoint(table_SBJ.position, table_SBJ.centered_square(1),...
  98. table_SBJ.centered_square(2));
  99. table_SBJ.dimension(3) = ball_final_SBJ.dimension(1); %%%%
  100. table_SBJ.dimension(1) = table_SBJ.dimension(3)-table_SBJ.length/2;
  101. %% create Piston for SBJ
  102. pos(1) = ball_final_SBJ.centered_square(1);
  103. pos(2) = ball_final_SBJ.centered_square(2);
  104. piston_SBJ = [];
  105. piston_SBJ.name = 'piston_SBJ';
  106. piston_SBJ.type = 'square';
  107. piston_SBJ.window = window;
  108. piston_SBJ.centered_square = [pos(1) pos(2)];
  109. piston_SBJ.length = dimP1(2);
  110. piston_SBJ.height = dimP1(1);
  111. piston_SBJ.position = [0 0 piston_SBJ.length piston_SBJ.height];
  112. piston_SBJ.color = [0.5 0.5 0.5];
  113. piston_SBJ.dimension = ...
  114. CenterRectOnPoint(piston_SBJ.position, piston_SBJ.centered_square(1),...
  115. piston_SBJ.centered_square(2));
  116. piston_SBJ.dimension(2) = table_SBJ.dimension(4);
  117. piston_SBJ.dimension(4) = piston_SBJ.dimension(2)+ piston_SBJ.height;
  118. %% create Background object
  119. back = [];
  120. back.name = 'back';
  121. back.type = 'square';
  122. back.color = [0 0 0];
  123. back.dimension = screen_dimensions;
  124. back.centered_square = [screen_dimensions(3)/2 screen_dimensions(4)/2];
  125. back.length = screen_dimensions(3);
  126. back.height = screen_dimensions(4);
  127. back.position = [0 0 back.length back.height];
  128. back.dimension = ...
  129. CenterRectOnPoint(back.position, back.centered_square(1),...
  130. back.centered_square(2));
  131. %% create arduino objects standing for the three sensors
  132. % pressure sensor underneath CF right hand
  133. arduino_CF = [];
  134. arduino_CF.name = 'arduino_CF';
  135. arduino_CF.val = [];
  136. arduino_CF.type = 'none';
  137. % pressure sensor underneath PTP right hand
  138. arduino_SBJ_DCG = [];
  139. arduino_SBJ_DCG.name = 'arduino_SBJ_DCG';
  140. arduino_SBJ_DCG.val = [];
  141. arduino_SBJ_DCG.type = 'none';
  142. % pressure sensor underneath PTP left hand
  143. arduino_SBJ_RISP = [];
  144. arduino_SBJ_RISP.name = 'arduino_SBJ_RISP';
  145. arduino_SBJ_RISP.val = [];
  146. arduino_SBJ_RISP.type = 'none';
  147. %% creates a structure containing all the objects created that can be put as inputs or outputs for functions in the main script
  148. Ob = [];
  149. Ob.back = back;
  150. Ob.piston_CF = piston_CF;
  151. Ob.piston_SBJ =piston_SBJ;
  152. Ob.ball = ball;
  153. Ob.table_CF = table_CF;
  154. Ob.table_SBJ = table_SBJ;
  155. Ob.arduino_CF = arduino_CF;
  156. Ob.arduino_SBJ_DCG = arduino_SBJ_DCG;
  157. Ob.arduino_SBJ_RISP = arduino_SBJ_RISP;
  158. Ob_fieldnames = fieldnames(Ob);
  159. %% the following allows sliding the whole set of objects on the screen along the X axis
  160. [slide] = JA_prop2dim(Par.screen_dimensions, 0.2, 0);
  161. for sl = 1:length(Ob_fieldnames)
  162. if ~strcmp(Ob.(Ob_fieldnames{sl}).name, 'back')
  163. % if the object has a 'dimension' field...
  164. if isfield(Ob.(Ob_fieldnames{sl}), 'dimension')
  165. % slide it on the X axis by subtracting the pixels in the slide variable
  166. Ob.(Ob_fieldnames{sl}).dimension([1 3]) = Ob.(Ob_fieldnames{sl}).dimension([1 3])-slide(1);
  167. Ob.(Ob_fieldnames{sl}).centered_square(1) = Ob.(Ob_fieldnames{sl}).centered_square(1)-slide(1);
  168. end
  169. end
  170. end
  171. end