Created
February 8, 2018 21:30
-
-
Save kybr/178b948a61fce4049ceda785f7e4b645 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "allocore/io/al_App.hpp" | |
using namespace al; | |
using namespace std; | |
struct MyApp : App, osc::PacketHandler { | |
MyApp() { | |
initWindow(); | |
initAudio(); | |
// I listen on 60777 | |
oscRecv().open(60777, "", 0.016, Socket::UDP); | |
oscRecv().handler(*this); | |
oscRecv().start(); | |
// you better be listening on 60777 | |
oscSend().open(60777, "192.168.1.149", 0.016, Socket::UDP); | |
addSphere(them); | |
} | |
Mesh them; | |
Pose other; | |
void onAnimate(double dt) { | |
oscSend().send("/xyz", nav().pos().x, nav().pos().y, nav().pos().z); | |
oscSend().send("/xyzw", nav().quat().x, nav().quat().y, nav().quat().z, | |
nav().quat().w); | |
} | |
void onMessage(osc::Message& m) { | |
if (m.addressPattern() == "/xyz") { | |
Vec3f o; | |
m >> o.x; | |
m >> o.y; | |
m >> o.z; | |
other.pos(o); | |
} else if (m.addressPattern() == "/xyzw") { | |
Quatf q; | |
m >> q.x; | |
m >> q.y; | |
m >> q.z; | |
m >> q.w; | |
other.quat(q); | |
} else | |
m.print(); | |
} | |
void onDraw(Graphics& g) { | |
g.translate(other.pos()); | |
g.rotate(other.quat()); | |
g.draw(them); | |
} | |
}; | |
int main() { MyApp().start(); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment