Restore Goddard leveling and Scooter positional pitch processing
This commit is contained in:
1 parent
74be19eb15
commit
fccc0b9d1b
24 files changed
+967
-8
No files matched your search
@@ -96,10 +96,15 @@ public sealed class ActorPatrol
|
||||
throw new InvalidOperationException("Goddard body solver produced nonfinite state");
|
||||
actor.Position = body.Position;
|
||||
Velocity = body.Velocity;
|
||||
var yawError = (desiredYaw - actor.Rotation.Y) % 360;
|
||||
if (yawError > 180) yawError -= 360;
|
||||
if (yawError < -180) yawError += 360;
|
||||
actor.Rotation = actor.Rotation with { Y = actor.Rotation.Y + yawError * yawFactor * dt };
|
||||
if(FollowPlayer&&actor.Kind=="3DOG")
|
||||
actor.Rotation=GoddardFacing(actor.Rotation,desiredYaw,dt);
|
||||
else
|
||||
{
|
||||
var yawError = (desiredYaw - actor.Rotation.Y) % 360;
|
||||
if (yawError > 180) yawError -= 360;
|
||||
if (yawError < -180) yawError += 360;
|
||||
actor.Rotation = actor.Rotation with { Y = actor.Rotation.Y + yawError * yawFactor * dt };
|
||||
}
|
||||
|
||||
switch (actor.AIstate)
|
||||
{
|
||||
@@ -120,6 +125,16 @@ public sealed class ActorPatrol
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>4096E0 with41C8DB Goddard factors and the ordinary supported
|
||||
/// follow target (pitch/roll0). Dismount copies tilt; this later AI phase
|
||||
/// gradually levels it. Full airborne AI target selection remains separate.</summary>
|
||||
public static Vector3 GoddardFacing(Vector3 rotation,float yaw,float dt)
|
||||
{
|
||||
static float Arc(float delta)=>delta>180?delta-360:delta< -180?delta+360:delta;
|
||||
var delta=new Vector3(Arc(-rotation.X)*.3f*dt,Arc(yaw-rotation.Y)*3.2f*dt,Arc(-rotation.Z)*.3f*dt);
|
||||
return RocketOrientation.Add(rotation,delta);
|
||||
}
|
||||
|
||||
private void StepFollow()
|
||||
{
|
||||
var target=findActor("JIM1");if(target==null||!target.Active)return;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Numerics;
|
||||
namespace GamePort.Game;
|
||||
|
||||
/// <summary>412ED0 engine command followed by bounded47D9D0 positional pitch.
|
||||
/// Owns source695F84 channel history; scene/global audio scheduling stays separate.</summary>
|
||||
public sealed class ScooterAudio
|
||||
{
|
||||
private int appliedFrequency;
|
||||
public float History { get; private set; }
|
||||
public void Reset(){History=0;appliedFrequency=0;}
|
||||
|
||||
public static int EngineFrequency(int baseFrequency,float speed)
|
||||
=>Math.Max(7000,(int)(baseFrequency+(double)speed*0.5263157894736842*51));
|
||||
|
||||
public int Frequency(int baseFrequency,float speed,Vector3 source,Vector3 listener)
|
||||
{
|
||||
float distance=OriginalBodySupport.QuickMagnitude(listener-source);
|
||||
//A zero-distance source exits before set_frequency, retaining device Hz.
|
||||
if(distance==0)return appliedFrequency==0?baseFrequency:appliedFrequency;
|
||||
var history=History;
|
||||
int nominal=EngineFrequency(baseFrequency,speed);
|
||||
int adjusted=PositionalFrequency(nominal,distance,ref history);
|
||||
History=history;
|
||||
//DX accepts unsigned Hz, clamps nonzero to100..100000;0 means source rate.
|
||||
uint hz=unchecked((uint)adjusted);
|
||||
appliedFrequency=hz==0?baseFrequency:(int)Math.Clamp(hz,100u,100000u);
|
||||
return appliedFrequency;
|
||||
}
|
||||
|
||||
public static int PositionalFrequency(int nominal,float distance,ref float history)
|
||||
{
|
||||
if(distance==0)return nominal; //47DA7E returns without the channel write/history update.
|
||||
int correction=(int)(((double)distance-history)*.75);
|
||||
int result=distance>history?unchecked(nominal-correction):unchecked(nominal+correction);
|
||||
//47DBFC/47DC11 fild the integer correction, not the current distance.
|
||||
history=correction;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user