Hello, I want to use window0 for presentation of cloud of dots and window1 for different stimuli (e.g. rectangle).
I referred to Draw dots in 3D space for the cloud of dots.
however, when using multiple window, cloud of dots appear in window1 along with rectangle.
are there any ways to designate cloud of dots stimuli in specific window ?
below is the minimal replication of the script;
#!/bin/env python3
# -*- coding: utf-8 -*-
# this program is based on 3D cloud of dots from following link
# https://discourse.psychopy.org/t/draw-dots-in-3d-space/8918/4
from psychopy import event,visual, event
import numpy as np
import pyglet.gl as GL
import psychopy.tools.viewtools as vt
import psychopy.tools.mathtools as mt
#Monitor settings
SCREEN = 0
SCREEN1 = 1
BG_COLOR = [-1,-1,-1]
scrDist = 0.50 # 50cm
scrWidth = 0.53 # 53cm
scrAspect = 1.0
# Create a window
WINDOW = visual.Window(screen=SCREEN, size=(800, 800), color=BG_COLOR,
units='pix', allowGUI=True, fullscr=False, useFBO=True)
WINDOW1 = visual.Window(screen=SCREEN1, size=(800,800), color=BG_COLOR,
units='pix', allowGUI=True, fullscr=False, useFBO=True)
# Rectangle
startBtn = visual.Rect(
WINDOW1, size=30, autoLog=False, lineColor=[1, 1, 1],
fillColor=[1, 1, 1], name='StartBtn')
#Frustum (Parameters are in m)
frustum = vt.computeFrustum(scrWidth, scrAspect, scrDist, nearClip=0.1, farClip=1000.0)
WINDOW.projectionMatrix = vt.perspectiveProjectionMatrix(*frustum)
# Transformation for points (model/view matrix)
MV = mt.translationMatrix((0.0, 0.0, -scrDist)) # X, Y, Z
WINDOW.viewMatrix = MV
# create array of random points
nPoints = 10000
pos = np.zeros((nPoints, 3), dtype=np.float32)
# random X, Y
pos[:, :2] = np.random.uniform(-500, 500, (nPoints, 2))
# random Z to far clipping plane, -1000.0 is -farClip
pos[:, 2] = np.random.uniform(0.0, -1000.0, (nPoints,))
while 1:
# --- render loop ---
startBtn.draw()
WINDOW.applyEyeTransform()
# draw 3D stuff here
GL.glColor3f(1, 1, 1) # white RGB color space (0 ~ 1)
# draw objects in glbegin~glend
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.glVertex3f(*pos[i, :]) # position
GL.glEnd()
# Show image
WINDOW.flip()
WINDOW1.flip()
# transform points -Z direction, in OpenGL -Z coordinates are forward
pos[:, 2] += 10.0 # distance to move the dots per frame towards the viewer
# if a point is behind us, return to initial -Z position
pos[:, 2] = np.where(pos[:, 2] > 0.0, -1000.0, pos[:, 2])
# check events to break out of the loop!
# Press Esc to break loop
KEY = event.getKeys(keyList= ['escape'])
if 'escape' in KEY:
break
version is 2023.1.2
Thanks in advance !