Skip to content

Commit

Permalink
Add alternative touch controls (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Plonq authored Feb 18, 2024
1 parent c807119 commit aabd39b
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 4,842 deletions.
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Use it to quickly prototype, experiment, for model viewers, and more!
- Works with orthographic camera projection in addition to perspective
- Customisable controls, sensitivity, and more
- Touch support
- Currently 'beta' - please report any issues!
- Works with multiple viewports and/or windows
- Easy to control manually, e.g. for keyboard control or animation
- Can control cameras that render to a texture
Expand All @@ -34,15 +33,12 @@ Default mouse controls:
- Right Mouse - Pan
- Scroll Wheel - Zoom

Touch controls:
Default touch controls:

- One finger - Orbit
- Two fingers - Pan
- Pinch - Zoom

Note: touch controls are currently not customisable. Please create an issue if you would like to customise the touch
controls.

## Quick Start

Add the plugin:
Expand Down Expand Up @@ -85,7 +81,7 @@ Note that if you change the up vector either by changing `PanOrbitCamera.base_tr

## Cargo Features

- `bevy_egui` (optional): makes `PanOrbitCamera` ignore any input that `egui` uses, thus preventing moving the camera
- `bevy_egui` (optional): Makes `PanOrbitCamera` ignore any input that `egui` uses, thus preventing moving the camera
when interacting with egui windows

## Version Compatibility
Expand Down
4 changes: 3 additions & 1 deletion examples/advanced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! Zoom: Mousewheel
use bevy::prelude::*;
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin, TouchControls};
use std::f32::consts::TAU;

fn main() {
Expand Down Expand Up @@ -78,6 +78,8 @@ fn setup(
modifier_pan: Some(KeyCode::ShiftLeft),
// Reverse the zoom direction
reversed_zoom: true,
// Use alternate touch controls
touch_controls: TouchControls::TwoFingerOrbit,
..default()
},
));
Expand Down
15 changes: 11 additions & 4 deletions examples/egui.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
//! Demonstrates the bevy_egui feature which allows bevy_panorbit_camera to ignore input events in
//! egui windows
use bevy::ecs::event::EventUpdateSignal;
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_plugins(PanOrbitCameraPlugin)
.add_systems(Startup, setup)
.add_systems(Update, ui_example_system)
.run();
.add_systems(Update, ui_example_system);

// Make Bevy drop unconsumed events every frame to prevent weird behaviour when moving mouse
// out of an egui window right after scrolling (zooming)
// See: https://bevyengine.org/news/bevy-0-13/#events-live-longer
app.world.remove_resource::<EventUpdateSignal>();

app.run();
}

fn setup(
Expand Down
15 changes: 11 additions & 4 deletions examples/egui_multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
//! This is a combination of the egui and multiple_windows examples, and doesn't show anything new,
//! it's primarily here for easy e2e testing.
use bevy::ecs::event::EventUpdateSignal;
use bevy::prelude::*;
use bevy::render::camera::RenderTarget;
use bevy::window::WindowRef;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
let mut app = App::new();
app.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.add_plugins(PanOrbitCameraPlugin)
.add_systems(Startup, setup)
.add_systems(Update, ui_example_system)
.run();
.add_systems(Update, ui_example_system);

// Make Bevy drop unconsumed events every frame to prevent weird behaviour when moving mouse
// out of an egui window right after scrolling (zooming)
// See: https://bevyengine.org/news/bevy-0-13/#events-live-longer
app.world.remove_resource::<EventUpdateSignal>();

app.run();
}

fn setup(
Expand Down
5 changes: 0 additions & 5 deletions examples/touch/.cargo/config.toml

This file was deleted.

2 changes: 0 additions & 2 deletions examples/touch/.gitignore

This file was deleted.

Loading

0 comments on commit aabd39b

Please sign in to comment.