From 537df16f13d20908a6f888891b77a12762f90d36 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Fri, 15 Dec 2023 15:50:28 +0100 Subject: [PATCH] Record view and dir in get_camera_view --- src/geoview.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/geoview.rs b/src/geoview.rs index 2e94515..42d5d30 100644 --- a/src/geoview.rs +++ b/src/geoview.rs @@ -1,6 +1,9 @@ use super::geopos::*; use crate::player::Player; -use bevy::prelude::*; +use bevy::{ + prelude::*, + utils::tracing::{self, instrument}, +}; use big_space::FloatingOriginSettings; use std::{collections::HashMap, f32::consts::FRAC_PI_2}; @@ -116,19 +119,25 @@ impl GeoView { player.set_pos(starting_position); } + #[instrument(level = "debug", skip(space, player), ret)] pub fn get_camera_view(space: &FloatingOriginSettings, player: &Player) -> Self { let position = player.pos(); let geo_pos = position.to_planetary_position().to_geopos(); - info!(?geo_pos); // wrong!: lat: 31.906904, lon: 93.580765 let height = position.position_double(space).length() as f32 - crate::geopos::EARTH_RADIUS; - info!(?height); + let forward = position.pos.transform.forward(); + let directions = position.directions(); + let view = forward.angle_between(-directions.up).to_degrees(); + let dir = forward + .cross(directions.up) + .cross(position.pos.transform.right()) + .angle_between(directions.north); Self { geo_pos, height, - dir: 0., - view: 0., + dir, + view, radius: 6., fov: 7., }