• Stars
    star
    284
  • Rank 145,616 (Top 3 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Bevy camera controllers with buttery, exponential smoothing.

smooth-bevy-cameras

crates.io docs.rs

A collection of exponentially-smoothed camera controllers for the Bevy Engine.

Look Transform

All controllers are based on a [LookTransform] component, which is just an eye point that looks at a target point. By modifying this component, the scene graph Transform will automatically be synchronized.

Any entities with all of Transform, LookTransform, and [Smoother] components will automatically have their Transform smoothed. Smoothing will have no effect on the LookTransform, only the final Transform in the scene graph.

use bevy::prelude::*;
use smooth_bevy_cameras::{LookTransform, LookTransformBundle, LookTransformPlugin, Smoother};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        // Enables the system that synchronizes your `Transform`s and `LookTransform`s.
        .add_plugin(LookTransformPlugin)
        .add_startup_system(setup)
        .add_system(move_camera_system);
}

fn setup(mut commands: Commands) {
    let eye = Vec3::default();
    let target = Vec3::default();

    commands
        .spawn(LookTransformBundle {
            transform: LookTransform::new(eye, target),
            smoother: Smoother::new(0.9), // Value between 0.0 and 1.0, higher is smoother.
        })
        .insert_bundle(Camera3dBundle::default());

}

fn move_camera_system(mut cameras: Query<&mut LookTransform>) {
    // Later, another system will update the `Transform` and apply smoothing automatically.
    for mut c in cameras.iter_mut() { c.target += Vec3::new(1.0, 1.0, 1.0); }
}

Look Angles

When implementing a camera controller, it's often useful to work directly with the angles (pitch and yaw) of your look direction. You can do this with the [LookAngles] type:

use bevy::prelude::*;
use smooth_bevy_cameras::{
    LookAngles,
    LookTransform
};

fn look_angles(mut transform: LookTransform, delta: Vec2) {
    let mut angles = LookAngles::from_vector(transform.look_direction().unwrap());
    angles.add_pitch(delta.y);
    angles.add_yaw(delta.x);
    // Third-person.
    transform.eye = transform.target + 1.0 * transform.radius() * angles.unit_vector();
    // First-person.
    // transform.target = transform.eye + 1.0 * transform.radius() * angles.unit_vector();
}

This is how the built-in controllers implement rotation controls.

Built-In Controllers

These plugins depend on the [LookTransformPlugin]:

  • FpsCameraPlugin + FpsCameraBundle

    • WASD: Translate on the XZ plane
    • Shift/Space: Translate along the Y axis
    • Mouse: Rotate camera
  • OrbitCameraPlugin + OrbitCameraBundle

    • CTRL + mouse drag: Rotate camera
    • Right mouse drag: Pan camera
    • Mouse wheel: Zoom
  • UnrealCameraPlugin + UnrealCameraBundle

    Best use: hold Right mouse button to orbit the view while using WASD to navigate in the scene, using scroll wheel to accelerate/decelerate.

    • Left mouse drag: Locomotion
    • Right mouse drag: Rotate camera
    • Left and Right or Middle mouse drag: Pan camera
    • While holding any mouse button, use A/D for panning left/right, Q/E for panning up/down
    • While holding any mouse button, use W/S for locomotion forward/backward
    • While holding any mouse button, use scroll wheel to increase/decrease locomotion and panning speeds
    • While holding no mouse button, use scroll wheel for locomotion forward/backward

License: MIT

More Repositories

1

building-blocks

A voxel library for real-time applications.
Rust
367
star
2

block-mesh-rs

Generate voxel block meshes in Rust.
Rust
195
star
3

fast-surface-nets-rs

A fast isosurface extraction algorithm.
Rust
100
star
4

feldspar

Procedural voxel worlds for Bevy Engine.
Rust
70
star
5

grid-tree-rs

Pixel quadtrees and voxel octrees
Rust
47
star
6

bevy_triplanar_splatting

Triplanar Mapping and Material Blending for Bevy Engine
WGSL
28
star
7

bevy_metrics_dashboard

bevy + metrics + egui_plot
Rust
21
star
8

building-blocks-editor

Voxel map editor using building-blocks and bevy.
Rust
17
star
9

bevy_rider

Classic Line Rider implemented with the Bevy engine and Rapier 2D.
Rust
17
star
10

ilattice3

Data types, structures, and algorithms for 3D integer lattices (voxels)
Rust
16
star
11

height-mesh-rs

A small crate to generate a 3D mesh from a 2D heightmap.
Rust
16
star
12

ndshape-rs

Linearization of N-dimensional array indices.
Rust
15
star
13

ilattice-rs

Generic math on integer lattices
Rust
9
star
14

ilattice3-mesh

Meshing algorithms for ilattice3.
Rust
9
star
15

grid-ray-rs

Rust implementation of Amantides and Woo algorithm for casting a ray through pixels or voxels.
Rust
8
star
16

rkyv_impl

Attribute macro for implementing methods on both Foo and ArchivedFoo.
Rust
8
star
17

feldspar-editor

A level editor for the Feldspar voxel plugin.
Rust
7
star
18

sled-snapshots

Incremental backups of sled trees.
Rust
7
star
19

octree_dual_contour

Rust
6
star
20

projectris

Shadow Tetris.
Rust
6
star
21

trashbot

Autonomous trash disposal.
C++
6
star
22

mxnet-neural-style

Implementation of Gatys, Ecker, and Bethge's Neural Style algorithm, made with MXNet's Julia interface.
Julia
5
star
23

legion-task

Fork-join multitasking for Legion ECS.
Rust
5
star
24

specs-task

Fork-join multitasking for SPECS ECS
Rust
5
star
25

ndcopy-rs

N-dimensional array memcpy.
Rust
5
star
26

grid-db-rs

Quadtree and octree databases built on sled.
Rust
5
star
27

mmap-cache-rs

A read-only, memory-mapped cache.
Rust
3
star
28

ilattice3-wfc

Wave Function Collapse for ilattice3
Rust
3
star
29

material-converter

Easily harvest free PBR materials from the Internet and convert them into the material format you need.
Rust
2
star
30

megadodge_mayhem

Bevy Jam 4. Command an army of dodgeball players.
Rust
1
star
31

wgpu-isosurface

Rust
1
star
32

kv-par-merge-sort-rs

Sort (key, value) data sets that don't fit in memory
Rust
1
star
33

qef

3D quadric error functions in Rust
Rust
1
star
34

dotfiles

My Unix user configuration.
Shell
1
star
35

nocturne

A cross-platform, MIDI-controlled music synthesizer written in Rust.
Rust
1
star