前段时间我问了一个similar question,但我想我现在可能可以更好地表达它。
下面的代码(我正在改编,而不是从头开始写)在正确的位置和正确的角度绘制了一个白条,如下图所示。它使用Psychtoolbox中的OpenGL命令(在Matlab上运行)。simple坐标非常简单且基于像素:(0,0)位于左上角。Y向下增加,x向右增加。
我在理解OpenGL和心理学工具箱坐标之间的映射时遇到了麻烦。特别是,行glTranslatef( SkitSet.xLever, SkitSet.yLever, 0 );
将白条向下平移1.5个单位。这些单元是什么?我在哪里告诉matlab,1.5个单位的OpenGL大约是垂直屏幕的一半?
%% Psychtoolbox settings
whichScreen = 0;
Screen('Preference', 'SkipSyncTests', 1); %1->without testing
inScreenRect = [0 0 500 500];
% Open window and specify some OpenGL settings
InitializeMatlabOpenGL( [], [], [], 0 );
[win , winRect] = PsychImaging( 'OpenWindow', whichScreen, 0, inScreenRect, [], [], 0, 0 );
Screen( 'BeginOpenGL', win );
aspectRatio = winRect( 4 ) / winRect( 3 ); %% Get the aspect ratio of the screen
[winCenter.x, winCenter.y] = RectCenter(winRect); %find the center of the screen
glMatrixMode( GL.PROJECTION );
glLoadIdentity;
gluPerspective( 25, 1 / aspectRatio, 0.1, 100 );
glMatrixMode( GL.MODELVIEW );
glLoadIdentity;
gluLookAt( 0, 0, 8, 0, 0, 0, 0, 1, 0); %Set view point, center and direction
glClearColor( 0, 0, 0, 0 );
Screen( 'EndOpenGL', win );
SkitSet.xLever = 0;
SkitSet.yLever = -1.5000;
SkitSet.LeverLength = 0.4000;
SkitSet.LeverWidth = 0.0400;
Screen( 'BeginOpenGL', win );
glClear;
glPushMatrix;
glTranslatef( SkitSet.xLever, SkitSet.yLever, 0 );
glRotatef( -45, 0.0, 0.0, 1.0 );
glRectf( -SkitSet.LeverLength, -SkitSet.LeverWidth / 2, 0, SkitSet.LeverWidth / 2 );
glPopMatrix;
Screen( 'EndOpenGL', win );
Screen( 'Flip', win, [], [], 0 );
发布于 2017-06-29 21:06:44
这是一个更多的OpenGL问题,而不是任何特定于心理工具箱的问题。您正在设置投影平截体。因此,您绘制的任何刺激都将使用您设置的投影和模型视图进行投影。单位是任意的,但以米为单位是有帮助的。如果gluPerspective
中的zNear和zFar是以米为单位的,那么所有其他调用(如glTranslatef
和glRectf
)也会采用相同单位的输入参数。如果你想把东西向下移动半个屏幕,你必须计算它在Y和Z中的位置,给定你在gluPerspective
中指定的视野。如果只是绘制杠杆,是否确实要设置自己的投影和模型视图矩阵?心理工具箱的默认设置将为您完成此操作,然后您也可以在OpenGL模式下处理单个像素。如果PTB默认设置不起作用,那么使用窗口矩形作为四个顶点来设置gluortho2d
。
https://stackoverflow.com/questions/43676901
复制相似问题