0

I'm new at psychtoolbox and trying to rotate/draw my framed square to a diamond/rhombus, but can't quite figure it out how it works. Here's my code:

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; 

I tried changing my baseRect into [320 115 320 365], but it doesn't work. Not so sure how to specify the [left, top, right, bottom] coordinate if I want a diamond/rhombus.

Thanks for any help.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
hanna
  • 3
  • 1

2 Answers2

0

The FrameRect function will only construct upright rectangles. You could create a texture from the rectangle, then rotate that on display. Alternatively, you could specify the coordinates of each edge of the diamond, then display that using the 'FramePoly' function. For example:

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; 
DMR
  • 1,479
  • 1
  • 8
  • 11
0

You can transform the primitives drawn by psychtoolbox with these functions:

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]);

Then you can just keep using Screen('FrameRect')