This repository has been archived by the owner on Dec 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_parameters_OSC.cpp
100 lines (79 loc) · 2.79 KB
/
02_parameters_OSC.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "al/core/app/al_App.hpp"
#include "al/core/graphics/al_Shapes.hpp"
#include "al/util/ui/al_Parameter.hpp"
#include "al/util/ui/al_ControlGUI.hpp"
using namespace al;
/* A simple App that draws a cone on the screen
* Parameters are exposed via OSC.
*/
class MyApp : public App
{
public:
virtual void onCreate() override {
// Set the camera to view the scene
nav().pos(Vec3d(0,0,8));
// Prepare mesh to draw a cone
addCone(mesh);
mesh.primitive(Mesh::LINE_STRIP);
// Register the parameters with the GUI
gui << X << Y << Size;
gui.init(); // Initialize GUI. Don't forget this!
/*
Parameters need to be added to the ParameterServer by using the
streaming operator <<.
*/
parameterServer() << X << Y << Size; // Add parameters to parameter server
/*
You can add an OSC listener to a parameter server. Any change to any
parameter will be broadcast to the OSC address and port registered using the
addListener() function.
*/
parameterServer().addListener("127.0.0.1", 13560);
/*
The print function of the ParameterServer object provides information
on the server, including the paths to all registered parameters.
You will see a cone on the screen. I will not move until you send OSC
messages with values to any of these addresses:
Parameter X : /Position/X
Parameter Y : /Position/Y
Parameter Scale : /Size/Scale
*/
parameterServer().print();
}
virtual void onAnimate(double dt) override {
// You will want to disable navigation and text if the mouse is within
// the gui window. You need to do this within the onAnimate callback
navControl().active(!gui.usingInput());
}
virtual void onDraw(Graphics &g) override
{
g.clear();
g.pushMatrix();
// You can get a parameter's value using the get() member function
g.translate(X.get(), Y.get(), 0);
g.scale(Size.get());
g.draw(mesh); // Draw the mesh
g.popMatrix();
// Draw th GUI
gui.draw(g);
}
private:
Mesh mesh;
/*
The parameter's name is the first argument, followed by the name of the
group it belongs to. The group is used in particular by OSC to construct
the access address. The "prefix" is similar to group in this respect
as is prefixes the text to the address.
*/
Parameter X {"X", "Position", 0.0, "", -1.0f, 1.0f};
Parameter Y {"Y", "Position", 0.0, "", -1.0f, 1.0f};
Parameter Size {"Scale", "Size", 1.0, "", 0.1f, 3.0f};
ControlGUI gui;
};
int main(int argc, char *argv[])
{
MyApp app;
app.dimensions(800, 600);
app.start();
return 0;
}