Skip to content

Commit

Permalink
Fix lighting error
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Dec 2, 2024
1 parent 4895282 commit 06eddbe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
23 changes: 23 additions & 0 deletions TSOClient/tso.world/Components/Model/SM64ObjectGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ internal class SM64ObjectGeometry
}
);

private static SM64ObjectGeometryObj GenStairsGeo(float baseHeight)
{
int steps = 6;
float stepSize = 1f / steps;

var entries = new SM64ObjectGeometry4C[steps];

for (int i = 0; i < steps; i++)
{
float step = i * stepSize;
float step1 = (i + 1) * stepSize;
float s0 = (baseHeight + 0.25f * step1) * 2.95f;
entries[i] = new SM64ObjectGeometry4C(new Vector3(0, s0, 1f - step), new Vector3(1, s0, 1f - step), new Vector3(1, s0, 1 - step1), new Vector3(0, s0, 1 - step1));
}

return new SM64ObjectGeometryObj(entries);
}

private static SM64ObjectGeometryObj StairLowAdv = GenStairsGeo(0f);
private static SM64ObjectGeometryObj StairMiddleLowAdv = GenStairsGeo(0.25f);
private static SM64ObjectGeometryObj StairMiddleHiAdv = GenStairsGeo(0.5f);
private static SM64ObjectGeometryObj StairHiAdv = GenStairsGeo(0.75f);

private static SM64ObjectGeometryObj StairLow = new SM64ObjectGeometryObj(
new SM64ObjectGeometry4C[] {
new SM64ObjectGeometry4C(new Vector3(0, 0, 1), new Vector3(1, 0, 1), new Vector3(1, 2.95f * 0.25f, 0), new Vector3(0, 2.95f * 0.25f, 0))
Expand Down
10 changes: 5 additions & 5 deletions TSOClient/tso.world/Components/SM64Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ public Tuple<float, float> CalculateVolumePan()
return new Tuple<float, float>(volume, pan);
}

public sbyte DetermineLevel()
public sbyte DetermineLevel(bool forLight)
{
return Component.DetermineLevel(GetMarioPosition());
return Component.DetermineLevel(GetMarioPosition(), forLight);
}
}

Expand Down Expand Up @@ -363,14 +363,14 @@ public bool TileIndoors(int x, int y, int level)
return false;
}

public sbyte DetermineLevel(Vector3 pos)
public sbyte DetermineLevel(Vector3 pos, bool forLight)
{
float elevation = Bp.InterpAltitude(pos);
float height = pos.Z - elevation;

sbyte level = (sbyte)(Math.Max(0, Math.Min(Bp.Stories - 1, Math.Floor((height + 0.5f) / 2.95f))) + 1);

return TileIndoors((int)pos.X, (int)pos.Y, level) ? level : (sbyte)(Bp.Stories - 1);
return forLight || TileIndoors((int)pos.X, (int)pos.Y, level) ? level : (sbyte)(Bp.Stories - 1);
}

public void RemoveMario(AvatarComponent avatar)
Expand Down Expand Up @@ -770,7 +770,7 @@ private void DrawMario(GraphicsDevice gd, WorldState state, VisualMario visual)
rotation = SmartLerp(visual.LastRotation, rotation, visual.InterpProgress, 0.4f);
scale = Vector3.Lerp(visual.LastScale, scale, visual.InterpProgress);

sbyte level = visual.DetermineLevel();
sbyte level = visual.DetermineLevel(true);

Matrix world = Matrix.CreateScale(scale) *
Matrix.CreateRotationZ(rotation.Z) *
Expand Down
2 changes: 1 addition & 1 deletion TSOClient/tso.world/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public void CenterTo(EntityComponent comp)

if (((AvatarComponent)comp).MyMario != null)
{
level = ((AvatarComponent)comp).MyMario.DetermineLevel();
level = ((AvatarComponent)comp).MyMario.DetermineLevel(false);
}
}
else
Expand Down

0 comments on commit 06eddbe

Please sign in to comment.