Skip to content

fix: stabilize LookAt for parallel up vectors - #29

Merged
kolkov merged 1 commit into
gogpu:mainfrom
besmpl:agent/fix-lookat-parallel-up
Aug 11, 2026
Merged

fix: stabilize LookAt for parallel up vectors#29
kolkov merged 1 commit into
gogpu:mainfrom
besmpl:agent/fix-lookat-parallel-up

Conversation

@besmpl

@besmpl besmpl commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What changed

  • normalize the caller's up vector before testing LookAt basis stability
  • provide deterministic fallback axes for parallel and anti-parallel view/up directions
  • preserve conventional +Y orientation for a zero up vector and a valid -Z view for coincident eye/target positions
  • add matrix- and node-level regressions for parallel, anti-parallel, near-parallel, scaled, zero, tiny, and ordinary inputs

Why

Mat4LookAt previously normalized forward × up without handling a zero cross product. A camera directly above or below its target with the conventional {0,1,0} up vector therefore produced a singular view matrix. This includes the top-down camera arrangement shown in the project documentation; projected points could end up with an invalid clip-space w.

The fix constructs a stable, right-handed orthonormal basis while keeping ordinary non-degenerate views unchanged.

Impact

Top-down and bottom-up cameras now orient correctly instead of producing a zero basis. Up-vector magnitude no longer affects the result, and boundary inputs remain finite and deterministic.

Verification

  • focused Mat4LookAt, Node.LookAt, and camera tests (including repeated and race runs)
  • go test ./...
  • go test -race ./...
  • go build ./...
  • go vet ./...
  • CGO-disabled Linux, Windows, and Darwin cross-builds
  • gofmt and git diff --check
  • baseline discrimination and independent review

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@besmpl
besmpl marked this pull request as ready for review August 10, 2026 19:30
@besmpl
besmpl requested a review from kolkov as a code owner August 10, 2026 19:30
@besmpl
besmpl force-pushed the agent/fix-lookat-parallel-up branch from be43ffa to 2738613 Compare August 10, 2026 20:37

@kolkov kolkov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code reviewed: robust LookAt degenerate case handling — zero direction, zero up, parallel up/forward fallbacks. Bitwise epsilon comparison correct. 10 tests with orthonormal basis validation. LGTM.

@kolkov
kolkov merged commit 4107255 into gogpu:main Aug 11, 2026
10 checks passed
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