Skip to content

Commit 3a1879a

Browse files
committed
feat: all camera modes
1 parent 6035f12 commit 3a1879a

File tree

5 files changed

+237
-86
lines changed

5 files changed

+237
-86
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bevy = { workspace = true, default-features = false, features = [
3131
"bevy_state",
3232
"bevy_core_pipeline",
3333
] }
34-
bevy_pancam = { git = "https://github.com/tomara-x/bevy_pancam", features = [
34+
bevy_pancam = { git = "https://github.com/johanhelsing/bevy_pancam", features = [
3535
"bevy_egui",
3636
] }
3737
#bevy_pancam = "0.12.0"

examples/simple/src/main.rs

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::ops::Deref;
2-
3-
use bevy::{color::palettes::css, prelude::*, transform::commands};
1+
use bevy::{color::palettes::css, prelude::*};
42
use bevy_egui::{egui, EguiContexts, EguiPlugin};
53
use bevy_ogle::{prelude::*, OglePlugin};
64
use rand::random;
@@ -12,11 +10,8 @@ fn main() {
1210
App::new()
1311
.add_plugins(DefaultPlugins)
1412
.add_plugins(EguiPlugin)
15-
.add_plugins(OglePlugin)
13+
.add_plugins(OglePlugin::default())
1614
.add_systems(Startup, setup_scene)
17-
.add_systems(Startup, |mut commands: Commands| {
18-
commands.spawn(Camera2dBundle::default());
19-
})
2015
.add_systems(Update, move_target)
2116
.add_systems(Update, control_camera_ui)
2217
.run();
@@ -81,9 +76,6 @@ fn control_camera_ui(
8176
|| ui
8277
.radio_value(&mut set_mode, OgleMode::Following, "Following")
8378
.clicked()
84-
|| ui
85-
.radio_value(&mut set_mode, OgleMode::Choreographed, "Choreographed")
86-
.clicked()
8779
|| ui
8880
.radio_value(&mut set_mode, OgleMode::Pancam, "Pancam")
8981
.clicked()
@@ -92,7 +84,7 @@ fn control_camera_ui(
9284
}
9385

9486
ui.separator();
95-
ui.heading("Mode");
87+
ui.heading("Camera Target");
9688
let target_entity = query_thing.single();
9789
if ui.radio(*target == OgleTarget::None, "None").clicked() {
9890
commands.ogle_clear_target();
@@ -103,5 +95,25 @@ fn control_camera_ui(
10395
{
10496
commands.ogle_target_entity(target_entity);
10597
}
98+
ui.horizontal(|ui| {
99+
let mut pos = match *target {
100+
OgleTarget::Position(p) => p,
101+
_ => Vec2::new(0.0, 0.0),
102+
};
103+
if ui
104+
.radio(matches!(*target, OgleTarget::Position(_)), "Position")
105+
.clicked()
106+
{
107+
commands.ogle_target_position(pos);
108+
}
109+
ui.label("X");
110+
if ui.add(egui::DragValue::new(&mut pos.x)).changed() {
111+
commands.ogle_target_position(pos);
112+
}
113+
ui.label("Y");
114+
if ui.add(egui::DragValue::new(&mut pos.y)).changed() {
115+
commands.ogle_target_position(pos);
116+
}
117+
});
106118
});
107119
}

src/lib.rs

+68-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bevy::prelude::*;
2-
3-
mod rig;
2+
use dolly::prelude::*;
43

54
mod commands;
65
pub use commands::OgleCommandExt;
@@ -28,14 +27,76 @@ pub enum OgleMode {
2827
Frozen,
2928
/// The camera should exponentially follow its target.
3029
Following,
31-
/// The camera is being choreographed and should mirror its target position exactly.
32-
///
33-
/// This is useful when the camera follows a spline, or you don't want loose following behavior.
34-
Choreographed,
3530
/// The camera is in a detached pancam mode.
3631
Pancam,
3732
}
3833

34+
#[derive(Resource, Deref, DerefMut)]
35+
pub struct OgleRig(CameraRig);
36+
37+
impl Default for OgleRig {
38+
fn default() -> Self {
39+
let pos = mint::Point3 {
40+
x: 0.0,
41+
y: 0.0,
42+
z: 1.0,
43+
};
44+
Self(
45+
CameraRig::builder()
46+
.with(Position::new(pos))
47+
.with(Arm::new(pos))
48+
.with(Smooth::new_position(1.5).predictive(false))
49+
.build(),
50+
)
51+
}
52+
}
53+
54+
#[derive(Resource, Debug, Clone, Copy, PartialEq)]
55+
pub struct OgleSettings {
56+
/// The minimum scale for the camera
57+
///
58+
/// The orthographic projection's scale will be clamped at this value when zooming in
59+
pub min_scale: f32,
60+
/// The maximum scale for the camera
61+
///
62+
/// If present, the orthographic projection's scale will be clamped at
63+
/// this value when zooming out.
64+
pub max_scale: Option<f32>,
65+
/// The minimum x position of the camera window
66+
///
67+
/// If present, the orthographic projection will be clamped to this boundary both
68+
/// when dragging the window, and zooming out.
69+
pub min_x: Option<f32>,
70+
/// The maximum x position of the camera window
71+
///
72+
/// If present, the orthographic projection will be clamped to this boundary both
73+
/// when dragging the window, and zooming out.
74+
pub max_x: Option<f32>,
75+
/// The minimum y position of the camera window
76+
///
77+
/// If present, the orthographic projection will be clamped to this boundary both
78+
/// when dragging the window, and zooming out.
79+
pub min_y: Option<f32>,
80+
/// The maximum y position of the camera window
81+
///
82+
/// If present, the orthographic projection will be clamped to this boundary both
83+
/// when dragging the window, and zooming out.
84+
pub max_y: Option<f32>,
85+
}
86+
87+
impl Default for OgleSettings {
88+
fn default() -> Self {
89+
Self {
90+
min_scale: -(1.0 - 0.00001),
91+
max_scale: None,
92+
min_x: None,
93+
max_x: None,
94+
min_y: None,
95+
max_y: None,
96+
}
97+
}
98+
}
99+
39100
pub mod prelude {
40-
pub use super::{OgleCommandExt, OgleMode, OgleTarget};
101+
pub use super::{OgleCommandExt, OgleMode, OgleRig, OgleSettings, OgleTarget};
41102
}

0 commit comments

Comments
 (0)