Skip to content

Commit

Permalink
Improve 3d camera
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Dec 2, 2024
1 parent c697714 commit 4895282
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
19 changes: 18 additions & 1 deletion TSOClient/tso.world/Components/SM64Component.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,29 @@ public Tuple<Vector3, Vector3> GetBaseMarioPos()
return new Tuple<Vector3, Vector3>(pos, angle);
}

public bool TileIndoors(int x, int y, int level)
{
if (x < 0 || y < 0 || level < 0 || x >= Bp.Width || y >= Bp.Height || level >= Bp.Stories)
{
return false;
}

var room = Bp.RoomMap[level - 1][x + y * Bp.Width];
var room1 = room & 0xFFFF;
var room2 = (room >> 16) & 0x7FFF;
if (room1 < Bp.Rooms.Count && !Bp.Rooms[(int)room1].IsOutside) return true;
if (room2 > 0 && room2 < Bp.Rooms.Count && !Bp.Rooms[(int)room2].IsOutside) return true;
return false;
}

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

return (sbyte)(Math.Max(0, Math.Min(Bp.Stories - 1, Math.Floor((height + 0.5f) / 2.95f))) + 1);
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);
}

public void RemoveMario(AvatarComponent avatar)
Expand Down
14 changes: 12 additions & 2 deletions TSOClient/tso.world/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,18 @@ public Tuple<float, float> Get3DTTHeights()
{
if (Blueprint == null) { return new Tuple<float, float>(0, 0); }
var terrainHeight = (Blueprint.InterpAltitude(new Vector3(State.CenterTile, 0))) * 3;
var targHeight = terrainHeight + (State.Level - 1) * 2.95f * 3;
targHeight = Math.Max((Blueprint.InterpAltitude(new Vector3(State.Camera.Position.X, State.Camera.Position.Z, 0) / 3) + (State.Level - 1) * 2.95f) * 3, terrainHeight);

float targHeight;

if (State.ScrollAnchor?.MyMario != null)
{
targHeight = State.ScrollAnchor.MyMario.GetMarioPosition().Z * 3;
}
else
{
targHeight = Math.Max((Blueprint.InterpAltitude(new Vector3(State.Camera.Position.X, State.Camera.Position.Z, 0) / 3) + (State.Level - 1) * 2.95f) * 3, terrainHeight);
}

return new Tuple<float, float>(terrainHeight, targHeight);
}

Expand Down

0 comments on commit 4895282

Please sign in to comment.