Repository navigation
Expand file tree
/
Copy pathplay_events.cpp
More file actions
53 lines (38 loc) · 1.73 KB
/
Copy pathplay_events.cpp
File metadata and controls
53 lines (38 loc) · 1.73 KB
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
// play_events.cpp - play an event from your workspace, then shape it at runtime:
// strength, speed, rotation around the body, vertical offset, looping and stopping.
//
// play_events <sdk_api_key> <workspace_id> <event>
// (or set BHAPTICS_SDK_API_KEY, BHAPTICS_WORKSPACE_ID, BHAPTICS_EVENT)
#include "example_common.hpp"
using namespace example;
namespace {
void step(const char* what) { std::printf("\n> %s\n", what); }
} // namespace
int main(int argc, char** argv) {
Args args;
if (!parse_args(argc, argv, args, /*needs_event=*/true)) return 2;
Session session(args);
if (!session) return 1;
const char* event = args.event;
std::printf("Event \"%s\" lasts %d ms\n", event, getEventTime(event));
step("As designed");
wait_until_done(play(event));
step("Half strength");
wait_until_done(playParam(event, kAutoId, /*intensity=*/0.5f, /*duration=*/1.0f, 0.0f, 0.0f));
step("Twice as long");
wait_until_done(playParam(event, kAutoId, 1.0f, /*duration=*/2.0f, 0.0f, 0.0f));
// angleX rotates the pattern around the body (0-360 degrees): 180 moves front to back.
step("Rotated 180 degrees");
wait_until_done(playParam(event, kAutoId, 1.0f, 1.0f, /*angleX=*/180.0f, 0.0f));
// offsetY shifts it vertically (-0.5 up ... 0.5 down).
step("Shifted down");
wait_until_done(playParam(event, kAutoId, 1.0f, 1.0f, 0.0f, /*offsetY=*/0.3f));
step("Three times, 300 ms apart");
wait_until_done(playLoop(event, kAutoId, 1.0f, 1.0f, 0.0f, 0.0f, /*interval=*/300, /*maxCount=*/3));
step("Looping until stopped after 2 s");
const int32_t loop = playLoop(event, kAutoId, 1.0f, 1.0f, 0.0f, 0.0f, 300, 1000);
sleep_for(2s);
stop(loop);
std::puts("\nDone.");
return 0;
}