Skip to content

Commit

Permalink
Renamed argument variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
-karlos- committed Dec 21, 2023
1 parent cbd4e2b commit 402fbe8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 61 deletions.
10 changes: 5 additions & 5 deletions src/flycam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ fn setup(
args: Res<crate::Args>,
space: Res<FloatingOriginSettings>,
) {
let pos = args.starting_position.normalize().as_vec3();
let height_direction = args.starting_position.normalize().as_vec3();
let (grid, subgrid): (GalacticGrid, _) = space.translation_to_grid(args.starting_position);
let mut transform =
Transform::from_translation(subgrid + pos * args.height).looking_at(subgrid, Vec3::Z); // ::Z for Nord
let mut transform = Transform::from_translation(subgrid + height_direction * args.elevation)
.looking_at(subgrid, Vec3::Z); // ::Z for Nord

let rotation = Quat::from_axis_angle(Vec3::Z, args.direction.to_radians()) // Todo: why ::Z??
* Quat::from_axis_angle(Vec3::X, args.view.to_radians());
* Quat::from_axis_angle(Vec3::X, args.up_view.to_radians());
transform = transform * Transform::from_rotation(rotation);

movement_settings.up = pos;
movement_settings.up = height_direction;

let material = materials.add(StandardMaterial {
base_color_texture: Some(images.add(uv_debug_texture())),
Expand Down
80 changes: 40 additions & 40 deletions src/geoview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Views {
* Geo position on Earth and rotation at/abowe a GPU scene
*
* An instance of self [[GeoView]] serves
* to define a geo Position and a camera position and view angles,
* to define a geo Position and a camera position and view-angles,
*
* A crate user, by the lib API
* may create an instance to define a (or find an existing) GPU scene
Expand All @@ -28,16 +28,16 @@ pub struct Views {
#[derive(Default, Debug, Clone, Copy)]
pub struct GeoView {
geo_coord: GeoCoord, // lat/lon
height: f32,
dir: f32,
view: f32,
radius: f32, // todo: use fov and radius(by ArcControl)
fov: f32,
elevation: f32,
direction: f32,
up_view: f32,
distance: f32, // todo: use distance and camera_fov (by ArcControl)
camera_fov: f32,
}

impl GeoView {
/**
* Store self geo view in a browser cookie
* Store self GeoView in a browser cookie
* To restore it into your viewer, use [[GeoView]].[[restore]]
* internal, util [[restore]] is called.
* @param id "name" of the cookie
Expand All @@ -49,11 +49,11 @@ impl GeoView {
"{} {} {} {} {} {} {}",
self.geo_coord.lat,
self.geo_coord.lon,
self.height,
self.dir, // alpha, compas
self.view, // beta, headupdown
self.radius,
self.fov,
self.elevation,
self.direction, // alpha, compas
self.up_view, // beta, headupdown
self.distance,
self.camera_fov,
);
println!(">>> id: {} cookie: {}", id, cookie);

Expand All @@ -64,7 +64,7 @@ impl GeoView {
/**
* restore this geo pos from browser cookie
* @param id "name" of the cookie to restore it
* @return restored geo view
* @return restored GeoView
*/
pub fn restore(id: String, views: &mut HashMap<String, String>) -> Option<GeoView> {
let cookie = views.get(&id); //.unwrap();//_or(&or);
Expand All @@ -81,11 +81,11 @@ impl GeoView {

Some(GeoView {
geo_coord,
height: (floats[2]).parse().unwrap(),
dir: (floats[3]).parse().unwrap(),
view: (floats[4]).parse().unwrap(),
radius: (floats[5]).parse().unwrap(),
fov: (floats[6]).parse().unwrap(),
elevation: (floats[2]).parse().unwrap(),
direction: (floats[3]).parse().unwrap(),
up_view: (floats[4]).parse().unwrap(),
distance: (floats[5]).parse().unwrap(),
camera_fov: (floats[6]).parse().unwrap(),
})
} else {
None
Expand All @@ -101,7 +101,7 @@ impl GeoView {
let mut starting_position = self.geo_coord.to_cartesian().to_galactic_position(space);
let directions = starting_position.directions();

starting_position.transform.translation += directions.up * self.height;
starting_position.transform.translation += directions.up * self.elevation;
// Look northwards
starting_position
.transform
Expand All @@ -110,13 +110,13 @@ impl GeoView {
// Rotate to west or east
starting_position
.transform
.rotate_axis(directions.up, self.dir.to_radians());
// Pan up or down. We subtract 90°, because the view is an angle from looking
.rotate_axis(directions.up, self.direction.to_radians());
// Pan up or down. We subtract 90°, because the up-view is an angle from looking
// straight down. We don't default to looking down, as that doesn't guarantee us
// that the forward direction is north.
starting_position
.transform
.rotate_local_x(self.view.to_radians() - FRAC_PI_2);
.rotate_local_x(self.up_view.to_radians() - FRAC_PI_2);
player.set_pos(starting_position);
}

Expand All @@ -126,9 +126,9 @@ impl GeoView {

let geo_coord = position.to_planetary_position().to_geocoord();
//info!(?geo_coord);
let height =
let elevation =
position.position_double(space).length() as f32 - crate::geocoord::EARTH_RADIUS;
//info!(?height);
//info!(?elevation);

/*
let mut transform = player.pos().transform;
Expand All @@ -137,26 +137,26 @@ impl GeoView {
transform.rotate_local_x(geo_coord.lat.to_radians() + FRAC_PI_2);
// Un-Rotate to west or east
transform.rotate_local_z(geo_coord.lon.to_radians());
let view = transform.rotation.x.to_degrees(); // lat
let dir = transform.rotation.z.to_degrees(); // llon
let up_view = transform.rotation.x.to_degrees(); // lat
let direction = transform.rotation.z.to_degrees(); // llon
*/

let forward = position.pos.transform.forward();
let directions = position.directions();
let view = forward.angle_between(-directions.up).to_degrees();
let dir = forward
let up_view = forward.angle_between(-directions.up).to_degrees();
let direction = forward
.cross(directions.up)
.cross(position.pos.transform.right())
.angle_between(directions.north)
.to_degrees();

Self {
geo_coord,
height,
dir,
view,
radius: 6.,
fov: 7.,
elevation,
direction,
up_view,
distance: 6.,
camera_fov: 7.,
}
}
}
Expand All @@ -183,11 +183,11 @@ fn keys_ui(
};
let start_view = GeoView {
geo_coord,
height: args.height,
dir: args.direction,
view: args.view,
radius: 6.,
fov: 7.,
elevation: args.elevation,
direction: args.direction,
up_view: args.up_view,
distance: 6.,
camera_fov: 7.,
};
start_view.store("start".to_string(), &mut views.map);
start_view.set_camera_view(&space, &mut player);
Expand All @@ -207,8 +207,8 @@ fn keys_ui(
let key = format!("{:?}", key);
if keys.pressed(KeyCode::ShiftRight) {
info!("*** KEY: {:?}", key);
let view = GeoView::get_camera_view(&space, &player);
view.store(key.to_string(), &mut views.map);
let geo_view = GeoView::get_camera_view(&space, &player);
geo_view.store(key.to_string(), &mut views.map);
} else {
info!("*** key: {:?}", key);
let view3 = GeoView::restore(key.to_string(), &mut views.map);
Expand Down
30 changes: 15 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type GalacticTransformItem<'a> = GridTransformItem<'a, GridPrecision>;
#[derive(Resource)]
struct Args {
starting_position: PlanetaryPosition,
height: f32,
elevation: f32,
direction: f32,
view: f32,
up_view: f32,
xr: bool,
}

Expand All @@ -76,14 +76,14 @@ pub fn main() {
}

let mut pos = GeoCoord {
lat: 48.1408, // Germany, Munic, Main railway station
lon: 11.5577,
lat: 0., //48.1408, // Germany, Munic, Main railway station
lon: 0., //11.5577,
};
let mut height: f32 = 300.0; // Camare hight about ground
let mut elevation: f32 = 5000000.; //300.0; // Camare hight about ground

// View to city center, Marienplatz
let mut direction: f32 = (-105.0_f32); // Compass view direction to Oeast-Southeast. 0 = Nord, -90 = East Todo: Why minus?
let mut view: f32 = (75.0_f32); // View slightly down. 0 = starit down, 90 = horizontal TODO: check!: 0=down or ahead
// GeoView to city center, Marienplatz
let mut direction: f32 = 0.; //(-105.0_f32); // Compass view-direction to Oeast-Southeast. 0 = Nord, -90 = East Todo: Why minus?
let mut up_view: f32 = 0.; //(75.0_f32); // Up-view slightly down. -90 = down, 0 = horizontal 90 = Up

let mut xr = false;

Expand All @@ -94,8 +94,8 @@ pub fn main() {
match k {
"lat" => pos.lat = v.parse().unwrap(),
"lon" => pos.lon = v.parse().unwrap(),
"ele" => height = v.parse().unwrap(),
"view" => view = v.parse().unwrap(),
"ele" => elevation = v.parse().unwrap(),
"view" => up_view = v.parse().unwrap(),
"dir" => direction = v.parse().unwrap(),
"xr" => xr = v.parse().unwrap(),
other => panic!("unknown key `{other}`"),
Expand All @@ -105,9 +105,9 @@ pub fn main() {
let mut app = App::new();
app.insert_resource(Args {
starting_position: pos.to_cartesian(),
height,
elevation,
direction,
view,
up_view,
xr,
});
app.insert_resource(ViewDistance(2000.0));
Expand Down Expand Up @@ -143,12 +143,12 @@ pub fn main() {
Update,
(
(
// After recomputing the view distance from the FPS
// After recomputing the view-distance from the FPS
recompute_view_distance,
(
// Hide tiles that are now beyond the view distance
// Hide tiles that are now beyond the view-distance
get_main_camera_position.pipe(TileMap::hide_faraway_tiles),
// And load tiles that are now within the view distance
// And load tiles that are now within the view-distance
get_main_camera_position
.pipe(TileMap::load_next)
.pipe(TileMap::load),
Expand Down
2 changes: 1 addition & 1 deletion src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TileMap {
) {
let elevation = fly_cam.single().position_double(&space).length() as f32 - EARTH_RADIUS;
for (tile, mut vis) in tiles.iter_mut() {
// FIXME: use tile zoom level to increase view distance for lower zoom tiles.
// FIXME: use tile zoom level to increase view-distance for lower zoom tiles.
let tile_size = tile.as_coord().to_geo_coord().tile_size(TILE_ZOOM);
let distance = (tile.distance_squared(origin) as f32).sqrt() * tile_size;
//info!("o_e_r {:?} {:?} {:?}", distance, elevation, radius);
Expand Down

0 comments on commit 402fbe8

Please sign in to comment.