3D-Arena (Duell, Hub, Freiheit, Erstellung, Bestenliste), Retiarius beidhändig, Waffen je Klasse, Einführung, Willkommen, weniger Reiter, Wirtschaft ohne Taberna, Kantenglättung, Leuchten, weiche Schatten, Gamepad, Absturz-Protokoll
Stand von main 20cd8ba2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,7 @@ namespace GladiatorIdle.Arena
|
||||
_trauma = MathF.Max(0, _trauma - dt * 1.7f);
|
||||
_punch *= MathF.Exp(-dt * 9f);
|
||||
if (calm) { _trauma = 0; _punch = 0; }
|
||||
UpdateYaw(dt, calm);
|
||||
}
|
||||
|
||||
/// Kameraverschiebung durch Rütteln (Design-Pixel).
|
||||
@@ -48,6 +49,95 @@ namespace GladiatorIdle.Arena
|
||||
s * (MathF.Cos((float)_t * 89) + 0.6f * MathF.Sin((float)_t * 151 + 0.7f)) / 1.6f);
|
||||
}
|
||||
|
||||
// ── 3D: Perspektive, die die Kampfebene z = 0 genau wie die 2D-Ansicht abbildet ──
|
||||
// Raum in Design-Pixeln: x rechts, y nach unten, z zum Betrachter; Kämpfer bei z = 0.
|
||||
|
||||
/// Augenhöhe (y) und Abstand der Kamera zur Kampfebene; Nah- und Fernebene.
|
||||
public const float EYE_Y = 330, DIST = 2600, NEAR = 150, FAR = 16000;
|
||||
/// Augenhöhe jetzt (atmet leicht, steigt beim Sprung mit).
|
||||
public float EyeY { get; private set; } = EYE_Y;
|
||||
float _lift, _liftTarget;
|
||||
|
||||
/// Kamera hebt sich kurz (Sprungangriff): Ziel in Design-Pixeln nach oben.
|
||||
public void Lift(float amount) => _liftTarget = amount;
|
||||
|
||||
/// Drehung um die Bildmitte (Grad): Kinomomente. Basis gleitet zum Ziel, Puls schwingt hin und zurück.
|
||||
public float Yaw { get; private set; }
|
||||
float _yawBase, _yawTarget, _pulseAmp, _pulseDur, _pulseT = -1;
|
||||
|
||||
/// Kurzer Schwenk um die Kämpfer und zurück (Raserei, Treffer zum Sieg).
|
||||
public void Pulse(float degrees, float seconds)
|
||||
{
|
||||
// ein laufender, größerer Schwenk wird nicht von einem kleinen unterbrochen
|
||||
if (_pulseT >= 0 && MathF.Abs(_pulseAmp) > MathF.Abs(degrees) && _pulseT < _pulseDur * 0.7f) return;
|
||||
_pulseAmp = degrees; _pulseDur = seconds; _pulseT = 0;
|
||||
}
|
||||
|
||||
/// Langsame Fahrt auf einen festen Winkel (Sieg); 0 = zurück zur Seitenansicht.
|
||||
public void HoldYaw(float degrees) => _yawTarget = degrees;
|
||||
|
||||
void UpdateYaw(float dt, bool calm)
|
||||
{
|
||||
_yawBase += (_yawTarget - _yawBase) * (1 - MathF.Exp(-dt * 0.9f));
|
||||
float pulse = 0;
|
||||
if (_pulseT >= 0)
|
||||
{
|
||||
_pulseT += dt;
|
||||
float k = _pulseT / _pulseDur;
|
||||
if (k >= 1) _pulseT = -1;
|
||||
else pulse = _pulseAmp * MathF.Sin(MathF.PI * k);
|
||||
}
|
||||
// ständige leichte Bewegung: langsames Pendeln und Atmen der Höhe (wie eine Handkamera am Rand)
|
||||
float drift = 3.2f * MathF.Sin((float)_t * 0.21f) + 1.3f * MathF.Sin((float)_t * 0.53f + 1.1f);
|
||||
Yaw = calm ? 0 : _yawBase + pulse + drift;
|
||||
_lift += (_liftTarget - _lift) * (1 - MathF.Exp(-dt * 4));
|
||||
_liftTarget *= MathF.Exp(-dt * 1.5f);
|
||||
EyeY = calm ? EYE_Y : EYE_Y + 22 * MathF.Sin((float)_t * 0.33f) - _lift;
|
||||
}
|
||||
|
||||
/// Welt → Kameraraum (Kamera im Ursprung, Blick nach −z), mit Drehung um die Bildmitte.
|
||||
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);
|
||||
}
|
||||
|
||||
/// 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 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(
|
||||
1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
-ex / d, -ey / d, a, -1 / d,
|
||||
0, 0, b, 0);
|
||||
// Kameraraum hat den Ursprung bei (ex, ey, d): Design-Pixel = x_c + ex·W
|
||||
var v2 = View(screenScale, offset); // nur x/y benutzen (2D-affin)
|
||||
var a2 = new Matrix(
|
||||
v2.M11, v2.M12, 0, 0,
|
||||
v2.M21, v2.M22, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
v2.M41, v2.M42, 0, 1);
|
||||
var clip = new Matrix(
|
||||
2f / vpW, 0, 0, 0,
|
||||
0, -2f / vpH, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
-1, 1, 0, 1);
|
||||
return p * a2 * clip;
|
||||
}
|
||||
|
||||
/// Weltpunkt → Bildschirm-Pixel; <c>w</c> > 1 heißt weiter hinten (für Größen von Lichtern).
|
||||
public Vector2 ToPixel(Vector3 world, Matrix view3, Matrix proj3, int vpW, int vpH, out float w)
|
||||
{
|
||||
var c = Vector4.Transform(new Vector4(world, 1), view3 * proj3);
|
||||
w = MathF.Max(0.001f, c.W);
|
||||
return new Vector2((c.X / w + 1) * 0.5f * vpW, (1 - c.Y / w) * 0.5f * vpH);
|
||||
}
|
||||
|
||||
/// Design-Pixel → Bildschirm. <paramref name="parallax"/>: 1 = Ebene der Kämpfer, <1 weiter hinten.
|
||||
public Matrix View(float screenScale, Vector2 offset, float parallax = 1f)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user