I recently got great help from @mdc to perform a perspective projection and create an optic flow animation. Now that I managed to draw circles with fragment shaders, I would like to create another stim, with the same code, but instead of the perspective projection, I want the orthographic projection. I replaced then the perspective projection transformation with vt.orthoProjectionMatrix(). But I am just getting a black window with nothing drawn on it. Is there something I am missing, do I have to change other parameters?
Thanks in advance for your help!!
scrDist = 0.50 # 50cm
scrWidth = 0.53 # 53cm
scrAspect = 1.0
# Create a window
win = psychopy.visual.Window(
monitor=mon,
size=(800, 800),
color='Black',
colorSpace='rgb',
units='deg',
screen=scrn,
allowGUI=True,
fullscr=False)
# Frustum
frustum = vt.computeFrustum(scrWidth, scrAspect, scrDist, eyeOffset = 0.0, nearClip=0.05, farClip=10000.0)
# Frustum
frustum = vt.computeFrustum(scrWidth, scrAspect, scrDist, eyeOffset = 0.0, nearClip=0.05, farClip=10000.0)
# Transformation for points (model/view matrix)
MV = mt.translationMatrix((0.0, 0.0, -scrDist)) # X, Y, -Z (in camera view, the camera looks down the -Z axis)
# Perspective Projection
O = vt.orthoProjectionMatrix(*frustum)
# Set the window matrices
win.orthoMatrix = O
win.viewMatrix = MV
# create array of random points
nPoints = 900;
pos = np.zeros((nPoints, 3), dtype=np.float32) # create empty vector for each point, 3 coordinates (x,y,z)
# random X, Y : fill X and Y coordinates with uniform random values that serve as coordinates
pos[:, :2] = np.random.uniform(-500, 500, (nPoints, 2))
# random Z to far clipping plane, -1000.0 is -farClip
pos[:, -1] = np.random.uniform(0.0, -1000.0, (nPoints,))
while 1:
# --- render loop ---
# Before rendering
win.applyEyeTransform()
# draw 3D stuff here
GL.glColor3f(1.0, 1.0, 1.0)
GL.glPointSize(4.0);
GL.glBegin(GL.GL_POINTS)
for i in range(nPoints): # go over our array and draw the points using the coordinates
# color can be varied with distance if you like
#GL.glPointSize = GL.glPointSize / pos[i, :]
GL.glVertex3f(*pos[i, :]) # position
GL.glEnd()
win.flip()
# transform points -Z direction, in OpenGL -Z coordinates are forward
pos[:, -1] += 12.0 # distance to move the dots per frame towards the viewer
# if a point is behind us, return to initial -Z position
pos[:, -1] = np.where(pos[:, -1] > 0.0, -1000.0, pos[:, -1])
# check events to break out of the loop!
if len(event.getKeys())>0:
break
event.clearEvents()
win.close()