From 78694d85425b35d2c6c0e0a4b0ef3e57375553c6 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 22 Mar 2015 11:52:07 -0300 Subject: [PATCH] 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 scene/3d/spatial.cpp | 7 ++++ scene/3d/spatial.h | 1 + 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/demos/viewport/gui_in_3d/gui_3d.gd b/demos/viewport/gui_in_3d/gui_3d.gd index 5309db9acb7..c2a9df00691 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 df8f7d6dc5c360c29bb4df9c7c7eff3d241b48cc..c69d4dc73fad64fbe33e24bd3ca5dcb034aea6f0 100644 GIT binary patch literal 4668 zcmYjV3v?URnf_-+^2m}Mzhftk<10IfA4#k{NCI&j|0Bsx^MIsrfRYC@BWWxTmS)7v z$gxAa5lL7eDGNPWLV+zPNhyzz!xq?P*&JXJLl+3_($cbJyOc3tN`aPLpocx}N!ee9 zwySgQH~+nJ=f3~{`>wVR#bQwURRio<2#^aS-YS3?Td&9BGaUHL<5y>$7uOG9M0kLY+^` z>b4!d2=&xOS%)BNi^-vU`(nRvh*kRAui6S@jDAS z9Z6@*Dc{HxUj^mtP9Z-gkH-#iP{S&~Y1;$&_JRj*;Tcb?=Vd3UyyJ0=%2SCEudEKc zqg5Wvo`MC?;0al`!3*?ELBHqgaT~BFy4VZsQFp=|uR;wwxH>-K!D=<^`Tm48xG1&m zT-}X_J^y7bQyn66S6tOP;-Pl=_@G=yHq-i+H5@cA7%ND-R8@4`Z3O0nHu!Vuo zCI5D@9q&^tDx436`M4TEto`Nj{^yQ~=m}NACvRCug%9(No+U@(cQA7NeyQMwm2adL zxEJs-o+5(UP5nL+O?yKZgu^!u^fSu`AH~dmydZpM+a1rcSxS}ruvd8@_K+JcT-fk{ zdqKJjTjDkDh3Kc=k_(6o)VnCGOjX>AZTPJ3vEFZ=g93#atO_=D-hFO){$HdI<9|?3 zc|t4RKj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y;t2l106K)S;c!;=W!Pk~TbByY%SVL58a+W3rUo9^PRqB?A_ zmUY62k$GBXYtylTCgcUDBe8>+)~va>7CaW-(esg1G}XLWwCrhv z2|Kio#LXduCEekd!`e zF>%$Ar_(QKYs1d;v}gMHo3!|rA0;{xKT~djLULit{TPKzEt;FjZfO(un^>(X+5AqbYvcy7JV2sY!6$!k6h9+6jinkTkQvw})>Me8c5 zNks8m_z0$$dgpcybgAi>d^2+6LY(hEY zOnVTet(!~O)|@G0mcc*OEq^z5AyjZp)9$^1G#l>KvbQlFb&q5K z)@1NWKIH^&68;8B2QycFa!|Xk~Uw+IRcM9Je>z;hz+}l5W>b!X@hbKNYty%2T=`4vNw4G25BMEH;3$`26>Y){KR@?G zt_z>yw$EY#TIeQx4_c{&NBEv`XrpodW&rQv?3-)poj8}ih*Iu6O0br8bGeSsJ$>Vc zct-g&o`G)4qn}3?Bxp>T#E0-MAqlnfoSaCw482^Q;nYOJ^PHMU_&rWd_(`y7QG$N1 zUEthAQZn`RgEWQ&3pmBwhj=4?0-O19|Hj#h#O2Ucnc~Z~Ufp0Dm!H5eUtFgr5;uH1 zmmcRP5~{G1kN0psBH_XM*4Ob;buA@$l7H21D)Vm`<*z0=NsyF-oFdfa7?&fNwfITT mqk54O07)tGrFhqh^xrtDoV@AmmtNqJ18`vKK;{7dm-au=SRC>I diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index edca62ece51..6e118555434 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -660,6 +660,12 @@ void Spatial::orthonormalize() { } +void Spatial::set_identity() { + + set_transform(Transform()); + +} + void Spatial::look_at(const Vector3& p_target, const Vector3& p_up_normal) { @@ -735,6 +741,7 @@ void Spatial::_bind_methods() { ObjectTypeDB::bind_method( _MD("translate","offset"),&Spatial::translate ); ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); + ObjectTypeDB::bind_method( _MD("set_identity"),&Spatial::set_identity ); ObjectTypeDB::bind_method( _MD("look_at","target","up"),&Spatial::look_at ); ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); diff --git a/scene/3d/spatial.h b/scene/3d/spatial.h index d7addbb7922..f2cde8f1e63 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/spatial.h @@ -180,6 +180,7 @@ public: void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void orthonormalize(); + void set_identity(); void show(); void hide();