Skip to content

Commit 1fbaacd

Browse files
committed
Add Image::set_passive().
1 parent c86a9d3 commit 1fbaacd

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trackball"
3-
version = "0.17.0"
3+
version = "0.17.1"
44
rust-version = "1.87.0"
55
edition = "2024"
66
authors = ["Rouven Spreckels <rs@qu1x.dev>"]

RELEASES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 0.17.1 (2025-10-19)
2+
3+
* Add `Image::set_passive()`.
4+
15
# Version 0.17.0 (2025-10-05)
26

37
* Bump MSRV.

src/image.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ pub struct Image<N: Copy + RealField> {
3030
compute_mat: bool,
3131
/// Whether to compute inverse transformation. Default is `true`.
3232
compute_inv: bool,
33+
/// Whether to use passive transformations. Default is `false`.
34+
use_passive: bool,
3335
}
3436

3537
impl<N: Copy + RealField> Image<N> {
@@ -49,11 +51,14 @@ impl<N: Copy + RealField> Image<N> {
4951
proj_view_inv: zero(),
5052
compute_mat: true,
5153
compute_inv: true,
54+
use_passive: false,
5255
};
53-
image.compute_view(frame);
54-
image.compute_projection_and_upp(frame.distance(), scope);
55-
image.compute_transformation();
56-
image.compute_inverse_transformation();
56+
if frame.distance() != N::zero() {
57+
image.compute_view(frame);
58+
image.compute_projection_and_upp(frame.distance(), scope);
59+
image.compute_transformation();
60+
image.compute_inverse_transformation();
61+
}
5762
image
5863
}
5964
/// Recomputes only cached matrices whose parameters have changed, see [`Self::set_compute()`].
@@ -90,6 +95,12 @@ impl<N: Copy + RealField> Image<N> {
9095
self.compute_mat = compute_mat;
9196
self.compute_inv = compute_inv;
9297
}
98+
/// Sets whether to use passive transformations.
99+
///
100+
/// Default is `false`.
101+
pub const fn set_passive(&mut self, use_passive: bool) {
102+
self.use_passive = use_passive;
103+
}
93104
/// Current position in screen space of hovering input or pointing device.
94105
#[must_use]
95106
pub const fn pos(&self) -> &Point2<N> {
@@ -129,7 +140,11 @@ impl<N: Copy + RealField> Image<N> {
129140
}
130141
/// Computes view isometry and matrix from frame wrt camera eye and target.
131142
pub fn compute_view(&mut self, frame: &Frame<N>) {
132-
self.view_iso = frame.view();
143+
self.view_iso = if self.use_passive {
144+
frame.inverse_view()
145+
} else {
146+
frame.view()
147+
};
133148
self.view_mat = self.view_iso.to_homogeneous();
134149
}
135150
/// Cached projection matrix.
@@ -229,6 +244,7 @@ impl<N: Copy + RealField> Image<N> {
229244
proj_view_inv: self.proj_view_inv.cast(),
230245
compute_mat: self.compute_mat,
231246
compute_inv: self.compute_inv,
247+
use_passive: self.use_passive,
232248
}
233249
}
234250
}

0 commit comments

Comments
 (0)