Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include "allocore/io/al_App.hpp"
  2. using namespace al;
  3. using namespace std;
  4.  
  5. struct MyApp : App, osc::PacketHandler {
  6. MyApp() {
  7. initWindow();
  8. initAudio();
  9. // I listen on 60777
  10. oscRecv().open(60777, "", 0.016, Socket::UDP);
  11. oscRecv().handler(*this);
  12. oscRecv().start();
  13. // you better be listening on 60777
  14. oscSend().open(60777, "192.168.1.149", 0.016, Socket::UDP);
  15. addSphere(them);
  16. }
  17. Mesh them;
  18. Pose other;
  19. void onAnimate(double dt) {
  20. oscSend().send("/xyz", nav().pos().x, nav().pos().y, nav().pos().z);
  21. oscSend().send("/xyzw", nav().quat().x, nav().quat().y, nav().quat().z,
  22. nav().quat().w);
  23. }
  24. void onMessage(osc::Message& m) {
  25. if (m.addressPattern() == "/xyz") {
  26. Vec3f o;
  27. m >> o.x;
  28. m >> o.y;
  29. m >> o.z;
  30. other.pos(o);
  31. } else if (m.addressPattern() == "/xyzw") {
  32. Quatf q;
  33. m >> q.x;
  34. m >> q.y;
  35. m >> q.z;
  36. m >> q.w;
  37. other.quat(q);
  38. } else
  39. m.print();
  40. }
  41.  
  42. void onDraw(Graphics& g) {
  43. g.translate(other.pos());
  44. g.rotate(other.quat());
  45. g.draw(them);
  46. }
  47. };
  48.  
  49. int main() { MyApp().start(); }
Add Comment
Please, Sign In to add comment