Complete test gyroscope
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
extends Spatial
|
extends Spatial
|
||||||
|
|
||||||
const time_max = 3000 # msec
|
const TIME_MAX = 3000 # msec
|
||||||
const gyroscope_max_diff = 0.1
|
const GYROSCOPE_MAX_DIFF = 0.1
|
||||||
|
const OFFSET_CAMERA = 0.12
|
||||||
|
|
||||||
# var gyroscope_value_old = Vector2(0, 0)
|
|
||||||
var gyroscope_value_old = Vector3(0, 0, 0)
|
var gyroscope_value_old = Vector3(0, 0, 0)
|
||||||
|
|
||||||
onready var meshes = {
|
onready var meshes = {
|
||||||
@@ -37,7 +37,7 @@ func _check_dissolve_mesh():
|
|||||||
if meshes[mesh]["tick_reference"] == null:
|
if meshes[mesh]["tick_reference"] == null:
|
||||||
meshes[mesh]["tick_reference"] = OS.get_ticks_msec()
|
meshes[mesh]["tick_reference"] = OS.get_ticks_msec()
|
||||||
|
|
||||||
if OS.get_ticks_msec() < meshes[mesh]["tick_reference"] + time_max:
|
if OS.get_ticks_msec() < meshes[mesh]["tick_reference"] + TIME_MAX:
|
||||||
meshes[mesh]["value"] += 0.01
|
meshes[mesh]["value"] += 0.01
|
||||||
meshes[mesh]["mesh"].get_surface_material(0).set("shader_param/dissolve_amount", meshes[mesh]["value"])
|
meshes[mesh]["mesh"].get_surface_material(0).set("shader_param/dissolve_amount", meshes[mesh]["value"])
|
||||||
else:
|
else:
|
||||||
@@ -48,22 +48,22 @@ func _check_change_angle_camera():
|
|||||||
var camera = $"Main Camera"
|
var camera = $"Main Camera"
|
||||||
var gyroscope = Input.get_gyroscope()
|
var gyroscope = Input.get_gyroscope()
|
||||||
|
|
||||||
if camera.h_offset >= -0.2:
|
if camera.h_offset >= -OFFSET_CAMERA:
|
||||||
if _action_pressed("ui_left") or _gyroscope_changed_left(gyroscope):
|
if _action_pressed("ui_left") or _gyroscope_changed_left(gyroscope):
|
||||||
# print("[warcraft#_ready] move camera angle to left")
|
# print("[warcraft#_ready] move camera angle to left")
|
||||||
$"Main Camera".h_offset -= 0.01
|
$"Main Camera".h_offset -= 0.01
|
||||||
|
|
||||||
if camera.h_offset <= 0.2:
|
if camera.h_offset <= OFFSET_CAMERA:
|
||||||
if _action_pressed("ui_right") or _gyroscope_changed_right(gyroscope):
|
if _action_pressed("ui_right") or _gyroscope_changed_right(gyroscope):
|
||||||
# print("[warcraft#_ready] move camera angle to right")
|
# print("[warcraft#_ready] move camera angle to right")
|
||||||
$"Main Camera".h_offset += 0.01
|
$"Main Camera".h_offset += 0.01
|
||||||
|
|
||||||
if camera.v_offset >= -0.2:
|
if camera.v_offset >= -OFFSET_CAMERA:
|
||||||
if _action_pressed("ui_down") or _gyroscope_changed_down(gyroscope):
|
if _action_pressed("ui_down") or _gyroscope_changed_down(gyroscope):
|
||||||
# print("[warcraft#_ready] move camera angle to right")
|
# print("[warcraft#_ready] move camera angle to right")
|
||||||
$"Main Camera".v_offset -= 0.01
|
$"Main Camera".v_offset -= 0.01
|
||||||
|
|
||||||
if camera.v_offset <= 0.2:
|
if camera.v_offset <= OFFSET_CAMERA:
|
||||||
if _action_pressed("ui_up") or _gyroscope_changed_up(gyroscope):
|
if _action_pressed("ui_up") or _gyroscope_changed_up(gyroscope):
|
||||||
# print("[warcraft#_ready] move camera angle to right")
|
# print("[warcraft#_ready] move camera angle to right")
|
||||||
$"Main Camera".v_offset += 0.01
|
$"Main Camera".v_offset += 0.01
|
||||||
@@ -71,35 +71,39 @@ func _check_change_angle_camera():
|
|||||||
gyroscope_value_old = gyroscope
|
gyroscope_value_old = gyroscope
|
||||||
|
|
||||||
func _action_pressed(action):
|
func _action_pressed(action):
|
||||||
return Input.is_action_just_pressed(action)
|
return Input.is_action_pressed(action)
|
||||||
|
|
||||||
func _gyroscope_changed_left(gyroscope):
|
func _gyroscope_changed_left(gyroscope):
|
||||||
if (gyroscope.y - gyroscope_value_old.y) > gyroscope_max_diff:
|
if (gyroscope.y - gyroscope_value_old.y) > GYROSCOPE_MAX_DIFF:
|
||||||
# print("[warcraft#_ready] (left)")
|
print("[warcraft#_ready] (left)")
|
||||||
print("[warcraft#_ready] (left) y "+String(gyroscope.y)+" - y.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
# print("[warcraft#_ready] "+String(gyroscope.y)+" (left ) y "+String(gyroscope.y)+" - y.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func _gyroscope_changed_right(gyroscope):
|
func _gyroscope_changed_right(gyroscope):
|
||||||
if (gyroscope.y - gyroscope_value_old.y) > gyroscope_max_diff and gyroscope.y > 0:
|
if (gyroscope.y - gyroscope_value_old.y) > GYROSCOPE_MAX_DIFF and gyroscope.y > 0:
|
||||||
print("[warcraft#_ready] (right)")
|
print("[warcraft#_ready] (right)")
|
||||||
# print("[warcraft#_ready] (right) y "+String(gyroscope.y)+" - x.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
# print("[warcraft#_ready] "+String(gyroscope.y)+" (right) y "+String(gyroscope.y)+" - x.old "+String(gyroscope_value_old.y)+" = "+String(gyroscope.y - gyroscope_value_old.y))
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func _gyroscope_changed_down(gyroscope):
|
func _gyroscope_changed_down(gyroscope):
|
||||||
if (gyroscope.z - gyroscope_value_old.z) > gyroscope_max_diff:
|
if (gyroscope.z - gyroscope_value_old.z) > GYROSCOPE_MAX_DIFF or \
|
||||||
print("[warcraft#_ready] (down)")
|
(gyroscope.x - gyroscope_value_old.x) > GYROSCOPE_MAX_DIFF:
|
||||||
|
print("[warcraft#_ready] "+String(gyroscope.z)+"|| "+String(gyroscope.x)+" (down )")
|
||||||
|
# print("[warcraft#_ready] (down)")
|
||||||
# print("[warcraft#_ready] (down) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
# print("[warcraft#_ready] (down) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
func _gyroscope_changed_up(gyroscope):
|
func _gyroscope_changed_up(gyroscope):
|
||||||
if (gyroscope.z - gyroscope_value_old.z) > gyroscope_max_diff and gyroscope.z > 0:
|
if (gyroscope.z - gyroscope_value_old.z) > GYROSCOPE_MAX_DIFF and gyroscope.z > 0 or \
|
||||||
print("[warcraft#_ready] (up)")
|
(gyroscope.x - gyroscope_value_old.x) > GYROSCOPE_MAX_DIFF and gyroscope.x > 0 :
|
||||||
|
print("[warcraft#_ready] "+String(gyroscope.z)+"|| "+String(gyroscope.x)+" (up )")
|
||||||
|
# print("[warcraft#_ready] (up ) ")
|
||||||
# print("[warcraft#_ready] (up) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
# print("[warcraft#_ready] (up) x "+String(gyroscope.x)+" - x.old "+String(gyroscope_value_old.x)+" = "+String(gyroscope.x - gyroscope_value_old.x))
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user