Expand description
Virtual Trackball Orbiting via the Exponential Map
This is an alternative trackball technique using the exponential map for inducing coherent and intuitive trackball rotations.1 Displacements on straight radial lines through the screen’s center are carried to arcs of the same length on great circles of the trackball, whose half circumference is the maximum of the screen’s width and height. This is in contrast to state-of-the-art techniques using orthogonal projection which distorts radial distances further away from the screen’s center. Each rotation carries the trackball’s point under the previous cursor/finger position along the shortest arc to the one under the current position, keeping the grabbed point under the cursor/finger. This follows the paper’s differential of the exponential map rather than its recipe, which takes the differential to be parallel transport, preserving the lengths of displacements but letting the grabbed point drift. Screen corners beyond the trackball’s border are mapped beyond its equator, keeping radial displacements linear.
§Features
- Common trackball operations split into several operation handlers.
- Coherent and intuitive orbiting via the exponential map, see
Orbitoperation handler. - Identical C11 implementation for
Orbitoperation handler behindccfeature gate. - Coherent
Firstperson view aka free look or mouse look wrtOrbitoperation handler. - Observer
FramewithFrame::slide(),Frame::orbit(),Frame::scale()operations in world space and their local complements in camera space and with orbit and slide operations around arbitrary points in either world or camera space. - Gliding
Clampoperation handler trait ensuring boundary conditions of observerFrame. WhenDeltabetween initial and finalFrameis not orthogonal to a boundaryPlane,Deltais changed in such a way that the clamped movement glides along the plane. Rigidtransformation as direct isometry ofFrame::view()andBound::transform.BoundimplementingClampproviding customizable orthogonal boundary conditions.- Object inspection mode scaling clip plane distances by measuring from target instead of eye.
- Scale-preserving transitioning between orthographic and perspective projection mode.
- Converting between
Fixedquantities wrt to field of view, seeScope::set_fov(). - Time-free
Touchgesture recognition for slide, orbit, scale, and focus operations.
§Math Backend
Like glam, this crate requires one of the following math backends, forwarded to glam:
std(default) for using the math functions of the standard library.libmfor usinglibminstead ofstd, e.g., for consistent results across platforms.nostd-libmfor usinglibmonly ifstdis disabled, e.g., inno_stdenvironments.
This crate is no_std with default-features = false and libm or nostd-libm enabled.
§Optional Features
Following features are disabled unless their corresponding feature gate is enabled:
serdeforserdesupport of various structures of this crate and its dependencies.rkyv-08forrkyv0.8 support of various structures of this crate and its dependencies.ccfor testing the behaviorally identical C implementation of the exponential map.
§Example
A trackball camera mode implementation can be as easy as this by delegating events of your 3D
graphics library of choice to the Orbit operation handler along with other handlers.
use trackball::{Frame, Image, Orbit, glam::Vec2};
/// Trackball camera mode.
pub struct Trackball {
// Frame wrt camera eye and target.
frame: Frame,
// Image as projection of `Scope` wrt `Frame`.
image: Image,
// Orbit induced by displacement on screen.
orbit: Orbit,
}
impl Trackball {
// Usually, a cursor position event with left mouse button being pressed.
fn handle_left_button_displacement(&mut self, pos: Vec2) {
// Maximum position as screen's width and height.
let max = self.image.max();
// Induced rotation in camera space.
let rot = self.orbit.compute(pos, max).unwrap_or_default();
// Apply induced rotation to local observer frame.
self.frame.local_orbit(rot);
}
// Event when left mouse button is released again.
fn handle_left_button_release(&mut self) {
// Can also or instead be invoked on `Self::handle_left_button_press()`.
self.orbit.discard();
}
}G. Stantchev, “Virtual Trackball Modeling and the Exponential Map”, S2CID 44199608 (2004) , Archived PDF ↩
Re-exports§
pub use glam;
Structs§
- Archived
Bound - An archived
Bound - Archived
Frame - An archived
Frame - Archived
Image - An archived
Image - Archived
Plane - An archived
Plane - Archived
Rigid - An archived
Rigid - Archived
Scope - An archived
Scope - Bound
- Orthogonal boundary conditions implementing
Clamp. - Bound
Resolver - The resolver for an archived
Bound - First
- First person view induced by displacement on screen.
- Frame
- Frame wrt camera eye and target.
- Frame
Resolver - The resolver for an archived
Frame - Image
- Image as projection of
ScopewrtFrame. - Image
Resolver - The resolver for an archived
Image - Orbit
- Orbit induced by displacement on screen.
- Plane
- Plane encoding position with signed bias along unit normal.
- Plane
Resolver - The resolver for an archived
Plane - Rigid
- Rigid transformation as rotation followed by translation, i.e., a direct isometry.
- Rigid
Resolver - The resolver for an archived
Rigid - Scale
- Scale induced by relative input.
- Scope
- Scope defining enclosing viewing frustum.
- Scope
Resolver - The resolver for an archived
Scope - Slide
- Slide induced by displacement on screen.
- Touch
- Touch gestures inducing slide, orbit, scale, and focus.
Enums§
- Archived
Delta - An archived
Delta - Archived
Fixed - An archived
Fixed - Delta
- Delta transform from initial to final
Frame. - Delta
Resolver - The resolver for an archived
Delta - Fixed
- Fixed quantity wrt field of view.
- Fixed
Resolver - The resolver for an archived
Fixed