summaryrefslogtreecommitdiff
path: root/demos/viewport/gui_in_3d/gui_3d.gd
blob: c2a9df00691abd3170ff2bfb83f954098c1a3f28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

extends Spatial

# member variables here, example:
# var a=2
# var b="textvar"

var prev_pos=null


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)
		
	
#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("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture() )
	set_process_input(true)
	pass