MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / demo_lines_draw

Function demo_lines_draw

Examples/StereoKitCTest/demo_lines.cpp:71–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69///////////////////////////////////////////
70
71void demo_lines_draw() {
72 const hand_t *hand = input_hand(handed_right);
73 vec3 tip = hand->fingers[1][4].position;
74 tip = line_prev_tip + (tip-line_prev_tip) * 0.3f;
75
76 if ((hand->pinch_state & button_state_just_active) && !ui_is_interacting(handed_right)) {
77
78 if (line_draw.size() > 0)
79 line_list.push_back(line_draw);
80 line_draw.clear();
81 line_draw.push_back(line_point_t{tip, line_size, line_color});
82 line_draw.push_back(line_point_t{tip, line_size, line_color});
83 line_prev_tip = tip;
84 line_painting = true;
85 }
86 if (hand->pinch_state & button_state_just_inactive)
87 line_painting = false;
88
89 if (line_painting && line_draw.size() > 1)
90 {
91 vec3 prev = line_draw[line_draw.size() - 2].pt;
92 vec3 dir = vec3_normalize(prev - (line_draw.size() > 2 ? line_draw[line_draw.size() - 3].pt : line_draw[line_draw.size() - 1].pt));
93 float dist = vec3_magnitude(prev - tip);
94 float speed = vec3_magnitude(tip - line_prev_tip) * time_stepf();
95 line_point_t here = line_point_t{tip, max(1-speed/0.0003f,0.1f) * line_size, line_color};
96
97 if ((vec3_dot( dir, vec3_normalize(tip-prev)) < 0.2f && dist > 0.001f) || dist > 0.005f) {
98 line_draw.push_back(here);
99 } else {
100 line_draw[line_draw.size() - 1] = here;
101 }
102 }
103
104 line_add_listv(line_draw.data(), (int32_t)line_draw.size());
105 for (size_t i = 0; i < line_list.size(); i++)
106 line_add_listv(&line_list[i][0], (int32_t)line_list[i].size());
107 line_prev_tip = tip;
108}
109
110///////////////////////////////////////////
111

Callers 1

demo_lines_updateFunction · 0.85

Calls 8

input_handFunction · 0.85
ui_is_interactingFunction · 0.85
vec3_normalizeFunction · 0.85
vec3_magnitudeFunction · 0.85
time_stepfFunction · 0.85
vec3_dotFunction · 0.85
line_add_listvFunction · 0.85
clearMethod · 0.80

Tested by

no test coverage detected