Exemple #1
0
def mobiusband(gmap=None):
    from math import pi, cos, sin
    from numpy import array
    nbsq = 16
    if gmap is None: gmap = GMap(2)
    gmap, msquares = toposquares(nbsq, gmap)
    for i in xrange(nbsq - 1):
        gmap.sew_dart(msquares[i][5], msquares[i + 1][0])
    gmap.sew_dart(msquares[nbsq - 1][4], msquares[0][0])

    dalpha = 2 * pi / nbsq
    radius1, radius2 = 10, 5
    length = 1
    alpha = 0
    ralpha = pi / 8
    for sqid in xrange(nbsq):
        dart1, dart2 = msquares[sqid][0], msquares[sqid][1]
        centralpos = array([0, radius1 * cos(alpha), radius2 * sin(alpha)])
        #u,v = [1,0,0], [0,cos(alpha),sin(alpha)]
        #deltapos = [length*cos(alpha), length*sin(alpha)]
        position1 = centralpos + [
            length * cos(ralpha), length * sin(ralpha) * cos(alpha),
            length * sin(ralpha) * sin(alpha)
        ]
        gmap.set_position(dart1, position1)

        position2 = centralpos + [
            length * cos(pi + ralpha), length * sin(pi + ralpha) * cos(alpha),
            length * sin(pi + ralpha) * sin(alpha)
        ]
        gmap.set_position(dart2, position2)
        alpha += dalpha
        ralpha += dalpha / 2

    return gmap, sum(msquares, [])
Exemple #2
0
 def open(self):
    '''
    frame main structure is instanciated here.
    '''
    #load all needed resources
    GMenu.load_resources()
    GMap.load_resources()
    GUnit.load_resources()
    self.gmenu=GMenu(parent=self,pref_h=50)
    #instanciate screen objects
    self.gmap=GMap(parent=self)
    self.gnotifier=GNotifier(parent=self,pref_h=50)
Exemple #3
0
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.gMap = GMap()
        self.locationEdit = LocationEdit()
        self.gpsList = GpsList()
        gpsLayout = QVBoxLayout()
        gpsLayout.setContentsMargins(0, 2, 0, 0)
        gpsLayout.addWidget(self.locationEdit)
        gpsLayout.addWidget(self.gpsList)

        widget = QWidget()
        widget.setLayout(gpsLayout)

        self.splitter = QSplitter(Qt.Vertical)
        self.splitter.setHandleWidth(1)
        self.splitter.setChildrenCollapsible(False)
        self.splitter.addWidget(self.gMap)
        self.splitter.addWidget(widget)

        mainLayout = QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        mainLayout.setSpacing(0)
        mainLayout.addWidget(self.splitter)
        self.setLayout(mainLayout)
        self.setStyleSheet('QTableView{border-top: 1px solid #818A9A}'
                           'QSplitter{background-color: #818A9A}')
        self.gMap.locationSet.connect(self.locationEdit.setData)
        #self.gpsList.currentLocationChanged.connect(self.locationEdit.setData)
        self.gpsList.currentLocationChanged.connect(self.gMap.loadLocation)
        self.locationEdit.wantSaveLocation.connect(self.gpsList.addGpsItem)
        self.gMap.locationSet.connect(self.registerCurrentLocation)
Exemple #4
0
def topopolyline(nbpoints=3, gmap=None):
    if gmap is None: gmap = GMap(1)

    darts = [gmap.add_dart() for i in xrange(nbpoints * 2)]
    for i in xrange(nbpoints):
        gmap.link_darts(0, darts[2 * i], darts[2 * i + 1])
    for i in xrange(nbpoints - 1):
        gmap.link_darts(1, darts[2 * i + 1], darts[2 * i + 2])
    return gmap, darts
Exemple #5
0
def topopolygon(nbpoints=3, gmap=None):
    if gmap is None: gmap = GMap(2)

    darts = [gmap.add_dart() for i in xrange(nbpoints * 2)]
    for i in xrange(nbpoints):
        gmap.link_darts(0, darts[2 * i], darts[2 * i + 1])
    for i in xrange(nbpoints):
        gmap.link_darts(1, darts[2 * i + 1],
                        darts[(2 * i + 2) % (2 * nbpoints)])
    return gmap, darts
Exemple #6
0
def gmap_from_triangular_mesh(points, triangles, center=False):
    gmap = GMap()

    triangle_edges = np.sort(
        np.concatenate(
            [np.transpose([v, list(v[1:]) + [v[0]]]) for v in triangles]))

    edges = array_unique(triangle_edges)
    triangle_edges = (vq(triangle_edges, edges)[0]).reshape(
        (len(triangles), 3))

    triangle_edge_vertices = np.concatenate(
        [np.transpose([v, list(v[1:]) + [v[0]]]) for v in triangles])
    triangle_edge_orientation = (triangle_edge_vertices[:, 1] >
                                 triangle_edge_vertices[:, 0]).reshape(
                                     (len(triangles), 3))

    triangle_darts = {}
    for fid, t in enumerate(triangles):
        gmap, tri = topopolygon(3, gmap)
        triangle_darts[fid] = tri

    for eid, e in enumerate(edges):
        fids_to_sew, darts_to_sew = np.where(triangle_edges == eid)
        orientations_to_sew = triangle_edge_orientation[(fids_to_sew,
                                                         darts_to_sew)]
        if len(orientations_to_sew) > 1:
            gmap.sew_dart(
                2,
                triangle_darts[fids_to_sew[0]][2 * darts_to_sew[0] +
                                               (1 - orientations_to_sew[0])],
                triangle_darts[fids_to_sew[1]][2 * darts_to_sew[1] +
                                               (1 - orientations_to_sew[1])])

    mesh_center = np.mean(points, axis=0) if center else np.zeros(3)
    for fid, t in enumerate(triangles):
        for i, p in enumerate(t):
            gmap.set_position(triangle_darts[fid][2 * i],
                              points[p] - mesh_center)

    return gmap
Exemple #7
0
def crossshape():
    gmap = GMap(3)
    gmap, cube1 = cube(gmap=gmap)

    gmap, cube2 = cube(gmap=gmap, center=[10, 0, 0])
    gmap.sew_dart(cube1[8], cube2[8 * 3 + 1])

    gmap, cube3 = cube(gmap=gmap, center=[0, 10, 0])
    gmap.sew_dart(cube1[8 * 2], cube3[8 * 4 + 1])

    gmap, cube4 = cube(gmap=gmap, center=[0, 0, 10])
    gmap.sew_dart(cube1[0], cube4[8 * 5 + 1])

    gmap, cube5 = cube(gmap=gmap, center=[-10, 0, 0])
    gmap.sew_dart(cube1[8 * 3], cube5[8 + 1])

    gmap, cube6 = cube(gmap=gmap, center=[0, -10, 0])
    gmap.sew_dart(cube1[8 * 4], cube6[8 * 2 + 1])

    gmap, cube7 = cube(gmap=gmap, center=[0, 0, -10])
    gmap.sew_dart(cube1[8 * 5], cube7[1])

    return gmap, sum([cube1, cube2, cube3, cube4, cube5, cube6, cube7], [])
Exemple #8
0
class GFrame(Frame):
   '''
   gaming frame. responsible for any display while the game is running.
   '''
   stop_gaming='stop_gaming'

   def __init__(self,*args,**kwargs):
      kwargs['layout']=VLayout
      Frame.__init__(self,*args,**kwargs)
      self.process_server_input=pstat(self.process_server_input)
      #to be set as soon as a connection is done with the server
      self.pid=None

   def open(self):
      '''
      frame main structure is instanciated here.
      '''
      #load all needed resources
      GMenu.load_resources()
      GMap.load_resources()
      GUnit.load_resources()
      self.gmenu=GMenu(parent=self,pref_h=50)
      #instanciate screen objects
      self.gmap=GMap(parent=self)
      self.gnotifier=GNotifier(parent=self,pref_h=50)
   
   def pid_setup(self,data):
      self.pid=data['pid']
   
   def process_server_input(self,data):
      '''
      receives server messages.
      dispatches methods calls according to server messages.
      '''
      gframe_switch={   network.stc_conf:self.set_conf,
                        network.stc_pid_setup:self.pid_setup
                     }
      gnotifier_switch={   network.stc_tile_ratio_change:GNotifier.update_tile_ratio
                        }
      gmap_switch={  network.stc_new_tile:GMap.new_tile,
                     network.stc_new_home:GMap.new_home,
                     network.stc_new_unit:GMap.new_unit,
                  }
      gunit_switch={ network.stc_unit_add_path:GUnit.add_path,
                     network.stc_unit_move_over:GUnit.finish_move_to,
                     network.stc_tile_change_pawner:GTile.change_pawner,
                  }
      for meta in data:
         if meta in gframe_switch:
            gframe_switch[meta](data[meta])
         elif meta in gnotifier_switch:
            gnotifier_switch[meta](self.gnotifier,data[meta])
         elif meta in gmap_switch:
            gmap_switch[meta](self.gmap,data[meta])
         elif meta in gunit_switch:
            #check designed entity does exist within client
            if not 'eid' in data[meta]:
               out('ERROR in GFrame.process_server_input: eid not specified in packet.\npacket:\n'+str(data[meta]))
            if not data[meta]['eid'] in GEntity.instances:
               out('ERROR in GFrame.process_server_input: eid specified by server ('+str(data[meta]['eid'])+') does not exist client side.\npacket:\n'+str(data[meta]))   
            gunit_switch[meta](GEntity.instances[data[meta]['eid']],data[meta])
         else:
            out('WARNING in GFrame.process_server_input: packet could not get dispatched.\npacket:\n'+str(meta)+':'+str(data[meta]))

   def set_conf(self,conf):
      out('gframe: got config back.')
      if 'map.res' in conf:
         resx=ConfigVariableInt('map-width-'+conf['map.res']).getValue()
         resy=ConfigVariableInt('map-height-'+conf['map.res']).getValue()
         self.gmap.build_tile_matrix(conf['map.res'],resx,resy)
      else: raise Exception('in GFrame.set_conf(%s): gmap resolution not found (\'map.res\')'%str(conf))

   def start_game(self):
      '''
      'start !' animation/text/whatever
      +input handling setup
      '''
      #TODO: make gmenu wait for call to start_accepting for accepting player input. 
      self.gmenu.show()
      self.gmap.start_accepting()
      pass