tester.gd 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. extends Spatial
  2. # class member variables go here, for example:
  3. # var a = 2
  4. # var b = "textvar"
  5. const INTERP_SPEED = 2
  6. var tester_index = 0
  7. const ROT_SPEED = 0.15
  8. var rot_x = 0
  9. var rot_y = 0
  10. var zoom = 0
  11. const ZOOM_SPEED = 0.1
  12. const ZOOM_MAX = 2.5
  13. var hdrs=[
  14. { path="res://schelde.hdr", name="Riverside"},
  15. { path="res://lobby.hdr", name="Lobby"},
  16. { path="res://park.hdr", name="Park"},
  17. { path="res://night.hdr", name="Night"},
  18. { path="res://experiment.hdr", name="Experiment"},
  19. ]
  20. func _ready():
  21. for h in hdrs:
  22. get_node("ui/bg").add_item(h.name)
  23. func _unhandled_input(ev):
  24. if ev is InputEventMouseButton and ev.button_index == BUTTON_WHEEL_UP:
  25. if zoom < ZOOM_MAX:
  26. zoom += ZOOM_SPEED
  27. get_node("camera/base/rotation/camera").translation.z = -zoom
  28. if ev is InputEventMouseButton and ev.button_index == BUTTON_WHEEL_DOWN:
  29. if zoom > 0:
  30. zoom -= ZOOM_SPEED
  31. get_node("camera/base/rotation/camera").translation.z = -zoom
  32. if ev is InputEventMouseMotion and ev.button_mask & BUTTON_MASK_LEFT:
  33. rot_y += ev.relative.x * ROT_SPEED
  34. rot_x += ev.relative.y * ROT_SPEED
  35. rot_y = clamp(rot_y, -180, 180)
  36. rot_x = clamp(rot_x, 0, 150)
  37. var t = Transform()
  38. t = t.rotated(Vector3(0, 0, 1), rot_x * PI / 180.0)
  39. t = t.rotated(Vector3(0, 1, 0), -rot_y * PI / 180.0)
  40. get_node("camera/base").transform.basis = t.basis
  41. func _process(delta):
  42. var xform = get_node("testers").get_child(tester_index).get_node("MeshInstance").global_transform
  43. var p = xform.origin
  44. var r = Quat(xform.basis)
  45. var from_xform = get_node("camera").transform
  46. var from_p = from_xform.origin
  47. var from_r = Quat(from_xform.basis)
  48. p = from_p.linear_interpolate(p, INTERP_SPEED * delta)
  49. r = from_r.slerp(r, INTERP_SPEED * delta)
  50. var m = Transform(r)
  51. m.origin = p
  52. get_node("camera").transform = m
  53. get_node("ui/label").text = get_node("testers").get_child(tester_index).get_name()
  54. func _on_prev_pressed():
  55. if tester_index > 0:
  56. tester_index -= 1
  57. func _on_next_pressed():
  58. if tester_index < get_node("testers").get_child_count() -1:
  59. tester_index += 1
  60. func _on_bg_item_selected( ID ):
  61. get_node("environment").environment.background_sky.panorama = load(hdrs[ID].path)