summaryrefslogtreecommitdiff
path: root/demos/viewport/gui_in_3d/gui_3d.gd
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-04-10 00:18:27 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-04-10 00:18:27 -0300
commit7ea3e8267afaf626256c84a9a3dc61e2954fc6a2 (patch)
tree0aa7588918b814d1781fc94e8b518c7095a0bab7 /demos/viewport/gui_in_3d/gui_3d.gd
parentb4969373b3475799d6b24cdffeda4659c37f0b8a (diff)
-Fixed a few bugs in Viewport
-Made a few demos using Viewport to show it's true power! -Fixed some start-up error messages.
Diffstat (limited to 'demos/viewport/gui_in_3d/gui_3d.gd')
-rw-r--r--demos/viewport/gui_in_3d/gui_3d.gd44
1 files changed, 44 insertions, 0 deletions
diff --git a/demos/viewport/gui_in_3d/gui_3d.gd b/demos/viewport/gui_in_3d/gui_3d.gd
new file mode 100644
index 0000000000..5309db9acb
--- /dev/null
+++ b/demos/viewport/gui_in_3d/gui_3d.gd
@@ -0,0 +1,44 @@
+
+extends Spatial
+
+# member variables here, example:
+# var a=2
+# var b="textvar"
+
+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)
+
+ #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
+ 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() )
+ set_process_input(true)
+
+ pass
+
+