From 78694d85425b35d2c6c0e0a4b0ef3e57375553c6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 11:52:07 -0300 Subject: gui in 3D demo now uses area for input --- demos/viewport/gui_in_3d/gui_3d.gd | 49 ++++++++++++++++++------------------ demos/viewport/gui_in_3d/gui_3d.scn | Bin 3498 -> 4668 bytes 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'demos') diff --git a/demos/viewport/gui_in_3d/gui_3d.gd b/demos/viewport/gui_in_3d/gui_3d.gd index 5309db9acb..c2a9df0069 100644 --- a/demos/viewport/gui_in_3d/gui_3d.gd +++ b/demos/viewport/gui_in_3d/gui_3d.gd @@ -7,38 +7,39 @@ extends Spatial var prev_pos=null -func _input(ev): - if (ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION]): - var pos = ev.pos - var rfrom = get_node("camera").project_ray_origin(pos) - var rnorm = get_node("camera").project_ray_normal(pos) + +func _input( ev ): + #all other (non-mouse) events + if (not ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION,InputEvent.SCREEN_DRAG,InputEvent.SCREEN_TOUCH]): + get_node("viewport").input(ev) - #simple collision test against aligned plane - #for game UIs of this kind consider more complex collision against plane - var p = Plane(Vector3(0,0,1),0).intersects_ray(rfrom,rnorm) - if (p==null): - return - - pos.x=(p.x+1.5)*100 - pos.y=(-p.y+0.75)*100 - ev.pos=pos - ev.global_pos=pos - if (prev_pos==null): - prev_pos=pos - if (ev.type==InputEvent.MOUSE_MOTION): - ev.relative_pos=pos-prev_pos + +#mouse events for area +func _on_area_input_event( camera, ev, click_pos, click_normal, shape_idx ): + + #use click pos (click in 3d space, convert to area space + var pos = get_node("area").get_global_transform().affine_inverse() * click_pos + #convert to 2D + pos = Vector2(pos.x,pos.y) + #convert to viewport coordinate system + pos.x=(pos.x+1.5)*100 + pos.y=(-pos.y+0.75)*100 + #set to event + ev.pos=pos + ev.global_pos=pos + if (prev_pos==null): prev_pos=pos + if (ev.type==InputEvent.MOUSE_MOTION): + ev.relative_pos=pos-prev_pos + prev_pos=pos get_node("viewport").input(ev) - - + func _ready(): # Initalization here - get_node("quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() ) + get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() ) set_process_input(true) - pass - diff --git a/demos/viewport/gui_in_3d/gui_3d.scn b/demos/viewport/gui_in_3d/gui_3d.scn index df8f7d6dc5..c69d4dc73f 100644 Binary files a/demos/viewport/gui_in_3d/gui_3d.scn and b/demos/viewport/gui_in_3d/gui_3d.scn differ -- cgit v1.2.3