Пример #1
0
    def __init__(self, screenidx=1, color=(1., 1., 1.), scale=0.09, *args, **kwargs):
        display = pyglet.window.get_platform().get_default_display()
        screen = display.get_screens()[screenidx]
        super(DotWindow, self).__init__(screen=screen, *args, **kwargs)

        spheres = gen_spheres(scale=scale, color=color)
        self.scene = rc.Scene(meshes=spheres, bgColor=(0,)*3)
        cam = self.scene.camera
        self.shader = rc.Shader.from_file(*rc.resources.genShader)
        cam.projection = rc.OrthoProjection(origin='center', coords='relative')

        cam.update()

        pyglet.clock.schedule(update_silently)
Пример #2
0
import ratcave as rc
import pyglet


window = pyglet.window.Window(resizable=True, width=400, height=800)
pyglet.clock.schedule(lambda dt: dt)

cube = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh('Cube', scale=.02)
cube.position.xyz = .5, .5, -2
cam = rc.Camera()
cam.projection = rc.OrthoProjection(coords='relative', origin='corner')

@window.event
def on_draw():
    with rc.default_shader, rc.default_states, cam:
        cube.draw()

@window.event
def on_resize(width, height):
    # cam.projection.match_aspect_to_viewport()

    cam.projection.aspect = width / height
    # cam.reset_uniforms()
    # cam.projection.projection_matrix[0, 0] += .01
    print(cam.projection.viewport)
    print(cam.projection_matrix)
    print(cam.uniforms['projection_matrix'])


pyglet.app.run()
Пример #3
0
 }
 """

shader = rc.Shader(vert=vert_shader, frag=frag_shader)
plane = rc.WavefrontReader(rc.resources.obj_primitives).get_mesh(
    'Plane')  #gen_fullscreen_quad()
plane.scale.xyz = .2
plane.position.xyz = 0, 0, -1
plane.uniforms['theta'] = 0.
plane.uniforms['width'] = .01

window = pyglet.window.Window(fullscreen=True)

scene = rc.Scene(meshes=[plane],
                 bgColor=(.5, .5, .5),
                 camera=rc.Camera(projection=rc.OrthoProjection()))


# Draw Function
@window.event
def on_draw():
    with shader:
        scene.draw()


def update(dt):
    plane.uniforms['theta'] += dt * 7.


pyglet.clock.schedule(update)
Пример #4
0
cylinder.uniforms['flat_shading'] = True
cylinder.point_size = .02
cylinder.position.x = -.3
cylinder.scale.xyz = .5

cyl2 = cylinder.copy()
cyl2.position.x = 0
# cyl2.rotation.x = 20

cyl3 = cylinder.copy()
cyl3.position.x = .3
cyl3.rotation.y = 30

win = pyglet.window.Window(fullscreen=True)

scene = rc.Scene(meshes=[cylinder, cyl2, cyl3], bgColor=(0, 0, 0), camera=rc.Camera(projection=rc.OrthoProjection(coords='relative')))

fps_label = pyglet.window.FPSDisplay(window=win)

@win.event
def on_draw():
    with rc.default_shader:
        scene.draw()
    fps_label.draw()
#
def update(dt):
    cylinder.rotation.x += 100 * dt
    cyl2.rotation.y += 100 * dt
    cyl3.rotation.z += 100 * dt
pyglet.clock.schedule(update)
Пример #5
0
import pyglet
import ratcave as rc
import numpy as np
from numpy.random import random

n_points = 2000
width, height = 0.2, 0.5
theta = random(n_points) * np.pi * 2
verts = np.vstack((np.sin(theta) * width, (random(n_points) - .5) * height, np.cos(theta) * width)).T

cylinder = rc.Mesh.from_incomplete_data(verts, drawmode=rc.GL_POINTS, position=(0, 0, -2),
                                        point_size=1, mean_center=False)
cylinder.uniforms['diffuse'] = 1., 1., 1.
cylinder.uniforms['flat_shading'] = True

scene = rc.Scene(meshes=[cylinder], bgColor=(0., 0, 0), camera=rc.Camera(projection=rc.OrthoProjection()))

win = pyglet.window.Window()

@win.event
def on_draw():
    with rc.default_shader:
        scene.draw()


def update(dt):
    theta = random(n_points) * np.pi * 2
    verts = np.vstack((np.sin(theta) * width, (random(n_points) - .5) * height, np.cos(theta) * width)).T
    cylinder.vertices = verts
pyglet.clock.schedule_interval(update, 1/60.)
from psychopy import visual, event
import ratcave as rc
import numpy as np
from numpy.random import random

n_points = 1000
width, height = 0.2, 0.5
theta = random(n_points) * np.pi * 2
verts = np.vstack((np.sin(theta) * width, (random(n_points) - .5) * height,
                   np.cos(theta) * width)).T

cylinder = rc.Mesh.from_incomplete_data(verts,
                                        drawmode=rc.gl.GL_POINTS,
                                        position=(0, 0, -2),
                                        point_size=2,
                                        mean_center=False)
cylinder.uniforms['diffuse'] = 1., 1., 1.
cylinder.uniforms['flat_shading'] = True

scene = rc.Scene(meshes=[cylinder], bgColor=(0., 0, 0))
scene.camera.projection = rc.OrthoProjection()

win = visual.Window()

while 'escape' not in event.getKeys():
    cylinder.rotation.y += .02
    with rc.default_shader:
        scene.draw()
    win.flip()
cylinder.dynamic = True

cyl2 = cylinder.copy()
cyl2.position.x = 0
# cyl2.rotation.x = 20

cyl3 = cylinder.copy()
cyl3.position.x = .3
cyl3.rotation.y = 30

win = pyglet.window.Window(fullscreen=True)

scene = rc.Scene(
    meshes=[cylinder, cyl2, cyl3],
    bgColor=(0, 0, 0),
    camera=rc.Camera(projection=rc.OrthoProjection(coords='relative')))

fps_label = pyglet.window.FPSDisplay(window=win)


@win.event
def on_draw():
    with rc.default_shader:
        scene.draw()
    fps_label.draw()


#
def update(dt):
    cylinder.rotation.x += 100 * dt
    cyl2.rotation.y += 100 * dt
Пример #8
0
import numpy as np
import csv
import config


# Make Psychopy visual stimuli
window = visual.Window(fullscr=config.FULLSCREEN, allowStencil=True, color=config.BGCOLOR)
fixcross = visual.TextStim(window, text='+', alignVert='center', alignHoriz='center')

# Make Ratcave stimuli
reader = rc.WavefrontReader('stimuli/rotstim.obj')
stim_orig = reader.get_mesh('OrigStim', position=(-.25, 0., -1), rotation=(0, config.YROT, 0), scale=config.SCALE)
stim_orig2 = reader.get_mesh('OrigStim', position = (.25, 0., -1), rotation=(0, config.YROT, 0), scale=config.SCALE)
stim_flipped = reader.get_mesh('FlippedStim', position = (.25, 0., -1), rotation=(0, config.YROT, 0), scale=config.SCALE)

scene = rc.Scene(meshes=[], camera=rc.Camera(projection=rc.OrthoProjection(origin='center', coords='relative')))
scene.light.position.z = 20

# Make Groups of Stimuli to refer to in experiment
stims = [stim_orig, stim_orig2, stim_flipped]
condA = [stim_orig, stim_orig2]
condB = [stim_orig, stim_flipped]



def show_instructions():
    msg = """
    3D Mental Rotation Study

    Press the left arrow if the two objects can be rotated into the same configuration, and the right if they are different.