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

Function ui_button_behavior_depth

StereoKitC/ui/ui_core.cpp:243–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

241///////////////////////////////////////////
242
243void ui_button_behavior_depth(vec3 window_relative_pos, vec2 size, uint64_t id, float button_depth, float button_activation_depth, float &out_finger_offset, button_state_ &out_button_state, button_state_ &out_focus_state, int32_t* out_opt_hand) {
244 out_button_state = button_state_inactive;
245 out_focus_state = button_state_inactive;
246 int32_t hand = -1;
247
248 // Button interaction focus is detected out in front of the button to
249 // prevent 'reverse' or 'side' presses where the finger comes from the
250 // back or side.
251 //
252 // Once focused is gained, interaction is tracked within a volume that
253 // extends from the detection plane, to a good distance through the
254 // button's back. This is to help when the user's finger inevitably goes
255 // completely through the button. Width and height is added to this
256 // volume to account for vertical or horizontal movement during a press,
257 // such as the downward motion often accompanying a 'poke' motion.
258 float activation_plane = button_depth + skui_finger_radius*2;
259 vec3 activation_start = window_relative_pos + vec3{ 0, 0, -activation_plane };
260 vec3 activation_size = vec3{ size.x, size.y, 0.0001f };
261
262 vec3 box_size = vec3{ size.x + 2*skui_finger_radius, size.y + 2*skui_finger_radius, activation_plane + 6*skui_finger_radius };
263 vec3 box_start = window_relative_pos + vec3{ skui_finger_radius, skui_finger_radius, -activation_plane + box_size.z };
264 ui_box_interaction_1h_poke(id,
265 activation_start, activation_size,
266 box_start, box_size,
267 &out_focus_state, &hand);
268
269 // If a hand is interacting, adjust the button surface accordingly
270 out_finger_offset = button_depth;
271 if (out_focus_state & button_state_active) {
272 out_finger_offset = -(skui_hand[hand].finger.z+skui_finger_radius) - window_relative_pos.z;
273 bool pressed = out_finger_offset < button_activation_depth;
274 out_button_state = ui_active_set(hand, id, pressed);
275 out_finger_offset = fminf(fmaxf(2*mm2m, out_finger_offset), button_depth);
276 } else if (out_focus_state & button_state_just_inactive) {
277 out_button_state = ui_active_set(hand, id, false);
278 }
279
280 if (out_button_state & button_state_just_active)
281 ui_play_sound_on_off(ui_vis_button, id, skui_hand[hand].finger_world);
282
283 if (out_opt_hand)
284 *out_opt_hand = hand;
285}
286
287///////////////////////////////////////////
288

Callers 1

ui_button_behaviorFunction · 0.85

Calls 3

ui_active_setFunction · 0.85
ui_play_sound_on_offFunction · 0.85

Tested by

no test coverage detected