Integrate source airborne tilt and logical-root rendering
This commit is contained in:
1 parent
a61f1b0284
commit
27be8ed630
36 files changed
+1953
-62
No files matched your search
@@ -21,10 +21,12 @@ public sealed class LabSimulation
|
||||
private readonly Func<Vector3, Vector3, SupportHit?>? ceilingRay;
|
||||
private readonly OriginalBodyPhysics? originalBody;
|
||||
private readonly PlayerEnergy energy;
|
||||
private readonly Vector3 sourceStart;
|
||||
private readonly float startYaw, modelMinimumY, rootHeight, startFloor;
|
||||
private readonly Vector3 sourceStart, sourceRotation;
|
||||
private readonly float modelMinimumY, rootHeight, startFloor;
|
||||
private float targetYaw, extraAirAcceleration, shadowDistance, lateralContribution;
|
||||
private float targetPitch, targetRoll;
|
||||
private float forwardAirPitch, backwardAirPitch;
|
||||
private bool facingDirty;
|
||||
private int? retainedSupportMaterial;
|
||||
private bool bubbleLoop;
|
||||
private PlayerPose bubblePose;
|
||||
@@ -53,7 +55,11 @@ public sealed class LabSimulation
|
||||
public float MaximumSpeed { get; private set; } = RecoveredMotion.MaximumSpeed;
|
||||
public float Pitch { get; private set; }
|
||||
public float Roll { get; private set; }
|
||||
public bool TracksBubbleOrientation { get; private set; }
|
||||
public Vector3 Rotation => new(Pitch,Yaw,Roll);
|
||||
public Vector3 FacingTarget => new(targetPitch,targetYaw,targetRoll);
|
||||
public bool FacingDirty => facingDirty;
|
||||
public float ForwardAirPitch => forwardAirPitch;
|
||||
public float BackwardAirPitch => backwardAirPitch;
|
||||
public int BubbleBounces { get; private set; }
|
||||
public int GadgetMode
|
||||
{
|
||||
@@ -71,7 +77,6 @@ public sealed class LabSimulation
|
||||
if (Energy <= 0 && !IgnoresGadgetEnergy || Bubble.Active || Bubble.Expanding || Bubble.Collapsing) return;
|
||||
InteractionRadius=160; BodyFactor=.415f; movementMode=2; MaximumSpeed=1350;
|
||||
bubblePose=previousPose;
|
||||
TracksBubbleOrientation=true;
|
||||
gadgetMode=0; Bubble.Start();
|
||||
if (!bubbleLoop) { GadgetSound?.Invoke(2,true); bubbleLoop=true; }
|
||||
return;
|
||||
@@ -139,15 +144,23 @@ public sealed class LabSimulation
|
||||
public Vector3 ActorRoot => Position + Vector3.UnitY * rootHeight;
|
||||
public Vector3 CameraEye { get; private set; }
|
||||
public Vector3 CameraTarget => grapplerCameraTarget??ActorRoot + new Vector3(0, 80 + 1.9f * Baseball.CameraPitch, 0);
|
||||
public Matrix4x4 Model => Matrix4x4.CreateRotationZ(-(TracksBubbleOrientation?Roll:0) * MathF.PI / 180)
|
||||
* Matrix4x4.CreateRotationX(-(TracksBubbleOrientation?Pitch:0) * MathF.PI / 180) * Matrix4x4.CreateRotationY(-Yaw * MathF.PI / 180)
|
||||
* Matrix4x4.CreateTranslation(Position - new Vector3(0, modelMinimumY, 0));
|
||||
//Preserve upright sole placement as a modern local correction, while the
|
||||
//recovered full-axis rotation and unrotated translation use the actor root.
|
||||
public Matrix4x4 Model => JimmyRenderTransform.Aligned(ActorRoot,Rotation,-modelMinimumY-rootHeight);
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, float yaw,
|
||||
Func<Vector3, Vector3, SupportHit?>? cameraRay = null,
|
||||
Func<Vector3, Vector3, SupportHit?>? ceilingRay = null,
|
||||
OriginalStaticCollision? originalCollision = null, PlayerEnergy? energy = null)
|
||||
: this(collision,standingPose,start,new Vector3(0,yaw,0),cameraRay,ceilingRay,originalCollision,energy) { }
|
||||
|
||||
public LabSimulation(SceneCollision collision, Mesh standingPose, Vector3 start, Vector3 rotation,
|
||||
Func<Vector3, Vector3, SupportHit?>? cameraRay = null,
|
||||
Func<Vector3, Vector3, SupportHit?>? ceilingRay = null,
|
||||
OriginalStaticCollision? originalCollision = null, PlayerEnergy? energy = null)
|
||||
{
|
||||
if(!float.IsFinite(rotation.X)||!float.IsFinite(rotation.Y)||!float.IsFinite(rotation.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(rotation));
|
||||
this.collision = collision;
|
||||
this.cameraRay = cameraRay;
|
||||
this.ceilingRay = ceilingRay;
|
||||
@@ -157,7 +170,7 @@ public sealed class LabSimulation
|
||||
Invisible.BlendRequested += Appearance.SetBlend;
|
||||
Baseball.Thrown += () => GadgetSound?.Invoke(10,false);
|
||||
sourceStart = start;
|
||||
startYaw = yaw;
|
||||
sourceRotation = rotation;
|
||||
var bounds = standingPose.Bounds();
|
||||
modelMinimumY = bounds.Min.Y;
|
||||
BodyHeight = bounds.Max.Y - bounds.Min.Y;
|
||||
@@ -181,13 +194,14 @@ public sealed class LabSimulation
|
||||
Baseball.Reset();
|
||||
if (gadgetMode == 6) gadgetMode = -1;
|
||||
Bubble.Reset(); FloorState.Reset(); Appearance.Reset(); retainedSupportMaterial=null;
|
||||
Pitch=Roll=targetPitch=targetRoll=0; BubbleBounces=0;
|
||||
TracksBubbleOrientation=false;
|
||||
Pitch=sourceRotation.X;Roll=sourceRotation.Z;
|
||||
targetPitch=targetYaw=targetRoll=0;facingDirty=false;BubbleBounces=0;
|
||||
forwardAirPitch=JimmyAirMotion.ForwardPitch;backwardAirPitch=JimmyAirMotion.BackwardPitch;
|
||||
MaximumSpeed=RecoveredMotion.MaximumSpeed; BodyFactor=OriginalBodySupport.JimmyFactor;
|
||||
var floor = collision.GroundHeight(sourceStart, 2500)!.Value;
|
||||
Position = new(sourceStart.X, floor + (UsesOriginalBody ? 0 : SceneCollision.Skin), sourceStart.Z);
|
||||
Velocity = Vector3.Zero;
|
||||
Yaw = targetYaw = startYaw;
|
||||
Yaw = sourceRotation.Y;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = shadowDistance = 0;
|
||||
lateralContribution = 0; pendingImpulse = Vector3.Zero; movementMode = 0;
|
||||
keyboardTurn=false;hasSupportPolygon=false;
|
||||
@@ -214,7 +228,8 @@ public sealed class LabSimulation
|
||||
}
|
||||
|
||||
public PlayerLevelState? CaptureLevelState(int selectedGadget) => Noclip ? null
|
||||
: new(LevelCode, selectedGadget, movementMode, jumpState.HoldSeconds, jumpState.EffectRemaining);
|
||||
: new(LevelCode, selectedGadget, movementMode, jumpState.HoldSeconds, jumpState.EffectRemaining,
|
||||
forwardAirPitch,backwardAirPitch);
|
||||
|
||||
/// <summary>Apply after destination construction. Init re-applies authored
|
||||
/// body vectors and clears speed/turn; PostLoad resets jump, not these scalars.
|
||||
@@ -224,10 +239,12 @@ public sealed class LabSimulation
|
||||
ArgumentNullException.ThrowIfNull(state);
|
||||
if (!state.SupportsDestination(LevelCode)) return false;
|
||||
if (state.MovementMode is < 0 or > 1 || !float.IsFinite(state.HoldSeconds)
|
||||
|| state.HoldSeconds < 0 || !float.IsFinite(state.EffectRemaining))
|
||||
|| state.HoldSeconds < 0 || !float.IsFinite(state.EffectRemaining)
|
||||
|| !float.IsFinite(state.ForwardPitch)||!float.IsFinite(state.BackwardPitch))
|
||||
throw new ArgumentOutOfRangeException(nameof(state));
|
||||
movementMode = state.MovementMode;
|
||||
jumpState = new(0, state.HoldSeconds, state.EffectRemaining);
|
||||
forwardAirPitch=state.ForwardPitch;backwardAirPitch=state.BackwardPitch;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -295,10 +312,9 @@ public sealed class LabSimulation
|
||||
public void EnterScooter()
|
||||
{
|
||||
CancelPoweredFlight(); //425120 only cancels mode1 jump/effect.
|
||||
TracksBubbleOrientation=true;
|
||||
}
|
||||
public void ApplyScooterTransform(Vector3 root,Vector3 rotation)
|
||||
{ApplyAuthoredTransform(root,rotation.Y);Pitch=rotation.X;Roll=rotation.Z;targetPitch=Pitch;targetRoll=Roll;targetYaw=Yaw;}
|
||||
{ApplyAuthoredTransform(root,rotation);SetFacingDestination(rotation);}
|
||||
public void LeaveScooter(Vector3 root,Vector3 rotation,Vector3 eye)
|
||||
{
|
||||
ApplyScooterTransform(root+Vector3.UnitY*40,rotation);
|
||||
@@ -342,11 +358,6 @@ public sealed class LabSimulation
|
||||
}
|
||||
|
||||
public void FlattenOrientation() { Pitch=Roll=0; }
|
||||
public void SeedBubbleTilt(Vector3 euler)
|
||||
{
|
||||
if (TracksBubbleOrientation) return;
|
||||
Pitch=targetPitch=euler.X; Roll=targetRoll=euler.Z;
|
||||
}
|
||||
|
||||
private void StepFloorPolicy()
|
||||
{
|
||||
@@ -384,6 +395,13 @@ public sealed class LabSimulation
|
||||
Position = root - Vector3.UnitY * rootHeight; Yaw = yaw;
|
||||
}
|
||||
|
||||
public void ApplyAuthoredTransform(Vector3 root,Vector3 rotation)
|
||||
{
|
||||
if(!float.IsFinite(rotation.X)||!float.IsFinite(rotation.Y)||!float.IsFinite(rotation.Z))
|
||||
throw new ArgumentOutOfRangeException(nameof(rotation));
|
||||
ApplyAuthoredTransform(root,rotation.Y);Pitch=rotation.X;Roll=rotation.Z;
|
||||
}
|
||||
|
||||
/// <summary>Modern debug movement; never serialized into original save state.</summary>
|
||||
public bool SetNoclip(bool enabled)
|
||||
{
|
||||
@@ -410,7 +428,9 @@ public sealed class LabSimulation
|
||||
Velocity = pendingImpulse = Vector3.Zero;
|
||||
Speed = PublishedSpeed = TurnRate = extraAirAcceleration = lateralContribution = 0;
|
||||
jumpState = default; movementMode = 0; forceFall = JetpackEffectVisible = false;
|
||||
targetYaw = Yaw;
|
||||
//Modern debug stop freezes the retained facing request as well as body
|
||||
//motion. Otherwise entering noclip can leave a queued airborne lean.
|
||||
targetPitch=Pitch;targetYaw=Yaw;targetRoll=Roll;facingDirty=false;
|
||||
}
|
||||
|
||||
public bool ReturnToNoclipEntry()
|
||||
@@ -451,26 +471,25 @@ public sealed class LabSimulation
|
||||
//does not invent a hold timer or admit its seeded auto-turn branch.
|
||||
var ground=JimmyGroundMotion.Input(new(Speed,targetYaw),Yaw,input,MaximumSpeed,
|
||||
blockBackward:(GadgetMode is -1 or 3)&&input.Fire);
|
||||
Speed=ground.State.Speed;targetYaw=ground.State.TargetYaw;lateralContribution=ground.Lateral;
|
||||
Speed=ground.State.Speed;lateralContribution=ground.Lateral;
|
||||
if(input.Left||input.Right)keyboardTurn=true;
|
||||
if(ground.HeadingUpdated)targetPitch=targetRoll=0;
|
||||
if(ground.HeadingUpdated)SetFacingDestination(new(0,ground.State.TargetYaw,0));
|
||||
}
|
||||
else if (movementMode==2)
|
||||
{
|
||||
var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed);
|
||||
var steering=BubbleMotion.StepInput(Speed,TurnRate,input,Grounded,dt,MaximumSpeed,forwardAirPitch,backwardAirPitch);
|
||||
Speed=steering.Speed; TurnRate=steering.TurnRate;
|
||||
if(input.Left||input.Right)keyboardTurn=true;
|
||||
targetPitch=steering.TargetPitch; targetRoll=steering.TargetRoll; targetYaw=Yaw;
|
||||
SetFacingDestination(new(steering.TargetPitch,Yaw,steering.TargetRoll));
|
||||
}
|
||||
else
|
||||
{
|
||||
var steering = JimmyAirMotion.Input(new(Speed,TurnRate,keyboardTurn),input,Grounded,dt,MaximumSpeed);
|
||||
Speed = steering.Speed; TurnRate = steering.TurnRate;
|
||||
keyboardTurn=steering.KeyboardTurn;
|
||||
if (TracksBubbleOrientation) { targetPitch=0; targetRoll=-TurnRate; }
|
||||
//439E2B preserves current yaw as the destination; air apply then
|
||||
//438011..43802B adds the independent turn rate directly to yaw.
|
||||
targetYaw = Yaw;
|
||||
SetFacingDestination(JimmyAirMotion.Destination(input,Yaw,TurnRate,forwardAirPitch,backwardAirPitch));
|
||||
}
|
||||
Baseball.StepCameraInput(input);
|
||||
StepCamera(); //438BC0/439900 input path owns follow; still provisional geometry/state.
|
||||
@@ -497,16 +516,22 @@ public sealed class LabSimulation
|
||||
|
||||
private void StepFacing()
|
||||
{
|
||||
var rotation=JimmyOrientation.Step(new(Pitch,Yaw,Roll),new(targetPitch,targetYaw,targetRoll),FixedStepClock.Step);
|
||||
var before=Rotation;
|
||||
var rotation=JimmyOrientation.Step(before,FacingTarget,FixedStepClock.Step,dirty:facingDirty);
|
||||
if(facingDirty)facingDirty=before!=FacingTarget;
|
||||
Pitch=rotation.X;Yaw=rotation.Y;Roll=rotation.Z;
|
||||
}
|
||||
|
||||
private void SetFacingDestination(Vector3 target)
|
||||
{targetPitch=target.X;targetYaw=target.Y;targetRoll=target.Z;facingDirty=true;}
|
||||
|
||||
private void StepPlayer(PlayerInput input)
|
||||
{
|
||||
ControllerSteps++;
|
||||
const float dt = FixedStepClock.Step;
|
||||
if (movementMode==2)
|
||||
{
|
||||
forwardAirPitch=-10;backwardAirPitch=10; //43880A/438814, after input when fresh.
|
||||
var bubble=BubbleMotion.StepApply(Speed,TurnRate,Yaw,Pitch,Velocity,Grounded,input.Jump,dt);
|
||||
Velocity=bubble.Velocity; Yaw=bubble.Yaw; Speed=bubble.Speed; PublishedSpeed=Speed;
|
||||
if (Grounded) { BubbleBounces++; if (bubble.Boing) GadgetSound?.Invoke(106,false); }
|
||||
@@ -528,6 +553,7 @@ public sealed class LabSimulation
|
||||
}
|
||||
else
|
||||
{
|
||||
forwardAirPitch=JimmyAirMotion.ForwardPitch;backwardAirPitch=JimmyAirMotion.BackwardPitch;
|
||||
var airMotion=JimmyAirMotion.Apply(Speed,TurnRate,new(Pitch,Yaw,Roll),Velocity,dt);
|
||||
velocity=airMotion.Velocity;Pitch=airMotion.Rotation.X;Yaw=airMotion.Rotation.Y;Roll=airMotion.Rotation.Z;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user