Oath speech in the deep warrior voice, cinematic camera, crowd calls your name
Stand von main 730ac6a2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,14 +37,94 @@ namespace GladiatorIdle.Arena
|
||||
float k = 1 - MathF.Exp(-dt * 3.5f);
|
||||
if (FocusX is float fx) { targetZoom = 1.4f; target = new Vector2(fx, H / 2 + 30); k = 1 - MathF.Exp(-dt * 1.2f); }
|
||||
if (FollowX is float fw) { targetZoom = FollowZoom; target = new Vector2(fw, H / 2 + 40); k = 1 - MathF.Exp(-dt * 4f); } // Reise: ohne Begrenzung
|
||||
if (CineWeight > 0.01f) { target = Vector2.Lerp(target, new Vector2(CinePivot.X + CineFrameX, CinePivot.Y), CineWeight); targetZoom = MathHelper.Lerp(targetZoom, 1, CineWeight); }
|
||||
Center += (target - Center) * k;
|
||||
Zoom += (targetZoom - Zoom) * k;
|
||||
_trauma = MathF.Max(0, _trauma - dt * 1.7f);
|
||||
_punch *= MathF.Exp(-dt * 9f);
|
||||
if (calm) { _trauma = 0; _punch = 0; }
|
||||
UpdateYaw(dt, calm);
|
||||
UpdateCine(dt, calm);
|
||||
}
|
||||
|
||||
// ── Kinokamera: Fahrten um einen Drehpunkt (360°), Neigung (Untersicht), Heranfahren ──
|
||||
|
||||
/// Schlüsselbild einer Fahrt: Zeit (s), Drehung (Grad, beliebig, auch über 360), Neigung
|
||||
/// (Grad, negativ = von unten nach oben), Heranfahren (Design-Pixel näher).
|
||||
public readonly record struct Key(float T, float Yaw, float Pitch, float Dolly);
|
||||
|
||||
/// Drehpunkt der Fahrt (Weltpunkt, meist Brust eines Kämpfers); setzt die Szene jedes Bild.
|
||||
public Vector3 CinePivot;
|
||||
/// Bildlage des Drehpunkts: + schiebt ihn nach links (Platz für Tafeln rechts).
|
||||
public float CineFrameX;
|
||||
public float CineYaw { get; private set; }
|
||||
public float CinePitch { get; private set; }
|
||||
public float CineDolly { get; private set; }
|
||||
/// 0 = normale Seitenansicht, 1 = ganz in der Fahrt (Ein- und Ausblenden weich).
|
||||
public float CineWeight { get; private set; }
|
||||
Key[]? _shot; float _shotT, _orbitSpeed; bool _orbit; Key _orbitKey;
|
||||
|
||||
/// Fahrt aus Schlüsselbildern; danach weich zurück zur Seitenansicht.
|
||||
public void Shot(params Key[] keys) { if (keys.Length > 0) { _shot = keys; _shotT = 0; _orbit = false; } }
|
||||
|
||||
/// Fortlaufende Umrundung (Grad/s) mit fester Neigung und Nähe, bis <see cref="StopCine"/>.
|
||||
public void Orbit(float degPerSec, float pitch, float dolly)
|
||||
{
|
||||
_orbit = true; _shot = null; _orbitSpeed = degPerSec;
|
||||
_orbitKey = new Key(0, CineWeight > 0.01f ? CineYaw : 0, pitch, dolly);
|
||||
}
|
||||
|
||||
public void StopCine() { _shot = null; _orbit = false; }
|
||||
public bool CineActive => _shot != null || _orbit;
|
||||
|
||||
void UpdateCine(float dt, bool calm)
|
||||
{
|
||||
if (calm) { _shot = null; _orbit = false; CineWeight = 0; return; }
|
||||
float target = 0;
|
||||
if (_orbit)
|
||||
{
|
||||
_orbitKey = _orbitKey with { Yaw = _orbitKey.Yaw + _orbitSpeed * dt };
|
||||
Blend(_orbitKey, dt);
|
||||
target = 1;
|
||||
}
|
||||
else if (_shot is { } keys)
|
||||
{
|
||||
_shotT += dt;
|
||||
int i = 0;
|
||||
while (i < keys.Length - 1 && _shotT > keys[i + 1].T) i++;
|
||||
Key a = keys[i], b = keys[Math.Min(i + 1, keys.Length - 1)];
|
||||
float k = b.T > a.T ? MathHelper.Clamp((_shotT - a.T) / (b.T - a.T), 0, 1) : 1;
|
||||
k = k * k * (3 - 2 * k);
|
||||
CineYaw = MathHelper.Lerp(a.Yaw, b.Yaw, k); CinePitch = MathHelper.Lerp(a.Pitch, b.Pitch, k); CineDolly = MathHelper.Lerp(a.Dolly, b.Dolly, k);
|
||||
if (_shotT > keys[^1].T) _shot = null;
|
||||
target = 1;
|
||||
CineWeight = 1;
|
||||
}
|
||||
if (target == 0)
|
||||
{
|
||||
// zurück: Winkel auf den nächsten Vollkreis, Neigung und Nähe auf 0
|
||||
float home = MathF.Round(CineYaw / 360) * 360;
|
||||
float k = 1 - MathF.Exp(-dt * 3.2f);
|
||||
CineYaw += (home - CineYaw) * k; CinePitch -= CinePitch * k; CineDolly -= CineDolly * k;
|
||||
if (MathF.Abs(CineYaw - home) < 0.3f && MathF.Abs(CinePitch) < 0.2f && MathF.Abs(CineDolly) < 2) { CineYaw = 0; CinePitch = 0; CineDolly = 0; CineWeight = 0; }
|
||||
else CineWeight = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Blend(Key to, float dt)
|
||||
{
|
||||
float k = CineWeight < 1 ? 1 - MathF.Exp(-dt * 3f) : 1;
|
||||
CineYaw += (to.Yaw - CineYaw) * (_orbit && CineWeight >= 1 ? 1 : k);
|
||||
CinePitch += (to.Pitch - CinePitch) * k; CineDolly += (to.Dolly - CineDolly) * k;
|
||||
CineWeight = 1;
|
||||
}
|
||||
|
||||
/// Wie sichtbar die Kampfebene (2D-Effekte) gerade ist: 1 von vorn, 0 von der Seite.
|
||||
public float PlaneAlpha => MathHelper.Clamp((MathF.Abs(MathF.Cos(MathHelper.ToRadians(Yaw + CineYaw))) - 0.35f) / 0.4f, 0, 1);
|
||||
/// Publikum im Vordergrund (Bildschirm-Ebene) nur in der Seitenansicht.
|
||||
public float FrontAlpha => 1 - CineWeight; // während einer Fahrt tritt das Publikum im Vordergrund ganz zurück
|
||||
static float WrapDeg(float d) { d %= 360; return d > 180 ? d - 360 : d < -180 ? d + 360 : d; }
|
||||
|
||||
/// Kameraverschiebung durch Rütteln (Design-Pixel).
|
||||
Vector2 ShakeOffset()
|
||||
{
|
||||
@@ -104,15 +184,58 @@ namespace GladiatorIdle.Arena
|
||||
public Matrix View3()
|
||||
{
|
||||
var pivot = new Vector3(Center.X, 0, 0);
|
||||
return Matrix.CreateTranslation(-pivot) * Matrix.CreateRotationY(MathHelper.ToRadians(Yaw)) * Matrix.CreateTranslation(pivot)
|
||||
* Matrix.CreateTranslation(-Center.X, -EyeY, -DIST);
|
||||
var view = Matrix.CreateTranslation(-pivot) * Matrix.CreateRotationY(MathHelper.ToRadians(Yaw)) * Matrix.CreateTranslation(pivot);
|
||||
if (CineWeight > 0.001f)
|
||||
{
|
||||
// Kinofahrt: um den Drehpunkt drehen und neigen, dann heranfahren
|
||||
var cp = new Vector3(Center.X, CinePivot.Y, CinePivot.Z);
|
||||
view *= Matrix.CreateTranslation(-cp) * Matrix.CreateRotationY(MathHelper.ToRadians(CineYaw))
|
||||
* Matrix.CreateRotationX(MathHelper.ToRadians(CinePitch)) * Matrix.CreateTranslation(cp)
|
||||
* Matrix.CreateTranslation(0, 0, CineDolly - FitPull);
|
||||
}
|
||||
return view * Matrix.CreateTranslation(-Center.X, -EyeNow, -DIST);
|
||||
}
|
||||
|
||||
/// Augenhöhe mit Fahrt: wandert zum Drehpunkt, damit das Heranfahren auf ihn zielt.
|
||||
float EyeNow => MathHelper.Lerp(EyeY, CinePivot.Y, CineWeight * 0.85f);
|
||||
|
||||
/// Sicherung: so weit fährt die Kamera gerade zurück, damit alle Figuren im Bild bleiben.
|
||||
public float FitPull { get; private set; }
|
||||
|
||||
/// Figuren im Bild halten: ragt ein Punkt (Kopf, Füße) aus dem sicheren Bereich, zieht die
|
||||
/// Kamera schnell auf; ist genug Platz, kehrt sie langsam zur geplanten Nähe zurück.
|
||||
public void KeepInView(ReadOnlySpan<Vector3> points, float screenScale, Vector2 offset, int vpW, int vpH, float dt)
|
||||
{
|
||||
if (CineWeight < 0.01f && FitPull <= 0) return;
|
||||
var vp = View3() * Proj3(screenScale, offset, vpW, vpH);
|
||||
float worst = 0;
|
||||
foreach (var pt in points)
|
||||
{
|
||||
var c = Vector4.Transform(new Vector4(pt, 1), vp);
|
||||
if (c.W <= 1e-3f) { worst = MathF.Max(worst, 1); continue; } // hinter der Kamera
|
||||
float x = c.X / c.W, y = c.Y / c.W;
|
||||
worst = MathF.Max(worst, MathF.Max(MathF.Abs(x) - 0.78f, MathF.Abs(y) - 0.76f));
|
||||
}
|
||||
if (worst > 0) FitPull += (900 + 6000 * worst) * dt;
|
||||
else if (worst < -0.08f) FitPull = MathF.Max(0, FitPull - 260 * dt);
|
||||
FitPull = MathF.Min(FitPull, CineDolly + 1400); // höchstens etwas weiter weg als die Seitenansicht
|
||||
// nie hinter die Arenamauer: steht die Kamera außerhalb des Rings, fährt sie wieder heran
|
||||
if (Ring is { } ring && CineWeight > 0.01f)
|
||||
{
|
||||
var eye = Matrix.Invert(View3()).Translation;
|
||||
float d = Vector2.Distance(new Vector2(eye.X, eye.Z), ring.Center);
|
||||
if (d > ring.R - 260) FitPull -= (d - (ring.R - 260)) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/// Ring der Arena (Mitte x/z, Radius): die Kinokamera bleibt innen.
|
||||
public (Vector2 Center, float R)? Ring;
|
||||
|
||||
/// Kameraraum → Bildschirm (Clip): erst perspektivisch zurück in Design-Pixel der Ebene z = 0,
|
||||
/// dann dieselbe 2D-Abbildung wie <see cref="View"/> (Zoom, Wackeln, Stoß), dann Pixel → Clip.
|
||||
public Matrix Proj3(float screenScale, Vector2 offset, int vpW, int vpH)
|
||||
{
|
||||
float ex = Center.X, ey = EyeY, d = DIST;
|
||||
float ex = Center.X, ey = EyeNow, d = DIST;
|
||||
float a = -FAR / (d * (FAR - NEAR)), b = -NEAR * FAR / (d * (FAR - NEAR));
|
||||
// Zeilen-Vektor-Form: (x, y, z, 1) → (X, Y, Z, W) mit W = −z/d (z = 0 der Welt ⇒ W = 1)
|
||||
var p = new Matrix(
|
||||
|
||||
Reference in New Issue
Block a user