Package VisionEgg :: Package PyroApps :: Module ScreenPositionServer |
[frames] | no frames]

# Source Code for Module VisionEgg.PyroApps.ScreenPositionServer

      1  #!/usr/bin/env python
      2  #
      3  # The Vision Egg: ScreenPositionServer
      4  #
      5  # Copyright (C) 2001-2003 Andrew Straw.
      6  # Author: Andrew Straw <astraw@users.sourceforge.net>
      7  # URL: <http://www.visionegg.org/>
      8  #
      9  # Distributed under the terms of the GNU Lesser General Public License
     10  # (LGPL). See LICENSE.TXT that came with this file.
     11  #
     12  # $Id$
     13
     14  """Handle 3D perspective projection (server-side)"""
     15
     16  import Pyro.core
     17
     18  import sys, os, string
     19  import VisionEgg.Core
     20  import VisionEgg.FlowControl
     21  import VisionEgg.SphereMap
     22  import VisionEgg.Textures
     23  import VisionEgg.PyroHelpers
     24
     25  from VisionEgg.PyroApps.ScreenPositionGUI import ScreenPositionParameters
     26
     27  __version__ = VisionEgg.release_name
     28  __cvs__ = string.split('$Revision$')[1]
     29  __date__ = string.join(string.split('$Date$')[1:3], ' ')
     30  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     31
     32 -class ScreenPositionMetaController( Pyro.core.ObjBase ):
     33      """Encapsulates all parameters controlling screen position"""
     34 -    def __init__(self,presentation,projection):
     35          Pyro.core.ObjBase.__init__(self)
     36          self.meta_params = ScreenPositionParameters()
     37          if not isinstance(presentation,VisionEgg.FlowControl.Presentation):
     38              raise ValueError("Expecting instance of VisionEgg.FlowControl.Presentation")
     39          if not isinstance(projection,VisionEgg.Core.PerspectiveProjection):
     40              raise ValueError("Expecting instance of VisionEgg.Core.PerspectiveProjection")
     41          self.p = presentation
     42          self.proj = projection
     43
     44 -    def get_parameters(self):
     45          return self.meta_params
     46
     47 -    def set_parameters(self, new_parameters):
     48          if isinstance(new_parameters, ScreenPositionParameters):
     49              self.meta_params = new_parameters
     50          else:
     51              raise ValueError("Argument to set_parameters must be instance of ScreenPositionParameters")
     52          self.update()
     53
     54 -    def update(self):
     55          left = self.meta_params.left
     56          right = self.meta_params.right
     57          bottom = self.meta_params.bottom
     58          top = self.meta_params.top
     59          near = self.meta_params.near
     60          far = self.meta_params.far
     61
     62          eye = (self.meta_params.eye[0],
     63                 self.meta_params.eye[1],
     64                 self.meta_params.eye[2])
     65
     66          center = (self.meta_params.center[0],
     67                 self.meta_params.center[1],
     68                 self.meta_params.center[2])
     69
     70          up = (self.meta_params.up[0],
     71                 self.meta_params.up[1],
     72                 self.meta_params.up[2])
     73
     74          temp = VisionEgg.Core.PerspectiveProjection(left,right,bottom,top,near,far)
     75          temp.look_at(eye,center,up)
     76          self.proj.parameters.matrix = temp.get_matrix()
     77
     78 -    def go(self):
     79          self.p.parameters.enter_go_loop = 1
     80
     81 -    def quit_server(self):
     82          self.p.parameters.quit = 1
     83
     84  # Don't do anything unless this script is being run
     85  if __name__ == '__main__':
     86
     87      pyro_server = VisionEgg.PyroHelpers.PyroServer()
     88
     89      # get Vision Egg stimulus ready to go
     90      screen = VisionEgg.Core.Screen.create_default()
     91      filename = os.path.join(VisionEgg.config.VISIONEGG_SYSTEM_DIR,"data/az_el.png")
     92      texture = VisionEgg.Textures.Texture(filename)
     93      sphere_map = VisionEgg.SphereMap.SphereMap(texture=texture,
     94                                                 shrink_texture_ok=1,
     95                                                 stacks=100,
     96                                                 slices=100)
     97      temp = ScreenPositionParameters()
     98
     99      projection = VisionEgg.Core.PerspectiveProjection(temp.left,
    100                                                        temp.right,
    101                                                        temp.bottom,
    102                                                        temp.top,
    103                                                        temp.near,
    104                                                        temp.far)
    105      viewport = VisionEgg.Core.Viewport(screen=screen,stimuli=[sphere_map],projection=projection)
    106      p = VisionEgg.FlowControl.Presentation(viewports=[viewport])
    107
    108      # now hand over control of stimulus to GratingExperimentMetaController
    109      projection_controller = ScreenPositionMetaController(p,projection)
    110      pyro_server.connect(projection_controller,"projection_controller")
    111
    112      # get listener controller and register it
    113      p.add_controller(None,None, pyro_server.create_listener_controller())
    114
    115      # enter endless loop
    116      p.run_forever()
    117