trackball

Virtual Trackball Orbiting via the Exponential Map

Build Status Downloads Recent Downloads Rust Version Documentation License

This is an alternative trackball technique using exponential map and parallel transport to preserve distances and angles for inducing coherent and intuitive trackball rotations. For instance, displacements on straight radial lines through the screen's center are carried to arcs of the same length on great circles of the trackball. This is in contrast to state-of-the-art techniques using orthogonal projection which distorts radial distances further away from the screen's center. This implementation strictly follows the recipe given in the paper of Stantchev, G.. “Virtual Trackball Modeling and the Exponential Map.” . S2CID.

Features

See the release history to keep track of the development.

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.

```rust use nalgebra::{Point2, UnitQuaternion, Vector3}; use std::f32::consts::PI; use trackball::{Frame, Image, Orbit};

/// Trackball camera mode. pub struct Trackball { // Frame wrt camera eye and target. frame: Frame, // Image as projection of Scene 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 handleleftbuttondisplacement(&mut self, pos: &Point2) { // 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).unwrapordefault(); // Apply induced rotation to local observer frame. self.frame.localorbit(&rot); } // Event when left mouse button is released again. fn handleleftbutton_release(&mut self) { // Can also or instead be invoked on Self::handle_left_button_press(). self.orbit.discard(); } } ```

C11 Implementation

Identical C11 implementation for [Orbit] operation handler behind cc feature gate:

toml [dependencies] trackball = { version = "0.2", features = ["cc"] }

License

The works are licensed under the [BSD-2-Clause-Patent].

This license is designed to provide:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the works by you shall be licensed as above, without any additional terms or conditions.