Crates.io | bevy_trackball |
lib.rs | bevy_trackball |
version | 0.8.0 |
source | src |
created_at | 2023-08-19 13:06:10.439332 |
updated_at | 2024-10-27 10:22:07.59911 |
description | Coherent virtual trackball controller/camera plugin for Bevy |
homepage | https://qu1x.dev/bevy_trackball |
repository | https://github.com/qu1x/bevy_trackball |
max_upload_size | |
id | 948650 |
size | 197,786 |
Coherent virtual trackball controller/camera plugin for Bevy
Run interactive examples in your browser using WebAssembly and WebGL.
NOTE: Not all features are enabled by default, see Optional Features.
Supports multiple camera modes:
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 (e.g., dragging the mouse along an eights of the trackball's circumference rolls the camera by 360/8=45 degrees, dragging the mouse from the screen's center to its further edge linearly rotates the camera by 1 radian, where the trackball's diameter 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 (e.g., the rotation accelerates towards the edge).
trackball
crate which follows the recipe given in the paper of Stantchev, G.. “Virtual Trackball
Modeling and the Exponential Map.”. S2CID 44199608. See the exponential_map
example.TrackballWheelUnit
. Scales
eye distance from current cursor position or centroid of finger positions projected onto
focus plane.TrackballVelocity
for sliding/orbiting or free look by
time-based input (e.g., pressed key). By default, the linear velocity is deduced from the
angular velocity (where target and eye positions define the world radius) which in turn is
defined in units of vertical field of view per seconds and hence independent of the world
unit scale.gliding_clamp
example.constellation_clamp
example.bevy_egui
feature gate) to
steal the viewport and hence capture the input instead, see the egui
example.scaling_modes
example.f64
-ready for large worlds (e.g., solar system scale) whenever Bevy is, see issue #1680.Following features are disabled unless their corresponding feature gate is enabled:
bevy_egui
for automatic viewport stealing whenever egui
wants focus. On Linux you have
to enable either the bevy/wayland
or the bevy/x11
feature gate as well.serialize
for serde
support of various structures of this crate and its dependencies.c11-orbit
for testing the behaviorally identical C implementation of the exponential map.See the release history and roadmap to keep track of the development.
Following mappings are the defaults which can be customized, see TrackballInput
.
Mouse (Buttons) | Touch (Fingers) | Keyboard | Operation |
---|---|---|---|
Left Press + Drag | One + Drag | ijkl |
Orbits around target. |
↳ at trackball's border | Two + Roll | uo |
Rolls about view direction. |
Middle Press + Drag | Any + Drag + Left Shift | ↑←↓→ |
First-person mode. |
Right Press + Drag | Two + Drag | esdf |
Slides trackball on focus plane. |
gv |
Slides trackball in/out. | ||
Scroll In/Out | Two + Pinch Out/In | hn |
Scales distance zooming in/out. |
Left Press + Release | Any + Release | Slides to cursor/finger position. | |
m |
Toggle esdf /wasd mapping. |
||
p |
Toggle orthographic/perspective. | ||
Enter |
Reset camera transform. |
Alternatively, TrackballInput::map_wasd
maps wasd
/Space
/ControlLeft
to slide
operations where ws
slides in/out and Space
/ControlLeft
slides up/down (jump/crouch).
Add the TrackballPlugin
followed by spawning a TrackballController
together with a
TrackballCamera
and a Camera3dBundle
or try the interactive examples.
use bevy::prelude::*;
use bevy_trackball::prelude::*;
// Add the trackball plugin.
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(TrackballPlugin)
.add_systems(Startup, setup)
.run();
}
// Add a trackball controller and trackball camera to a camera 3D bundle.
fn setup(mut commands: Commands) {
let [target, eye, up] = [Vec3::ZERO, Vec3::Z * 10.0, Vec3::Y];
commands.spawn((
TrackballController::default(),
TrackballCamera::look_at(target, eye, up),
Camera3dBundle::default(),
));
// Set up your scene...
}
Copyright © 2023-2024 Rouven Spreckels rs@qu1x.dev
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.