Fix port cinematics and expand ship attractions

This commit is contained in:
josh
2026-11-28 18:39:32 -05:00
parent 2c85a5ba00
commit 56fafba6d9
37 changed files with 936 additions and 101 deletions

View File

@@ -19,6 +19,14 @@ namespace Soundings
internal bool PortCinematicActive => cinematicPort >= 0;
internal (Vector2 Near, Vector2 Far, Vector4 Matte) PortCinematicAlignment()
{
Vector3 edge = new(0, 1.4f, -QuayWidth * .5f);
Vector3 near = portQuay.transform.TransformPoint(edge - Vector3.right * QuayLength * .45f);
Vector3 far = portQuay.transform.TransformPoint(edge + Vector3.right * QuayLength * .45f);
return (viewCamera.WorldToViewportPoint(near), viewCamera.WorldToViewportPoint(far), water.GetVector("_PortMatteCrop"));
}
internal bool BeginPortCinematic(int port, bool arriving)
{
if (PortCinematicActive || vessel == null || port < 0 || port >= Market.Ports.Count)
@@ -101,7 +109,7 @@ namespace Soundings
private (Vector2 Center, float Heading, float Knots) PortMotion(float t)
{
float run = Mathf.Min(35f, vesselLength * .38f);
float run = PortRun;
if (portArrival)
{
float slowing = t * (2f - t);
@@ -116,6 +124,8 @@ namespace Soundings
castOff * 10.5f, Mathf.Lerp(1.4f, 12.6f, t));
}
private float PortRun => Mathf.Min(35f, vesselLength * .38f);
private static Vector2 PortBow(float heading)
{
float radians = heading * Mathf.Deg2Rad;
@@ -130,20 +140,34 @@ namespace Soundings
private void ComposePortCinematic()
{
if (portMatteAspect > 0)
{
// Painted waterfronts were framed broadside. A fixed lens keeps the painted shore and 3D berth aligned.
var fixedFacing = Quaternion.Euler(portArrival ? 10.4f : 9.9f, 0, 0);
var fixedFocus = new Vector3(PortRun * (portArrival ? -.36f : .10f), vesselTop * .32f, -.85f);
SetPortCamera(fixedFocus, fixedFacing, vesselLength * 1.43f, 39f);
return;
}
// Keep the ship ahead of the lens and the quay in frame as the camera tracks along the water.
float glide = Mathf.SmoothStep(0, 1, portFrame);
float angle = portArrival ? Mathf.Lerp(-28f, 31f, glide) : Mathf.Lerp(32f, -25f, glide);
float elevation = portArrival ? Mathf.Lerp(10.8f, 8.9f, glide) : Mathf.Lerp(8.0f, 12.2f, glide);
float distance = vesselLength * (portArrival ? Mathf.Lerp(1.49f, 1.25f, glide) : Mathf.Lerp(1.23f, 1.44f, glide));
distance *= Mathf.Max(1, 1.63f / ViewAspect);
Quaternion facing = Quaternion.Euler(elevation, -angle, 0);
Vector3 focus = vessel.position;
focus.x = focus.x * .64f + vesselLength * (portArrival ? .021f : .048f);
focus.y = vesselTop * .32f;
focus.z -= .85f;
SetPortCamera(focus, facing, distance, Mathf.Lerp(37.5f, 40.5f, portArrival ? 1f - glide : glide));
}
private void SetPortCamera(Vector3 focus, Quaternion facing, float distance, float fieldOfView)
{
distance *= Mathf.Max(1, 1.63f / ViewAspect);
viewCamera.orthographic = false;
viewCamera.nearClipPlane = OrbitNearClip;
viewCamera.fieldOfView = Mathf.Lerp(37.5f, 40.5f, portArrival ? 1f - glide : glide);
viewCamera.fieldOfView = fieldOfView;
viewCamera.transform.SetPositionAndRotation(focus + facing * Vector3.back * distance, facing);
FitViewport();
}