forked from 1b-agent/opencadstudio-upstream
fix: correct ViewCubeSnap and MSPACE orbit to write viewport entity
- Add orbit_active_viewport(), snap_active_viewport_to_angles(), active_view_rotation_mat(), active_viewport_yaw_pitch() helpers so navigation gestures modify the DXF viewport entity's view_direction instead of the paper-space camera. - Fix "already there → flip opposite" check: the previous code used rot * Vec4::W (always (0,0,0,1) for a rotation matrix); now reads (yaw, pitch) directly from camera_for_viewport() via the new helper. - MSPACE right-drag orbit early-returns after writing the viewport entity, preventing the paper-space camera from also being modified. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
This commit is contained in:
1 parent
7e0e892bcc
commit
f176f7c80a
2 files changed
+101
-9
No files matched your search
@@ -976,6 +976,72 @@ impl Scene {
|
||||
}
|
||||
}
|
||||
|
||||
/// Orbit the active viewport's view direction by the given screen-pixel delta.
|
||||
/// No-op when there is no active viewport or it is locked.
|
||||
pub fn orbit_active_viewport(&mut self, delta_x: f32, delta_y: f32) {
|
||||
let vp_handle = match self.active_viewport {
|
||||
Some(h) => h,
|
||||
None => return,
|
||||
};
|
||||
let mut cam = match self.camera_for_viewport(vp_handle) {
|
||||
Some(c) => c,
|
||||
None => return,
|
||||
};
|
||||
cam.orbit(delta_x, delta_y);
|
||||
// Write the new view direction back to the viewport entity.
|
||||
let eye = cam.rotation * glam::Vec3::Z;
|
||||
if let Some(acadrust::EntityType::Viewport(vp)) =
|
||||
self.document.get_entity_mut(vp_handle)
|
||||
{
|
||||
if vp.status.locked {
|
||||
return;
|
||||
}
|
||||
vp.view_direction.x = eye.x as f64;
|
||||
vp.view_direction.y = eye.y as f64;
|
||||
vp.view_direction.z = eye.z as f64;
|
||||
}
|
||||
}
|
||||
|
||||
/// Snap the active viewport's view direction to a canonical yaw/pitch.
|
||||
/// No-op when there is no active viewport or it is locked.
|
||||
pub fn snap_active_viewport_to_angles(&mut self, yaw: f32, pitch: f32) {
|
||||
let vp_handle = match self.active_viewport {
|
||||
Some(h) => h,
|
||||
None => return,
|
||||
};
|
||||
let cos_p = pitch.cos();
|
||||
let eye = glam::Vec3::new(cos_p * yaw.sin(), cos_p * yaw.cos(), pitch.sin());
|
||||
if let Some(acadrust::EntityType::Viewport(vp)) =
|
||||
self.document.get_entity_mut(vp_handle)
|
||||
{
|
||||
if vp.status.locked {
|
||||
return;
|
||||
}
|
||||
vp.view_direction.x = eye.x as f64;
|
||||
vp.view_direction.y = eye.y as f64;
|
||||
vp.view_direction.z = eye.z as f64;
|
||||
}
|
||||
}
|
||||
|
||||
/// View-rotation matrix for the active viewport (MSPACE), or the
|
||||
/// paper-space camera's matrix when not in MSPACE.
|
||||
/// Used by ViewCube hit-testing so clicks map to the correct camera.
|
||||
pub fn active_view_rotation_mat(&self) -> glam::Mat4 {
|
||||
if let Some(h) = self.active_viewport {
|
||||
if let Some(cam) = self.camera_for_viewport(h) {
|
||||
return cam.view_rotation_mat();
|
||||
}
|
||||
}
|
||||
self.camera.borrow().view_rotation_mat()
|
||||
}
|
||||
|
||||
/// Return (yaw, pitch) of the active viewport's camera, or None if PSPACE.
|
||||
pub fn active_viewport_yaw_pitch(&self) -> Option<(f32, f32)> {
|
||||
let h = self.active_viewport?;
|
||||
let cam = self.camera_for_viewport(h)?;
|
||||
Some((cam.yaw, cam.pitch))
|
||||
}
|
||||
|
||||
/// Return the handle of the user viewport whose bounding rectangle contains
|
||||
/// the given paper-space point, or `None` if no viewport matches.
|
||||
pub fn viewport_at_paper_point(&self, px: f32, py: f32) -> Option<Handle> {
|
||||
|
||||
Reference in new issue
Block a user