예제 #1
0
 def draw_inputs(self, context):
   inputs = self.target.receives()
   i = 0
   for label in inputs:
     x = -0.55
     y = -0.45 + (i * (1.0 / len(inputs)))
     Primitives.connector(context, x, y, label, 0.0, 0.0, 1.0)
     i = i + 1
예제 #2
0
  def draw(self, context):
    Thing.draw(self, context)
    
    self.text = self.target.__class__.__name__ # + "\n" + self.target.code
    
    # figure out scale factor to fit text to thing size
    scale = min(1.0 / self.pixel_width, 1.0 / self.pixel_height) / 2.0
    
    # draw connectors
    self.draw_inputs(context)
    #self.draw_outputs(context)

    # render the text
    context.save()
    context.move_to(-0.3, -0.5)
    context.scale(scale, scale)
    context.set_source_rgba(0.0, 0.0, 0.0, 1.0)
    context.show_layout(self.layout)        
    context.restore()
 
    # render box
    Primitives.panel(context, -0.5, -0.5, 1.0, 1.0, 0.05)
예제 #3
0
  def draw(self, context):
    now_time = time.time()
    remove_list = []
    
    for body in self.ode_bodies:
      # check particle age
      body_age = now_time - body.create_time
      if random() <= (body_age / self.particle_life):
        remove_list.append(body)
        self.output_buffer_count += 1
        continue
        
      # render body
      x,y,z = body.getPosition()
      if x > TheWorld.unit_range:
        x = TheWorld.unit_range 
      if x < -TheWorld.unit_range:
        x = -TheWorld.unit_range 
      if y > TheWorld.unit_range:
        y = TheWorld.unit_range
      if y < -TheWorld.unit_range:
        y = -TheWorld.unit_range
        
      context.set_line_width(0.5)
      context.move_to(x+BSIZE,y)
      r1,g1,b1 = body.color
      context.set_source_rgba(r1, g1, b1, 1.0 - (body_age / self.particle_life * 100.0))
      context.arc(x, y, BSIZE, 0, math.pi * 2.0)
      context.fill()
      
      # reset colors
      #body.color = (0.0,g1,1.0)      
      
    for body in remove_list:
      self.ode_space.remove(body.geom)
      self.ode_bodies.remove(body)
      # add body to output buffer
      self.output_buffer.append(body)
      
    # render rotor
    if self.rotor is not None:
      
      self.align_z_axis(self.rotor) # restrict rotation to 2D      
      rotor = self.rotor
      x,y,z = rotor.getPosition()
      R = rotor.getRotation()
      
      # convert rotation matrix to euler angle
      #if (R[3] > 0.998): # singularity at north pole
        #heading = math.atan2(R[2], R[8])
        #attitude = math.pi/2.0
        #bank = 0.0
      #elif (R[3] < -0.998): # singularity at south pole
        #heading = math.atan2(R[2], R[8])
        #attitude = -math.pi/2.0
        #bank = 0
      #else:
      heading = math.atan2(-R[6],R[0]);
      bank = math.atan2(-R[5],R[4]);
      attitude = math.asin(R[3]);
      if heading < -3.14 or heading > 3.14:
        heading = 0.0
      if bank < -3.14 or bank > 3.14:
        bank = 0.0
      #print heading, bank, attitude
      
      context.save()
      r = math.acos((R[0] + R[4] + R[8] - 1.0) / 2.0)  
      #r = MathLib.matrix_to_euler(R)
      if math.degrees(attitude) < 0:
        r = math.radians((180.0 - math.degrees(r)) + 180.0)
      #print x, y, "rotate=", math.degrees(attitude), " -> ", math.degrees(r)
      #print MathLib.matrix_to_rotation(R)
      context.translate(x,y)
      #context.rotate(attitude)
      context.rotate(r)
      context.set_source_rgba(0.0,0.0,0.0,1.0)
      context.rectangle(-rotor.w/2.0, -rotor.h/2.0, rotor.w, rotor.h)
      context.fill()
      context.restore()    
    
    # render walls
    for wall in self.ode_walls:
      x,y,z = wall.getPosition()
      context.set_source_rgba(0.0, 1.0, 0.0, 1.0)
      context.rectangle(x-(wall.w/2.0), y-(wall.h/2.0), wall.w, wall.h)
      context.fill()

    # tank
    Primitives.rounded_rectangle_bling(context, -TheWorld.unit_range, -TheWorld.unit_range, TheWorld.unit_range*2.0, TheWorld.unit_range*2.0, r = 10, padding = 0.0)

    # update physics
    self.ode_space.collide((self.ode, self.ode_contactgroup), self.ode_collide_callback)
    if (TheWorld.framerate > 0):
      self.ode.step(1.0/(TheWorld.framerate*10.0)) #TheSpaceTime.ticks_increment)  
    else:
      self.ode.step(1.0/(16.0 * 10.0))
    self.ode_contactgroup.empty()
    
    
    
예제 #4
0
 def draw_outputs(self, context):
   num_outputs = 2
   for i in range(num_outputs):
     x = 0.25
     y = -0.45 + (i * (1.0 / num_outputs))
     Primitives.connector(context, x, y, '', 1.0, 0.0, 0.0)