Portrait and square screens: world pixels, interface and zoom count on the shorter side
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
16857f1b9d
commit
25334e7b17
2 files changed
+18
-5
No files matched your search
+12
-4
@@ -85,12 +85,18 @@ impl Cam {
|
||||
vec3(self.rx, 0.0, self.rz)
|
||||
}
|
||||
|
||||
// visible world height in tiles: the zoom counts on the shorter side (upright screens: across)
|
||||
pub fn view_h(&self) -> f32 {
|
||||
let (w, h) = (screen_width().max(1.0), screen_height().max(1.0));
|
||||
if h > w { self.zoom * h / w } else { self.zoom }
|
||||
}
|
||||
|
||||
pub fn camera(&self) -> Camera3D {
|
||||
Camera3D {
|
||||
position: self.target() + self.eye_dir() * 60.0,
|
||||
target: self.target(),
|
||||
up: Vec3::Y,
|
||||
fovy: self.zoom,
|
||||
fovy: self.view_h(),
|
||||
projection: Projection::Orthographics,
|
||||
z_near: 1.0,
|
||||
z_far: 200.0,
|
||||
@@ -114,7 +120,7 @@ impl Cam {
|
||||
|
||||
pub fn ray(&self, sx: f32, sy: f32) -> (Vec3, Vec3) {
|
||||
let (f, r, u) = self.basis();
|
||||
let half_h = self.zoom * 0.5;
|
||||
let half_h = self.view_h() * 0.5;
|
||||
let half_w = half_h * screen_width() / screen_height();
|
||||
let nx = sx / screen_width() * 2.0 - 1.0;
|
||||
let ny = 1.0 - sy / screen_height() * 2.0;
|
||||
@@ -1468,7 +1474,7 @@ impl R3d {
|
||||
// Entity under the mouse (screen-space test against the projected sprite)
|
||||
pub fn pick_ent(&self, g: &Game, cam: &Cam, sx: f32, sy: f32, player_only: bool) -> Option<usize> {
|
||||
let m = cam.matrix();
|
||||
let px_per_tile = screen_height() / cam.zoom;
|
||||
let px_per_tile = screen_height() / cam.view_h();
|
||||
let mut best = None;
|
||||
let mut bd = (px_per_tile * 0.4).max(10.0);
|
||||
for (j, e) in g.ents.iter().enumerate() {
|
||||
@@ -1494,7 +1500,9 @@ impl R3d {
|
||||
// on the virtual screen (ui.rs) the world takes exactly k x k interface pixels per pixel
|
||||
let vrows = crate::ui::virtual_rows();
|
||||
let pix = if vrows > 0 && self.pixel_rows > 0 {
|
||||
let k = (vrows / self.pixel_rows).max(1);
|
||||
// the pixel rows count on the shorter side (upright screens: across)
|
||||
let short = vrows.min(crate::ui::sw().round() as u32);
|
||||
let k = (short / self.pixel_rows).max(1);
|
||||
let th = vrows / k;
|
||||
Some(((crate::ui::sw() / k as f32).ceil() as u32, th, k as f32))
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user