chore(glam): use camera-module projection API for deprecated Mat4 rh ctors

glam 0.33.2 deprecated Mat4::{orthographic,perspective,look_at}_rh in
favour of the glam:📷:rh::* functions. Switch the 7 call sites in
camera.rs and viewcube.rs to the equivalent camera-module functions
(directx orthographic/perspective = same [0,1] depth range; look_at_mat4
= same view matrix), silencing the deprecation warnings. No behaviour
change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-17 01:49:26 +03:00
commit 3e34da4ac6
2 changed files with 10 additions and 7 deletions

View file

@ -10,6 +10,7 @@
// with arcball orbit at all angles. // with arcball orbit at all angles.
use bytemuck::{Pod, Zeroable}; use bytemuck::{Pod, Zeroable};
use glam::camera::rh::proj::directx::orthographic;
use glam::{Mat4, Vec3, Vec4}; use glam::{Mat4, Vec3, Vec4};
use iced::wgpu; use iced::wgpu;
use iced::{Rectangle, Size}; use iced::{Rectangle, Size};
@ -208,7 +209,7 @@ impl CubeUniforms {
let inset = cube_half * NAV_INSET_F; let inset = cube_half * NAV_INSET_F;
let cx = hw - inset - VIEWCUBE_PAD; let cx = hw - inset - VIEWCUBE_PAD;
let cy = hh - inset - VIEWCUBE_PAD; let cy = hh - inset - VIEWCUBE_PAD;
let view_proj = Mat4::orthographic_rh(-hw, hw, -hh, hh, -2000.0, 2000.0) let view_proj = orthographic(-hw, hw, -hh, hh, -2000.0, 2000.0)
* Mat4::from_translation(Vec3::new(cx, cy, 0.0)) * Mat4::from_translation(Vec3::new(cx, cy, 0.0))
* Mat4::from_scale(Vec3::splat(cube_px as f32 * VIEWCUBE_SCALE)); * Mat4::from_scale(Vec3::splat(cube_px as f32 * VIEWCUBE_SCALE));
Self { Self {
@ -580,7 +581,7 @@ impl ViewCubeText {
let cube_half = cube_px as f32 * VIEWCUBE_SCALE; let cube_half = cube_px as f32 * VIEWCUBE_SCALE;
let inset = cube_half * NAV_INSET_F; let inset = cube_half * NAV_INSET_F;
let (hw, hh) = (vw * 0.5, vh * 0.5); let (hw, hh) = (vw * 0.5, vh * 0.5);
let view_proj = Mat4::orthographic_rh(-hw, hw, -hh, hh, -2000.0, 2000.0) let view_proj = orthographic(-hw, hw, -hh, hh, -2000.0, 2000.0)
* Mat4::from_translation(Vec3::new( * Mat4::from_translation(Vec3::new(
hw - inset - VIEWCUBE_PAD, hw - inset - VIEWCUBE_PAD,
hh - inset - VIEWCUBE_PAD, hh - inset - VIEWCUBE_PAD,
@ -1349,7 +1350,7 @@ pub fn hit_test(
} }
let (hw, hh) = (vp_w * 0.5, vp_h * 0.5); let (hw, hh) = (vp_w * 0.5, vp_h * 0.5);
let vp = Mat4::orthographic_rh(-hw, hw, -hh, hh, -2000.0, 2000.0) let vp = orthographic(-hw, hw, -hh, hh, -2000.0, 2000.0)
* Mat4::from_translation(Vec3::new( * Mat4::from_translation(Vec3::new(
hw - inset - VIEWCUBE_PAD, hw - inset - VIEWCUBE_PAD,
hh - inset - VIEWCUBE_PAD, hh - inset - VIEWCUBE_PAD,
@ -1431,7 +1432,7 @@ pub fn hit_test_cardinal(
} }
let (hw, hh) = (vp_w * 0.5, vp_h * 0.5); let (hw, hh) = (vp_w * 0.5, vp_h * 0.5);
let vp = Mat4::orthographic_rh(-hw, hw, -hh, hh, -2000.0, 2000.0) let vp = orthographic(-hw, hw, -hh, hh, -2000.0, 2000.0)
* Mat4::from_translation(Vec3::new( * Mat4::from_translation(Vec3::new(
hw - inset - VIEWCUBE_PAD, hw - inset - VIEWCUBE_PAD,
hh - inset - VIEWCUBE_PAD, hh - inset - VIEWCUBE_PAD,

View file

@ -11,6 +11,8 @@
// //
// Coordinate convention: Z-up world space (same as the rest of OpenCADStudio). // Coordinate convention: Z-up world space (same as the rest of OpenCADStudio).
use glam::camera::rh::proj::directx::{orthographic, perspective};
use glam::camera::rh::view::look_at_mat4;
use glam::{DVec3, Mat4, Quat, Vec3}; use glam::{DVec3, Mat4, Quat, Vec3};
use iced::{Point, Rectangle}; use iced::{Point, Rectangle};
@ -126,19 +128,19 @@ impl Camera {
let aspect = bounds.width / bounds.height; let aspect = bounds.width / bounds.height;
let up_dir = self.rotation * Vec3::Y; let up_dir = self.rotation * Vec3::Y;
let mut view = Mat4::look_at_rh(self.eye().as_vec3(), self.target.as_vec3(), up_dir); let mut view = look_at_mat4(self.eye().as_vec3(), self.target.as_vec3(), up_dir);
// Zero the translation column → pure rotation (world→view basis). // Zero the translation column → pure rotation (world→view basis).
view.w_axis = glam::vec4(0.0, 0.0, 0.0, 1.0); view.w_axis = glam::vec4(0.0, 0.0, 0.0, 1.0);
let proj = match self.projection { let proj = match self.projection {
Projection::Perspective => { Projection::Perspective => {
Mat4::perspective_rh(self.fov_y, aspect, self.distance * 0.001, self.distance * 1000.0) perspective(self.fov_y, aspect, self.distance * 0.001, self.distance * 1000.0)
} }
Projection::Orthographic => { Projection::Orthographic => {
let h = self.ortho_size(); let h = self.ortho_size();
let w = h * aspect; let w = h * aspect;
let (near, far) = self.ortho_depth_range(); let (near, far) = self.ortho_depth_range();
Mat4::orthographic_rh(-w, w, -h, h, near, far) orthographic(-w, w, -h, h, near, far)
} }
}; };
OPENGL_TO_WGPU * proj * view OPENGL_TO_WGPU * proj * view