-
- /*
- * this raycasting is super cumbersome because all the functions were
- * designed for other purposes. we dont care though.
- */
- m4x4f inverse;
- m4x4_inv( menu.view.mtx.p, inverse );
- v4f coords;
- coords[0] = vg_ui.mouse[0];
- coords[1] = vg.window_y - vg_ui.mouse[1];
- v2_div( coords, (v2f){ vg.window_x, vg.window_y }, coords );
- v2_muls( coords, 2.0f, coords );
- v2_add( coords, (v2f){-1.0f,-1.0f}, coords );
- coords[2] = 1.0f;
- coords[3] = 1.0f;
- m4x4_mulv( inverse, coords, coords );
- v3f ray;
- m3x3_mulv( menu.view.transform, coords, ray );
- v3_normalize( ray );
-
- if( menu.loc && (menu.loc->type == k_ent_menuitem_type_slider) &&
- ui_clicking(UI_MOUSE_LEFT) && menu.loc->pf32 ){
-
- u32 il = mdl_entity_id_id( menu.loc->slider.id_min ),
- ir = mdl_entity_id_id( menu.loc->slider.id_max );
- ent_marker *ml = mdl_arritm( &menu.markers, il ),
- *mr = mdl_arritm( &menu.markers, ir );
-
- v3f q2;
- v3_muladds( menu.view.pos, ray, 100.0f, q2 );
-
- f32 s,t;
- v3f c1, c2;
- v3f p1, q1, v0;
- v3_sub( mr->transform.co, ml->transform.co, v0 );
- v3_muladds( ml->transform.co, v0, -1.0f, p1 );
- v3_muladds( mr->transform.co, v0, 1.0f, q1 );
- closest_segment_segment( p1, q1, menu.view.pos, q2, &s,&t, c1,c2 );
-
- s-=(1.0f/3.0f);
- s/=(1.0f/3.0f);
-
- if( ui_click_down(UI_MOUSE_LEFT) ){
- menu.slider_offset = *menu.loc->pf32 - s;
- }
-
- f32 newvalue = vg_clampf( s+menu.slider_offset, 0.0f, 1.0f );
-
- newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.00f );
- newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 1.00f );
- newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.25f );
- newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.50f );
- newvalue = menu_slider_snap( newvalue, *menu.loc->pf32, 0.75f );
-
- *menu.loc->pf32 = newvalue;
- return;
- }
-
- ent_menuitem *hit_item = NULL;
-
- for( u32 i=0; i<mdl_arrcount(&menu.items); i++ ){
- ent_menuitem *item = mdl_arritm( &menu.items, i );
-
- if( item->type == k_ent_menuitem_type_page ) continue;
- if( (item->type == k_ent_menuitem_type_visual) ||
- (item->type == k_ent_menuitem_type_visual_nocol) ) continue;
- if( item->type == k_ent_menuitem_type_binding ) continue;
- if( !(item->groups & (0x1<<menu.page)) ) continue;
-
- ent_menuitem *ray_item = item;
-
- if( item->type == k_ent_menuitem_type_slider ){
- u32 subtarget = mdl_entity_id_id( item->slider.id_handle );
- ray_item = mdl_arritm( &menu.items, subtarget );
- }
-
- v3f local_ray,
- local_co;
-
- m4x3f inverse_mtx;
- mdl_transform_m4x3( &ray_item->transform, inverse_mtx );
- m4x3_invert_full( inverse_mtx, inverse_mtx );
-
- m4x3_mulv( inverse_mtx, menu.view.transform[3], local_co );
- m3x3_mulv( inverse_mtx, ray, local_ray );
- v3_normalize( local_ray );
-
- local_ray[0] = 1.0f/local_ray[0];
- local_ray[1] = 1.0f/local_ray[1];
- local_ray[2] = 1.0f/local_ray[2];
-
- for( u32 j=0; j<ray_item->submesh_count; j++ ){
- mdl_submesh *sm = mdl_arritm( &menu.model.submeshs,
- ray_item->submesh_start + j );
- if( ray_aabb1( sm->bbx, local_co, local_ray, 1000.0f ) ){
- hit_item = item;
- break;
- }
- }
- }
-
- if( hit_item != menu.loc ){
- menu.loc = hit_item;
- }
-
- if( escape ){
- menu_back_page();
- }
- else if( menu.loc ){
- if( ui_click_down( UI_MOUSE_LEFT ) )
- {
- menu_trigger_item( menu.loc );
- }
- }