Пример #1
0
  private void runOSCSun(int port) {
    sunPosition = controller.getLightPosition();
    try {
      final Timer timer =
          new Timer(
              50,
              new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                  Vec3 p = controller.getLightPosition();
                  Vec3 q = new Vec3(sunPosition.x - p.x, sunPosition.y - p.y, 0).scale(0.1f);
                  controller.setLightPosition(q);
                  controller.repaint();
                }
              });

      OSCServer oscServerSun = new OSCServer(port, null);
      // oscserver = new OSCServer(port, "224.0.1.0");
      oscServerSun.installHandler(
          "/",
          new OSCHandler() {
            @Override
            public Object[] handle(
                String[] address,
                int addrIdx,
                StringBuilder typeString,
                long timestamp,
                Object... args) {
              try {
                // /address[1]/address[2]/...
                // double someValue =
                if (args.length >= 2) {
                  sunPosition =
                      new Vec3(
                          ((Float) args[0]).floatValue() / 100.0f * 5,
                          ((Float) args[1]).floatValue() / 100.0f * 5,
                          0);
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              return null;
            }
          });
      timer.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #2
0
 private void runOSCScan(int port) {
   try {
     OSCServer oscServerScan = new OSCServer(port, "224.0.1.0");
     oscServerScan.installHandler(
         "/",
         new OSCHandler() {
           @Override
           public Object[] handle(
               String[] address,
               int addrIdx,
               StringBuilder typeString,
               long timestamp,
               Object... args) {
             try {
               System.out.println("osc args: " + args.length);
               // /address[1]/address[2]/...
               // double someValue =
               // ((Number)args[0]).doubleValue();
               ArrayList<ArrayList<Number>> objects = new ArrayList<>();
               ArrayList<Number> object = new ArrayList<>();
               for (int i = 1; i < args.length; ) {
                 if (args[i] instanceof String) {
                   objects.add(object);
                   object = new ArrayList<>();
                   i++;
                 } else {
                   object.add((Number) args[i]);
                   object.add((Number) args[i + 1]);
                   object.add((Number) args[i + 2]);
                   i += 3;
                 }
               }
               createGeometry(objects);
             } catch (Exception e) {
               e.printStackTrace();
             }
             return null;
           }
         });
   } catch (Exception e) {
     e.printStackTrace();
   }
 }