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

Function input_hand_init

StereoKitC/hands/input_hand.cpp:178–278  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176///////////////////////////////////////////
177
178void input_hand_init() {
179 input_hand_pointer_id[handed_left ] = input_add_pointer(input_source_hand | input_source_hand_left | input_source_can_press);
180 input_hand_pointer_id[handed_right] = input_add_pointer(input_source_hand | input_source_hand_right | input_source_can_press);
181
182 float blend = 1;
183 for (int32_t i = 0; i < _countof(hand_sources); i++) {
184 if (hand_sources[i].system == hand_system_oxr_controllers) {
185 blend = hand_sources[i].pinch_blend;
186 break;
187 }
188 }
189 vec3 from_pt = vec3_lerp(input_pose_neutral[4].position, input_pose_neutral[5+4].position, blend);
190 vec3 grab_pt = vec3_lerp(input_pose_pinch [4].position, input_pose_pinch [5+4].position, blend);
191 vec3 offset = from_pt - grab_pt;
192 for (int32_t i = 0; i < 25; i++) {
193 input_pose_pinch[i].position += offset;
194 }
195
196 input_hand_sim_pose_add(input_pose_neutral, controller_key_none);
197 input_hand_sim_pose_add(input_pose_pinch, controller_key_trigger, controller_key_none, key_mouse_left);
198 input_hand_sim_pose_add(input_pose_point, controller_key_grip, controller_key_none, key_mouse_right);
199 input_hand_sim_pose_add(input_pose_fist, controller_key_trigger, controller_key_grip, key_mouse_left, key_mouse_right);
200
201 material_t hand_mat = material_copy_id(default_id_material);
202 material_set_id (hand_mat, default_id_material_hand);
203 material_set_transparency(hand_mat, transparency_blend);
204
205 gradient_t color_grad = gradient_create();
206 // Snapdragon's implementation of XR_MSFT_hand_tracking_mesh does not work
207 // well with SK's implementation of UV generation just yet, so we set it to
208 // pure white for now instead. Users can always opt out of the extension if
209 // they prefer the fallback hand mesh.
210 if (strstr(device_get_runtime(), "Snapdragon") != nullptr && backend_openxr_ext_enabled("XR_MSFT_hand_tracking_mesh")) {
211 gradient_add(color_grad, color128{ 1,1,1,1 }, 0.0f);
212 gradient_add(color_grad, color128{ 1,1,1,1 }, 1.0f);
213 } else {
214 gradient_add(color_grad, color128{ .4f,.4f,.4f,0 }, 0.0f);
215 gradient_add(color_grad, color128{ .6f,.6f,.6f,0 }, 0.4f);
216 gradient_add(color_grad, color128{ .8f,.8f,.8f,1 }, 0.55f);
217 gradient_add(color_grad, color128{ 1, 1, 1, 1 }, 1.0f);
218 }
219
220 color32 gradient[16 * 16];
221 for (int32_t y = 0; y < 16; y++) {
222 color32 col = gradient_get32(color_grad, 1-y/15.f);
223 for (int32_t x = 0; x < 16; x++) {
224 gradient[x + y * 16] = col;
225 } }
226 gradient_release(color_grad);
227
228 tex_t gradient_tex = tex_create(tex_type_image, tex_format_rgba32_linear);
229 tex_set_colors (gradient_tex, 16, 16, gradient);
230 tex_set_address(gradient_tex, tex_address_clamp);
231 material_set_texture (hand_mat, "diffuse", gradient_tex);
232 material_set_queue_offset(hand_mat, 10);
233
234 // Initialize the hands!
235 for (int32_t i = 0; i < handed_max; i++) {

Callers 1

input_initFunction · 0.85

Calls 15

input_add_pointerFunction · 0.85
vec3_lerpFunction · 0.85
input_hand_sim_pose_addFunction · 0.85
material_copy_idFunction · 0.85
material_set_idFunction · 0.85
gradient_createFunction · 0.85
device_get_runtimeFunction · 0.85
gradient_addFunction · 0.85
gradient_get32Function · 0.85
gradient_releaseFunction · 0.85
tex_createFunction · 0.85

Tested by

no test coverage detected