2014-04-10 05:18:27 +02:00
|
|
|
|
|
|
|
extends Spatial
|
|
|
|
|
2015-11-21 13:31:25 +01:00
|
|
|
# Member variables
|
2015-12-09 08:38:23 +01:00
|
|
|
var prev_pos = null
|
|
|
|
|
|
|
|
|
|
|
|
func _input(event):
|
2015-11-21 13:31:25 +01:00
|
|
|
# All other (non-mouse) events
|
2015-12-09 08:38:23 +01:00
|
|
|
if (not event.type in [InputEvent.MOUSE_BUTTON, InputEvent.MOUSE_MOTION, InputEvent.SCREEN_DRAG, InputEvent.SCREEN_TOUCH]):
|
|
|
|
get_node("viewport").input(event)
|
|
|
|
|
|
|
|
|
2015-11-21 13:31:25 +01:00
|
|
|
# Mouse events for Area
|
2015-12-09 08:38:23 +01:00
|
|
|
func _on_area_input_event(camera, event, click_pos, click_normal, shape_idx):
|
2015-11-21 13:31:25 +01:00
|
|
|
# Use click pos (click in 3d space, convert to area space)
|
2015-12-09 08:38:23 +01:00
|
|
|
var pos = get_node("area").get_global_transform().affine_inverse()*click_pos
|
2015-11-21 13:31:25 +01:00
|
|
|
# Convert to 2D
|
2015-12-09 08:38:23 +01:00
|
|
|
pos = Vector2(pos.x, pos.y)
|
2015-11-21 13:31:25 +01:00
|
|
|
# Convert to viewport coordinate system
|
2015-12-09 08:38:23 +01:00
|
|
|
pos.x = (pos.x + 1.5)*100
|
|
|
|
pos.y = (-pos.y + 0.75)*100
|
2015-11-21 13:31:25 +01:00
|
|
|
# Set to event
|
2015-12-09 08:38:23 +01:00
|
|
|
event.pos = pos
|
|
|
|
event.global_pos = pos
|
|
|
|
if (prev_pos == null):
|
|
|
|
prev_pos = pos
|
|
|
|
if (event.type == InputEvent.MOUSE_MOTION):
|
|
|
|
event.relative_pos = pos - prev_pos
|
|
|
|
prev_pos = pos
|
2015-11-21 13:31:25 +01:00
|
|
|
# Send the event to the viewport
|
2015-12-09 08:38:23 +01:00
|
|
|
get_node("viewport").input(event)
|
|
|
|
|
2014-04-10 05:18:27 +02:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
# Initalization here
|
2015-12-09 08:38:23 +01:00
|
|
|
get_node("area/quad").get_material_override().set_texture(FixedMaterial.PARAM_DIFFUSE, get_node("viewport").get_render_target_texture())
|
2014-04-10 05:18:27 +02:00
|
|
|
set_process_input(true)
|