feat: add spectator camera flag
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -5,12 +5,14 @@ mod core;
|
|||||||
mod nodes;
|
mod nodes;
|
||||||
mod objects;
|
mod objects;
|
||||||
mod session;
|
mod session;
|
||||||
|
mod spectator_cam;
|
||||||
pub mod tracking_offset;
|
pub mod tracking_offset;
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
mod wayland;
|
mod wayland;
|
||||||
|
|
||||||
use crate::nodes::drawable::sky::SkyPlugin;
|
use crate::nodes::drawable::sky::SkyPlugin;
|
||||||
use crate::nodes::input;
|
use crate::nodes::input;
|
||||||
|
use crate::spectator_cam::SpectatorCameraPlugin;
|
||||||
|
|
||||||
use bevy::MinimalPlugins;
|
use bevy::MinimalPlugins;
|
||||||
use bevy::a11y::AccessibilityPlugin;
|
use bevy::a11y::AccessibilityPlugin;
|
||||||
@@ -89,6 +91,10 @@ struct CliArgs {
|
|||||||
#[clap(short, long, action)]
|
#[clap(short, long, action)]
|
||||||
flatscreen: bool,
|
flatscreen: bool,
|
||||||
|
|
||||||
|
/// Replaces the flatscreen mode with a first person spectator camera
|
||||||
|
#[clap(short, long, action)]
|
||||||
|
spectator: bool,
|
||||||
|
|
||||||
/// Creates a transparent window fot the flatscreen mode
|
/// Creates a transparent window fot the flatscreen mode
|
||||||
#[clap(short, long, action)]
|
#[clap(short, long, action)]
|
||||||
transparent_flatscreen: bool,
|
transparent_flatscreen: bool,
|
||||||
@@ -326,10 +332,11 @@ fn bevy_loop(
|
|||||||
{
|
{
|
||||||
let mut plugin = WinitPlugin::<WakeUp>::default();
|
let mut plugin = WinitPlugin::<WakeUp>::default();
|
||||||
plugin.run_on_any_thread = true;
|
plugin.run_on_any_thread = true;
|
||||||
plugins = plugins
|
plugins = plugins.add(plugin).disable::<ScheduleRunnerPlugin>();
|
||||||
.add(plugin)
|
plugins = match args.spectator {
|
||||||
.disable::<ScheduleRunnerPlugin>()
|
true => plugins.add(SpectatorCameraPlugin),
|
||||||
.add(FlatscreenInputPlugin);
|
false => plugins.add(FlatscreenInputPlugin),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
app.add_plugins(
|
app.add_plugins(
|
||||||
if !args.flatscreen {
|
if !args.flatscreen {
|
||||||
|
|||||||
39
src/spectator_cam.rs
Normal file
39
src/spectator_cam.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use bevy::{
|
||||||
|
app::Plugin,
|
||||||
|
core_pipeline::core_3d::Camera3d,
|
||||||
|
ecs::{
|
||||||
|
component::Component,
|
||||||
|
system::{Commands, Res},
|
||||||
|
},
|
||||||
|
render::camera::{PerspectiveProjection, Projection},
|
||||||
|
transform::components::Transform,
|
||||||
|
};
|
||||||
|
use bevy_mod_openxr::session::OxrSession;
|
||||||
|
use bevy_mod_xr::session::XrSessionCreated;
|
||||||
|
use openxr::ReferenceSpaceType;
|
||||||
|
|
||||||
|
pub struct SpectatorCameraPlugin;
|
||||||
|
|
||||||
|
impl Plugin for SpectatorCameraPlugin {
|
||||||
|
fn build(&self, app: &mut bevy::app::App) {
|
||||||
|
app.add_systems(XrSessionCreated, create);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[require(Camera3d)]
|
||||||
|
struct SpectatorCam;
|
||||||
|
|
||||||
|
fn create(session: Res<OxrSession>, mut cmds: Commands) {
|
||||||
|
cmds.spawn((
|
||||||
|
SpectatorCam,
|
||||||
|
session
|
||||||
|
.create_reference_space(ReferenceSpaceType::VIEW, Transform::IDENTITY)
|
||||||
|
.unwrap()
|
||||||
|
.0,
|
||||||
|
Projection::Perspective(PerspectiveProjection {
|
||||||
|
fov: 100f32.to_radians(),
|
||||||
|
..Default::default()
|
||||||
|
}),
|
||||||
|
));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user