Skip to content

Remember projection mode across app restarts - #19

Merged
ad-si merged 1 commit into
mainfrom
claude/luacad-issue-18-hwnhb0
Aug 20, 2026
Merged

Remember projection mode across app restarts#19
ad-si merged 1 commit into
mainfrom
claude/luacad-issue-18-hwnhb0

Conversation

@ad-si

@ad-si ad-si commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary

This PR adds persistence for the 3D view projection mode (orthogonal vs perspective) across application restarts, and improves camera distance handling to maintain consistent apparent scene size when switching projections.

Key Changes

  • Projection persistence: The selected projection mode is now saved to the state file and restored on app launch, defaulting to orthogonal (like OpenSCAD)
  • New set_orthogonal_view() method: Centralizes projection switching logic with automatic camera distance adjustment to keep the scene at the same apparent size
  • Extracted projection_distance_ratio() function: Eliminates magic number duplication and documents the mathematical relationship (tan(22.5°)) between orthogonal and perspective camera distances
  • Updated reset_camera(): Now respects the current projection mode when setting the default camera distance, instead of always using the orthogonal distance
  • UI simplification: Projection toggle buttons now call the new set_orthogonal_view() method instead of duplicating the distance calculation logic
  • Comprehensive test coverage: Added three tests validating projection switching behavior, no-op switches, and camera reset with different projections

Implementation Details

  • The distance ratio is calculated as 1.0 / tan(22.5°) where 22.5° is half the perspective FOV
  • When switching from orthogonal to perspective, the camera distance is multiplied by the ratio (perspective needs larger distance for same apparent size)
  • The projection state is persisted alongside existing settings (hide_editor, auto_reload) in the state file
  • All distance calculations now use the centralized projection_distance_ratio() function for consistency

https://claude.ai/code/session_01MB6F4dt6mJBviL7su3RKYz

Studio defaulted to the orthogonal projection on every launch, so a
perspective view had to be re-selected each time. The choice is now
persisted as `orthogonal_view` in `~/.config/luacad/state.json`, next to
`hide_editor` and `auto_reload`, and restored at startup.

Switching the projection moves the camera so the scene keeps its
apparent size. That conversion, previously inline in the bottom bar,
moves into `AppState::set_orthogonal_view` so restoring the setting at
startup goes through the same path, and the ratio it uses (the
perspective/orthogonal distance factor for the 45° FOV) is shared with
the raytrace framing instead of being spelled out twice.

`reset_camera` now uses the default distance that matches the current
projection as well, rather than always the orthogonal one — resetting
the camera in a perspective view no longer jumps the zoom.

Closes #18

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MB6F4dt6mJBviL7su3RKYz
@ad-si
ad-si merged commit 8282180 into main Aug 20, 2026
13 checks passed
@ad-si
ad-si deleted the claude/luacad-issue-18-hwnhb0 branch August 20, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants