feat: Folgekamera folgt der Fahrtrichtung
- Kamera nutzt die Bahn-Tangente statt des Koerper-Yaw - Rueckwaerts bleibt sie auf der Bahnseite und zeigt die Laeuferin von vorn - Element-Marker behalten die letzte Fahrtrichtung - 61 Praesentations-Assertions (1193 gesamt)
This commit is contained in:
parent
81be37101f
commit
a8c5e61faf
6 changed files with 151 additions and 12 deletions
|
|
@ -30,6 +30,7 @@ var _camera_mode: CameraMode = CameraMode.FOLLOW
|
|||
var _camera_initialized: bool = false
|
||||
var _look_target := Vector3(0.0, 1.0, 0.0)
|
||||
var _last_playback_time: float = -1.0
|
||||
var _travel_direction := Vector2.RIGHT
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -54,6 +55,7 @@ func setup(routine: Routine) -> void:
|
|||
|
||||
_camera_mode = CameraMode.FOLLOW
|
||||
_camera_initialized = false
|
||||
_travel_direction = Vector2.RIGHT
|
||||
if routine == null or routine.get_length_m() <= 0.0:
|
||||
skater.clear_pose()
|
||||
_update_camera(0.0, true)
|
||||
|
|
@ -96,6 +98,15 @@ func update_pose(
|
|||
if not _active:
|
||||
return
|
||||
|
||||
if segment != null and not segment.is_element_marker():
|
||||
var travel := heading
|
||||
if segment.direction == PathSegment.Direction.BACKWARD:
|
||||
travel = -heading
|
||||
if travel.length_squared() > 0.0001:
|
||||
_travel_direction = travel
|
||||
elif segment == null and heading.length_squared() > 0.0001:
|
||||
_travel_direction = heading
|
||||
|
||||
var moved := previous.distance_to(skater.position)
|
||||
var jumped := moved > TRAIL_RESET_DISTANCE_M
|
||||
if jumped or time_reset:
|
||||
|
|
@ -125,6 +136,7 @@ func clear_pose() -> void:
|
|||
skater.clear_pose()
|
||||
trail.clear()
|
||||
_last_playback_time = -1.0
|
||||
_travel_direction = Vector2.RIGHT
|
||||
_camera_initialized = false
|
||||
if _active:
|
||||
_update_camera(0.0, true)
|
||||
|
|
@ -171,17 +183,24 @@ func get_skater_yaw() -> float:
|
|||
return skater.rotation.y
|
||||
|
||||
|
||||
func get_camera_travel_forward() -> Vector3:
|
||||
var forward := Vector3(
|
||||
_travel_direction.x,
|
||||
0.0,
|
||||
-_travel_direction.y
|
||||
)
|
||||
if forward.length_squared() < 0.0001:
|
||||
return Vector3(0.0, 0.0, 1.0)
|
||||
return forward.normalized()
|
||||
|
||||
|
||||
func update_camera_now() -> void:
|
||||
_update_camera(0.0, true)
|
||||
|
||||
|
||||
func _update_camera(delta: float, snap: bool = false) -> void:
|
||||
var skater_position := skater.position
|
||||
var forward := Vector3(
|
||||
sin(skater.rotation.y),
|
||||
0.0,
|
||||
cos(skater.rotation.y)
|
||||
)
|
||||
var forward := get_camera_travel_forward()
|
||||
|
||||
var desired := Vector3.ZERO
|
||||
var target := Vector3.ZERO
|
||||
|
|
|
|||
|
|
@ -190,6 +190,44 @@ func _test_presentation() -> void:
|
|||
"clear pose clears the trail"
|
||||
)
|
||||
|
||||
presentation.update_pose(
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2.RIGHT,
|
||||
forward_segment
|
||||
)
|
||||
presentation.update_camera_now()
|
||||
_check(
|
||||
_vec3_matches(
|
||||
presentation.get_camera_travel_forward(),
|
||||
Vector3(1.0, 0.0, 0.0)
|
||||
),
|
||||
"forward camera follows the path direction"
|
||||
)
|
||||
var camera_before := presentation.camera.position
|
||||
presentation.update_pose(
|
||||
Vector2(0.0, 0.0),
|
||||
Vector2.LEFT,
|
||||
backward_segment
|
||||
)
|
||||
presentation.update_camera_now()
|
||||
_check(
|
||||
_vec3_matches(
|
||||
presentation.get_camera_travel_forward(),
|
||||
Vector3(1.0, 0.0, 0.0)
|
||||
),
|
||||
"backward camera keeps the travel direction"
|
||||
)
|
||||
_check(
|
||||
presentation.camera.position.distance_to(camera_before) < 0.01,
|
||||
"backward skating does not swing the camera"
|
||||
)
|
||||
_check(
|
||||
absf(
|
||||
angle_difference(presentation.get_skater_yaw(), -PI * 0.5)
|
||||
) < 0.001,
|
||||
"the skater faces the camera when skating backward"
|
||||
)
|
||||
|
||||
presentation.set_active(false)
|
||||
_check(not presentation.visible, "inactive presentation is hidden")
|
||||
_check(not presentation.camera.current, "inactive presentation releases the camera")
|
||||
|
|
@ -306,6 +344,14 @@ func _color_matches(actual: Color, expected: Color) -> bool:
|
|||
)
|
||||
|
||||
|
||||
func _vec3_matches(
|
||||
actual: Vector3,
|
||||
expected: Vector3,
|
||||
tolerance: float = 0.001
|
||||
) -> bool:
|
||||
return actual.distance_to(expected) <= tolerance
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
_assertions += 1
|
||||
if not condition:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue