Skip to content
Browse files

starting to change mouse handling

  • Loading branch information...
1 parent e278dca commit ef59b1af43d725debdf4e9bb2c792c0e81048814 geoffroy committed Jun 23, 2011
Showing with 36 additions and 18 deletions.
  1. +26 −12 src/engine/engine.opa
  2. +10 −6 src/modeler/guiModeler.opa
View
38 src/engine/engine.opa
@@ -312,18 +312,32 @@ initGL(canvas_sel, width, height, get_scene, get_camera_setting, mouse_listener,
gl_pos = { x_px=min(max(m_pos.x_px,0), width-1); y_px=min(max(height - 1 - m_pos.y_px, 0), height-1) };
do Log.debug("P", "[({m_pos.x_px},{m_pos.y_px})] {gl_pos.x_px}, {gl_pos.y_px}");
gl_pos;
- handler_mousedown(e) =
- gl_pos = recompute_pos(e.mouse_position_on_page);
- cont(e) =
- do mode.set({normal});
- mouse_listener(e);
- if not(is_picking(mode.get())) then mode.set({pick=gl_pos; ~cont}) else void;
- _ = Dom.bind(canvas_sel, { mousedown }, handler_mousedown);
- handler_mouseup(e) =
- gl_pos = recompute_pos(e.mouse_position_on_page);
- cont(x, switch) = mouse_listener({mouseup; pos=x; ~switch});
- pending_mouseup.set(List.cons((gl_pos, cont), pending_mouseup.get()));
- _ = Dom.bind(canvas_sel, { mouseup }, handler_mouseup);
+ compute_rel_quarter_pos(abs_full_pos) =
+ match which_box(viewbox, abs_full_pos) with
+ | {out} -> ((0., 0., 0.), {f1})
+ | {_YX} as who | {_YZ} as who | {_ZX} as who | {_3D} as who ->
+ this_viewbox = fetch_box(viewbox, who);
+ some_settings = fetch_box(get_camera_setting(), who);
+ mvMatrix = mat4.copy(some_settings.m);
+ do mat4.inverse(mvMatrix, mvMatrix);
+ (x, y) = rel_pos_in_box(this_viewbox, abs_full_pos);
+ vstart = vec4.from_public((x, y, 1.0, 1.0));
+ vtmp = vec4.from_public((9.9, 9.9, 9.9, 9.9));
+ do mat4.multiplyVec4(mvMatrix, vstart, vtmp);
+ vpreres = vec4.to_public(vtmp);
+ vres = (vpreres.f1 / vpreres.f4, vpreres.f2 / vpreres.f4, vpreres.f3 / vpreres.f4);
+ do Log.debug("Converting coord", "vstart={ vec4.str(vstart) }, \t vres={ vres }");
+ (vres, some_settings.clear_near_far);
+ handler_mousedown(event) =
+ abs_full_pos=recompute_pos(event.mouse_position_on_page);
+ (gl_pos, clear_near_far) = compute_rel_quarter_pos(abs_full_pos);
+ mouse_listener({ mousedown; ~event; ~abs_full_pos; ~gl_pos })
+ do Dom.bind(canvas_sel, { mousedown }, handler_mousedown);
+ handler_mouseup(event) =
+ abs_full_pos=recompute_pos(event.mouse_position_on_page);
+ (gl_pos, clear_near_far) = compute_rel_quarter_pos(abs_full_pos);
+ mouse_listener({ mouseup; ~event; ~gl_pos; switch=clear_near_far })
+ do Dom.bind(canvas_sel, { mouseup }, handler_mouseup);
void;
//Clear screen and make everything light gray // disabled to show png grid
//do Webgl.clearColor(gl, 0.875, 0.875, 0.875, 1.0);
View
16 src/modeler/guiModeler.opa
@@ -141,12 +141,16 @@ type GuiModeler.t = {
do Session.send(central_modelers, {register; ~scene_url; ~sync_channel; ~client_id});
(channel, (-> get_state().modeler.scene), (->get_state().subjects), (->get_state().modeler.views)) ;
support_gpu_picking = Mutable.make(Option.none);
- mouse_listener(e) = match e with
- | { mousedown; ~pos; ~possible_target; ~coord_fixer } ->
- f(gpu_picker_regsiter) = (-> gpu_picker_regsiter(({ x_px=0; y_px=0}, (_ -> void))));
- (Option.switch(f, (-> Session.send(channel, {click_on_scene; where=pos; ~possible_target; last_coord_fixer=coord_fixer})), support_gpu_picking.get()))()
- | { mouseup; ~pos; ~switch } ->
- msg = {modeler_apply_possible_move; where=pos; ~switch };
+ lock_mouse_event = Mutable.make(false);
+ mouse_listener(msg) =
+ match msg with
+ | { mousedown; event=_; ~abs_full_pos; ~gl_pos } ->
+ f(gpu_picker_regsiter) =
+ do lock_mouse_event.set(true);
+ gpu_picker_regsiter((abs_full_pos, (possible_target -> do Session.send(channel, {click_on_scene; where=gl_pos; ~possible_target; last_coord_fixer=Option.none}); lock_mouse_event.set(false)))) ;
+ Option.switch(f, void, support_gpu_picking.get())
+ | { mouseup; event=_; ~gl_pos; ~switch } ->
+ msg = {modeler_apply_possible_move; where=gl_pos; ~switch };
Session.send(channel, msg)
end ;
res = initGL(#{id_canvas_canvas}, width, height, get_scene, get_camera_setting, mouse_listener, support_gpu_picking) ;

0 comments on commit ef59b1a

Please sign in to comment.
Something went wrong with that request. Please try again.