Can I know how many times the cylinder rotates?
Mostrar comentarios más antiguos
Hello.
I am a beginner in matlab.
I got the code in psychtoolbox that can make rotating cylinder.
I want to create a cylinder that rotates only once in 1.43 seconds at 60fps.
So I put number 60 in nframes and 86 in while fr (like under).
nFrames = 60; % 3 line on number 2 file
while fr <= 86 % 15 line on number 2 file
But I do not know how can I make a cylinder only once rotating in that time. I think I should put adequate number in NumFrames (8 line on number 1 file). If it is right, what number should I put it?
Because when I put 86(the same number with while fr), the resulting cylinder appears to rotate for one and a half round.
Could anyone help me, please..?
Below is rotating cylinder code file.
#number 1 file
clear;
makeCyl = 1;
%% parameters
W = 153; %width
ndot = 900;
NumFrames = 86;
stepD = 400; % ie the half perimeter of the cylinder
cylR = stepD/pi; %guarantee the cylinder aprroaches with the same distance per 180 degree as the figure walks a step
%% cylinder
if makeCyl
backCol=0.9;
dotx = sin((rand(1,ndot)-0.5)*pi)* W/2; %dots are more concentrated on the two boundaries after ttransformed to sin, more natural than sqrt
dotc = ones(1, ndot);
angs = 2*pi* rand(1,ndot);
angpf = 2*pi/NumFrames; %angle per frame
Cylin = NaN(NumFrames*3,ndot); %keep it the same format as the mov file
dotC = cell(NumFrames,1);
for zz = 1:NumFrames
Cylin(zz*3-2,:) = dotx;
Cylin(zz*3-1,:) = cylR*cos(angs);
Cylin(zz*3,:) = cylR*sin(angs); % all dots are in the same depth so that it won'd contain perspective cue when drawn by moglDrawDots3D
angs = angs-angpf;
dotc = ones(1, ndot);
dotc(:, mod(angs,2*pi)<=pi) = backCol;
dotC{zz}= [1;1;1]*dotc;
end
save('Cylin_aaa','Cylin' ,'ndot');
end
#number 2 file
InitializeMatlabOpenGL;
load('Cylin_aaa.mat')
nFrames = 60;
fr = 1;
InitializeMatlabOpenGL; % open GL reset, moglDrawDots3D Required for function execution
%Screen('Preference', 'SkipSyncTests', 1);
Screen('Preference', 'SkipSyncTests', 1) % Skip sync test for testing
whichScreen = max(Screen('Screens'));
[w, screenRect] = Screen('OpenWindow', whichScreen,[0 0 0],[]); % small screen output
ScreenCenter = [screenRect(3)/2 screenRect(4)/2];
commandwindow;
while fr <= 86
thefr = fr;
while thefr > nFrames; thefr =thefr-nFrames; end
disp(thefr); % Check frame progress
this_xyz = Cylin(thefr*3-2:thefr*3,:);
Screen('DrawDots',w, this_xyz(1:2,:),[],[255 255 255],ScreenCenter, 0);
% moglDrawDots3D(w, this_xyz, 1, [1 1 1]); %
Screen('Flip',w);
%WaitSecs(0.05); % To see the dot move slowly
fr = fr +1;
end
sca;
Thank you.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Timing and presenting 2D and 3D stimuli en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!