Skip to content

Commit

Permalink
WIP: more on Window.viewScale, .viewPos
Browse files Browse the repository at this point in the history
with outline of a test
  • Loading branch information
jeremygray committed Nov 18, 2015
1 parent ff76914 commit 6284c5b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
26 changes: 26 additions & 0 deletions psychopy/tests/test_all_visual/flips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# test window.viewScale and .viewPos simultaneous and negative-going values
# the green square/rect should move clockwise around the text

from psychopy import visual, event

win = visual.Window(size=(400,400), units='pix') #, viewOri=30) test viewOri here

v = [(1,1),(1,-1),(-1,-1),(-1,1)] # vertices to use = square
n = 30 # size of the square
pimg= (n,n) # position for the image
pgrn = (-n,-n) # position for green square

for offset in [(0,0), (-.4,0)]:
win.viewPos = offset
for scale in [[1,1], # normal: green at lower left
[1,-1], # mirror vert only: green appears to move up, text mirrored
[-1,-1], # mirror horiz & vert: green appears to move right, text normal but upside down
[-1,1], # mirror horiz only: green appears to move down, text mirrored
[2,2],[2,-2],[-2,-2],[-2,2]]: # same, but both larger
win.viewScale = scale
grn = visual.ShapeStim(win, vertices=v, pos=pgrn, size=n, fillColor='darkgreen')
img = visual.ImageStim(win, image='s.png', pos=pimg)
grn.draw()
img.draw()
win.flip()
event.waitKeys()
Binary file added psychopy/tests/test_all_visual/s.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 9 additions & 5 deletions psychopy/visual/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,15 +609,13 @@ def flip(self, clearBuffer=True):
if stencilOn:
GL.glEnable(GL.GL_STENCIL_TEST)
#rescale/reposition view of the window
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
if self.viewScale is not None:
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
GL.glOrtho(-1, 1, -1, 1, -1, 1)
GL.glScalef(self.viewScale[0], self.viewScale[1], 1)
scale = self.viewScale
else:
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
scale = [1, 1]

if self.viewPos is not None:
Expand All @@ -626,7 +624,13 @@ def flip(self, clearBuffer=True):
GL.glTranslatef(norm_rf_pos_x, norm_rf_pos_y, 0.0)

if self.viewOri is not None:
GL.glRotatef(self.viewOri, 0.0, 0.0, -1.0)
# the logic below for flip is partially correct, but does not handle viewPos
flip = 1
if self.viewScale is not None:
_f = self.viewScale[0] * self.viewScale[1]
if _f < 0:
flip = -1
GL.glRotatef(flip * self.viewOri, 0.0, 0.0, -1.0)

#reset returned buffer for next frame
self._endOfFlip(clearBuffer)
Expand Down

0 comments on commit 6284c5b

Please sign in to comment.