在MATLAB中加速轮 - psychtoolbox

时间:2010-04-10 19:24:29

标签: matlab psychtoolbox

我正在尝试编写一个显示加速轮的代码。只要用户按下'a',车轮就会逆时针加速。问题是它转向正确的方向,但它没有加速。这是我正在使用的代码(在PTB-3和Windows XP中):

img=imread('c:\images.jpg');  
[yimg,ximg,z]=size(img);  
rot_spd = 1;  
larrow = KbName('a'); % modify this for Windows  
rarrow = KbName('b');  
[w,rect]=Screen('OpenWindow',0,[0 0 0]);  
sx = 400; % desired x-size of image (pixels)  
sy = yimg*sx/ximg; % desired y-size--keep proportional  
t = Screen('MakeTexture',w,img);  
bdown=0;  
th = 0; % initial rotation angle (degrees)  
HideCursor  
while(~any(bdown)) % exit loop if mouse button is pressed  
    [x,y,bdown]=GetMouse;  
    [keyisdown,secs,keycode] = KbCheck;    
    if(keycode(larrow))  
        th = th - rot_spd-1; % accelerate counterclockwise  
        th  
    end  
    if(keycode(rarrow))  
        th = th + rot_spd+1; % accelerate clockwise  
        th  
    end  
    destrect=[x-sx/2,y-sy/2,x+sx/2,y+sy/2];  
    Screen('DrawTexture',w,t,[],destrect,th);  
    Screen('Flip',w);   
end  
Screen('Close',w)   
ShowCursor   

如果有人知道它为什么不加速,我会非常感激。

1 个答案:

答案 0 :(得分:1)

if(keycode(larrow))  
    th = th - rot_spd-1; % accelerate counterclockwise  
    th  
end  
if(keycode(rarrow))  
    th = th + rot_spd+1; % accelerate clockwise  
    th  
end 

此代码似乎仅影响th一个“周期”。相反,您应该修改旋转速度,并使旋转速度影响角度。

试试这个:

if(keycode(larrow))  
    rot_spd-=1; % accelerate counterclockwise  
    th  
end
if(keycode(rarrow))  
    rot_spd+=1; % accelerate clockwise  
    th  
end
the+=rot_speed;