gui in 3D demo now uses area for input

This commit is contained in:
Juan Linietsky 2015-03-22 11:52:07 -03:00
parent 92ab362afa
commit 78694d8542
4 changed files with 33 additions and 24 deletions

View file

@ -7,20 +7,24 @@ extends Spatial
var prev_pos=null 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 func _input( ev ):
#for game UIs of this kind consider more complex collision against plane #all other (non-mouse) events
var p = Plane(Vector3(0,0,1),0).intersects_ray(rfrom,rnorm) if (not ev.type in [InputEvent.MOUSE_BUTTON,InputEvent.MOUSE_MOTION,InputEvent.SCREEN_DRAG,InputEvent.SCREEN_TOUCH]):
if (p==null): get_node("viewport").input(ev)
return
pos.x=(p.x+1.5)*100
pos.y=(-p.y+0.75)*100 #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.pos=pos
ev.global_pos=pos ev.global_pos=pos
if (prev_pos==null): if (prev_pos==null):
@ -33,12 +37,9 @@ func _input(ev):
func _ready(): func _ready():
# Initalization here # 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) set_process_input(true)
pass pass

Binary file not shown.

View file

@ -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) { 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("translate","offset"),&Spatial::translate );
ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate ); ObjectTypeDB::bind_method( _MD("global_translate","offset"),&Spatial::global_translate );
ObjectTypeDB::bind_method( _MD("orthonormalize"),&Spatial::orthonormalize ); 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","target","up"),&Spatial::look_at );
ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos ); ObjectTypeDB::bind_method( _MD("look_at_from_pos","pos","target","up"),&Spatial::look_at_from_pos );

View file

@ -180,6 +180,7 @@ public:
void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal); void look_at_from_pos(const Vector3& p_pos,const Vector3& p_target, const Vector3& p_up_normal);
void orthonormalize(); void orthonormalize();
void set_identity();
void show(); void show();
void hide(); void hide();