-- test application for table tracker -- draws a cursor for each device that is placed on the table. -- see do_timer() for code that parses tracker update messages new_x, new_y, new_a = 0, 0, 0 myport = 7000 device = {} function create_scene() camera = E.create_camera(E.camera_type_orthogonal) pivot = E.create_pivot() E.parent_entity(pivot, camera) dsp_x0, dsp_y0, dsp_w, dsp_h = E.get_display_union() E.set_entity_position(pivot, dsp_x0 + dsp_w/2, dsp_y0 + dsp_h/2, 0) brush_line = E.create_brush() brush_fill = E.create_brush() E.set_brush_color(brush_line, 0.2, 0.2, 0.5, 1.0) E.set_brush_color(brush_fill, 0.8, 0.8, 0.8, 1.0) end function mark_sprite(id) local id_string = E.create_string(string.format("%d", id)) local pivot = E.create_pivot () E.set_entity_scale (id_string, 32, 32, 32) E.set_entity_position(id_string, 96, 96, 0 ) E.set_string_line (id_string, brush_line) E.set_string_fill (id_string, brush_fill) E.parent_entity(id_string, pivot) return pivot end function make_sprite(filename, trans, unlit ) local image = E.create_image(filename) local brush = E.create_brush() E.set_brush_flags(brush, E.brush_flag_transparent, trans) E.set_brush_flags(brush, E.brush_flag_unlit, unlit) E.set_brush_color(brush, 1.0, 1.0, 1.0, 1.0) E.set_brush_image(brush, image) local sprite = E.create_sprite(brush) E.set_entity_position(sprite, -128, -128, 0) return E.create_sprite(brush) end function show_device(dev, type) for i=1, 3 do E.set_entity_flags(dev[i], E.entity_flag_hidden, not (i == type)) end end function do_timer(dt) local update = false while TT.poll(0) do local stat, msg_id, msg_xpos, msg_ypos, msg_angle, msg_type = TT.get() if stat == TT.OK then update = true E.print_console("received: " .. msg_id .. ", " .. msg_xpos .. ", " .. msg_ypos .. ", " .. msg_angle .. ", " .. msg_type .. "\n") -- if received a message for a new device, create the device if not device[msg_id] then local id = msg_id device[id] = {} device[id][1] = make_sprite("data/mark.png", true, true) device[id][2] = make_sprite("data/mark_left.png", true, true) device[id][3] = make_sprite("data/mark_right.png", true, true) device[id].id = mark_sprite(id) device[id].pv = E.create_pivot() local dgram E.parent_entity(device[id][1], device[id].pv) E.parent_entity(device[id][2], device[id].pv) E.parent_entity(device[id][3], device[id].pv) E.parent_entity(device[id].id, device[id].pv) E.parent_entity(device[id].pv, pivot) end show_device(device[msg_id], msg_type) -- update location of device new_x = msg_xpos * dsp_w + dsp_x0 new_y = msg_ypos * dsp_h + dsp_y0 new_a = msg_angle local x, y, a = new_x, new_y, new_a E.set_entity_rotation(device[msg_id].pv, 0, 0, a) E.set_entity_position(device[msg_id].pv, x, y, 0) end end return update end function do_start() create_scene() E.set_typeface("data/VeraBd.ttf", 0.0001, 0.03125) -- Open port to listen for track data TT.open(myport) E.enable_timer(true) end do_start()