2016-01-27 148 views
0

我是psychtoolbox的新手,嘗試旋轉/繪製框架方形的菱形/菱形,但無法完全弄清楚它是如何工作的。這裏是我的代碼:Psychtoolbox更改爲菱形/菱形繪製的方形

AssertOpenGL; 
screenNo = max(Screen('Screens')); 
screenRes = [0 0 640 480];   
Screen('Preference', 'SkipSyncTests', 2); 

ListenChar(2); 

[win, rect] = Screen('OpenWindow', screenNo, [0 0 0], screenRes); 
[width, height]=Screen('WindowSize', win); 
[x,y] = RectCenter(rect); 
baseRect = [0 0 250 250]; 
centeredRect = CenterRectOnPointd(baseRect, x, y); 

Screen('FrameRect', win, [255 255 255], centeredRect, 3); 
Screen('Flip', win); 

KbWait; 
sca; 

我試圖改變我的baseRect爲[320 115 320 365],但它不工作。如果我想要菱形/菱形,不太確定如何指定[左,上,右,下]座標。

感謝您的任何幫助。

回答

0

FrameRect函數只會構造直立的矩形。您可以從矩形創建紋理,然後旋轉顯示。或者,您可以指定鑽石每個邊緣的座標,然後使用「FramePoly」功能顯示該座標。例如:

AssertOpenGL; 
screenNo = max(Screen('Screens')); 
screenRes = [0 0 640 480];   
Screen('Preference', 'SkipSyncTests', 2); 

ListenChar(2); 

[win, rect] = Screen('OpenWindow', screenNo, [0 0 0], screenRes); 
[width, height]=Screen('WindowSize', win); 
[x,y] = RectCenter(rect); 

% compute poly coordinates 
polyWidth = 250; 
polyHeight = 250; 
xCoord = [x, x - (polyWidth/2), x, x + (polyWidth/2)]'; 
yCoord = [y + (polyHeight /2), y, y - (polyHeight /2), y]'; 
polyCoords = [xCoord yCoord]; 

Screen('FramePoly', win, [255 255 255], polyCoords, 3); 
Screen('Flip', win); 

KbWait; 
sca; 
+0

謝謝!這對我幫助很大! – hanna

0

您可以通過變換繪製psychtoolbox的原語與這些功能:

Screen('glPushMatrix', windowPtr); 
Screen('glPopMatrix', windowPtr); 
Screen('glLoadIdentity', windowPtr); 
Screen('glTranslate', windowPtr, tx, ty [, tz]); 
Screen('glScale', windowPtr, sx, sy [, sz]); 
Screen('glRotate', windowPtr, angle, [rx = 0], [ry = 0] ,[rz = 1]); 

然後,你可以繼續使用Screen('FrameRect')