From 358b79bbb008da1aeab6778f15cf559cf142390f Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Sun, 8 Feb 2026 21:20:35 +0000 Subject: [PATCH] render ortho map thumbnails --- src/main/java/game/map/editor/MapEditor.java | 54 ++++++++++++++++++- .../map/editor/camera/PerspBaseCamera.java | 9 +++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/game/map/editor/MapEditor.java b/src/main/java/game/map/editor/MapEditor.java index f8a206a..8e43315 100644 --- a/src/main/java/game/map/editor/MapEditor.java +++ b/src/main/java/game/map/editor/MapEditor.java @@ -399,6 +399,7 @@ public class MapEditor extends GLEditor implements MouseManagerListener, Keyboar public PostProcessFX postProcessFX = PostProcessFX.NONE; public boolean thumbnailMode = false; + public float thumbnailOrthoHalfHeight = 500f; public boolean showModels; public boolean showColliders; public boolean showZones; @@ -747,11 +748,62 @@ public class MapEditor extends GLEditor implements MouseManagerListener, Keyboar obj.hidden = true; for (MapObject obj : getCollisionMap().zoneTree) obj.hidden = true; - // for(MapObject obj : map.markerTree) obj.hidden = true; if (!thumbnailInitialized) initThumbnail(); + // Isometric camera: 45 degrees right, 45 degrees down + var camera = perspectiveView.camera; + camera.yaw = -45f; + camera.pitch = 45f; + + // Frame the map's model tree AABB + BoundingBox aabb = map.modelTree.getRoot().getUserObject().AABB; + Vector3f center = aabb.getCenter(); + camera.setPosition(center); + + // Project all 8 AABB corners through the view rotation to find + // the screen-space bounding box. View = Rx(pitch) * Ry(yaw) * (p - center). + Vector3f bmin = aabb.getMin(); + Vector3f bmax = aabb.getMax(); + float[] xs = { bmin.x, bmax.x }; + float[] ys = { bmin.y, bmax.y }; + float[] zs = { bmin.z, bmax.z }; + + double yawRad = Math.toRadians(-45); + double pitchRad = Math.toRadians(45); + double cy = Math.cos(yawRad), sy = Math.sin(yawRad); + double cp = Math.cos(pitchRad), sp = Math.sin(pitchRad); + + float screenMinX = Float.MAX_VALUE, screenMaxX = -Float.MAX_VALUE; + float screenMinY = Float.MAX_VALUE, screenMaxY = -Float.MAX_VALUE; + for (float wx : xs) { + for (float wy : ys) { + for (float wz : zs) { + // translate to camera-relative + float px = wx - center.x; + float py = wy - center.y; + float pz = wz - center.z; + // Ry(yaw) + float rx = (float)(px * cy + pz * sy); + float ry = py; + float rz = (float)(-px * sy + pz * cy); + // Rx(pitch) + float sx = rx; + float syt = (float)(ry * cp - rz * sp); + // screen X = sx, screen Y = syt + screenMinX = Math.min(screenMinX, sx); + screenMaxX = Math.max(screenMaxX, sx); + screenMinY = Math.min(screenMinY, syt); + screenMaxY = Math.max(screenMaxY, syt); + } + } + } + + float halfW = (screenMaxX - screenMinX) / 2f; + float halfH = (screenMaxY - screenMinY) / 2f; + thumbnailOrthoHalfHeight = Math.max(Math.max(halfW, halfH), 50f); + perspectiveView.resize(0, 0, size, size); for (int i = 0; i < 2; i++) { diff --git a/src/main/java/game/map/editor/camera/PerspBaseCamera.java b/src/main/java/game/map/editor/camera/PerspBaseCamera.java index 13874e3..025f281 100644 --- a/src/main/java/game/map/editor/camera/PerspBaseCamera.java +++ b/src/main/java/game/map/editor/camera/PerspBaseCamera.java @@ -109,7 +109,14 @@ public abstract class PerspBaseCamera extends MapEditCamera currentZfar = scriptData.camFarClip.get(); } - projMatrix.perspective(currentVfov, currentAspectRatio, currentZnear, currentZfar); + if (editor.thumbnailMode) { + float halfH = editor.thumbnailOrthoHalfHeight; + float halfW = halfH * currentAspectRatio; + projMatrix.ortho(-halfW, halfW, -halfH, halfH, -currentZfar, currentZfar); + } + else { + projMatrix.perspective(currentVfov, currentAspectRatio, currentZnear, currentZfar); + } } @Override -- 2.51.2