0

加速するホイールを表示するコードを作成しようとしています。ユーザーが「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   

加速しない理由がわかる方がいらっしゃいましたら、よろしくお願いいたします。

4

1 に答える 1

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このコードは、正確に 1 つの「サイクル」に影響を与えるように見えます。代わりに、回転速度を変更して、回転速度が角度に影響を与えるようにする必要があります。

これを試して:

if(keycode(larrow))  
    rot_spd-=1; % accelerate counterclockwise  
    th  
end
if(keycode(rarrow))  
    rot_spd+=1; % accelerate clockwise  
    th  
end
the+=rot_speed;
于 2011-06-30T21:45:55.067 に答える