diff --git a/Cargo.lock b/Cargo.lock index 8662205..460179f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,16 +73,10 @@ dependencies = [ "accesskit", "accesskit_macos", "accesskit_windows", - "raw-window-handle 0.6.2", + "raw-window-handle", "winit", ] -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "adler2" version = "2.0.0" @@ -193,55 +187,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.6.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - -[[package]] -name = "anstyle-parse" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" -dependencies = [ - "anstyle", - "windows-sys 0.52.0", -] - [[package]] name = "approx" version = "0.5.1" @@ -1377,7 +1322,7 @@ dependencies = [ "bevy_math", "bevy_reflect", "bevy_utils", - "raw-window-handle 0.6.2", + "raw-window-handle", "smol_str", ] @@ -1407,7 +1352,7 @@ dependencies = [ "bytemuck", "cfg-if", "crossbeam-channel", - "raw-window-handle 0.6.2", + "raw-window-handle", "wasm-bindgen", "web-sys", "wgpu-types 23.0.0", @@ -1552,9 +1497,9 @@ dependencies = [ [[package]] name = "bytemuck_derive" -version = "1.7.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" +checksum = "3fa76293b4f7bb636ab88fd78228235b5248b4d05cc589aed610f954af5d7c7a" dependencies = [ "proc-macro2", "quote", @@ -1679,12 +1624,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "colorchoice" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0" - [[package]] name = "com" version = "0.6.0" @@ -1944,9 +1883,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -2174,19 +2113,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "humantime", - "log", -] - [[package]] name = "epaint" version = "0.29.1" @@ -2285,9 +2211,9 @@ checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fdeflate" -version = "0.3.4" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f9bfee30e4dedf0ab8b422f03af778d9612b63f502710fc500a334ebe2de645" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" dependencies = [ "simd-adler32", ] @@ -2306,12 +2232,12 @@ checksum = "1d674e81391d1e1ab681a28d99df07927c6d4aa5b027d7da16ba32d1d21ecd99" [[package]] name = "flate2" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" dependencies = [ "crc32fast", - "miniz_oxide 0.8.0", + "miniz_oxide", ] [[package]] @@ -2392,25 +2318,17 @@ dependencies = [ "android_logger", "bevy", "bevy-inspector-egui", - "bytemuck", - "cfg-if", "console_error_panic_hook", "console_log", - "env_logger", "getrandom", - "image", - "lazy_static", "log", - "nalgebra", "noise", - "pollster", "rand", "voronoice", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", "wgpu 22.1.0", - "winit", ] [[package]] @@ -2519,7 +2437,7 @@ dependencies = [ "vec_map", "wasm-bindgen", "web-sys", - "windows 0.58.0", + "windows 0.52.0", ] [[package]] @@ -2765,12 +2683,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "humantime" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" - [[package]] name = "icu_collections" version = "1.5.0" @@ -2912,15 +2824,14 @@ dependencies = [ [[package]] name = "image" -version = "0.25.2" +version = "0.25.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10" +checksum = "cd6f44aed642f18953a158afeb30206f4d50da59fbc66ecb53c66488de73563b" dependencies = [ "bytemuck", "byteorder-lite", "num-traits", "png", - "rayon", "tiff", ] @@ -2979,12 +2890,6 @@ dependencies = [ "mach2", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - [[package]] name = "itertools" version = "0.13.0" @@ -3194,16 +3099,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "matrixmultiply" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a" -dependencies = [ - "autocfg", - "rawpointer", -] - [[package]] name = "memchr" version = "2.7.4" @@ -3242,21 +3137,12 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.7.4" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" -dependencies = [ - "adler", - "simd-adler32", -] - -[[package]] -name = "miniz_oxide" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" dependencies = [ "adler2", + "simd-adler32", ] [[package]] @@ -3322,33 +3208,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "nalgebra" -version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c4b5f057b303842cf3262c27e465f4c303572e7f6b0648f60e16248ac3397f4" -dependencies = [ - "approx", - "matrixmultiply", - "nalgebra-macros", - "num-complex", - "num-rational", - "num-traits", - "simba", - "typenum", -] - -[[package]] -name = "nalgebra-macros" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.90", -] - [[package]] name = "ndk" version = "0.8.0" @@ -3374,8 +3233,7 @@ dependencies = [ "log", "ndk-sys 0.6.0+11769913", "num_enum", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", + "raw-window-handle", "thiserror", ] @@ -3467,25 +3325,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-complex" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" -dependencies = [ - "num-traits", -] - [[package]] name = "num-derive" version = "0.4.2" @@ -3497,26 +3336,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -3930,15 +3749,15 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "png" -version = "0.17.13" +version = "0.17.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06e4b0d3d1312775e782c86c91a111aa1f910cbb65e1337f9975b5f9a554b5e1" +checksum = "82151a2fc869e011c153adc57cf2789ccb8d9906ce52c0b39a6b5697749d7526" dependencies = [ "bitflags 1.3.2", "crc32fast", "fdeflate", "flate2", - "miniz_oxide 0.7.4", + "miniz_oxide", ] [[package]] @@ -3956,12 +3775,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "pollster" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22686f4785f02a4fcc856d3b3bb19bf6c8160d103f7a99cc258bddd0251dc7f2" - [[package]] name = "pp-rs" version = "0.2.1" @@ -4105,24 +3918,12 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f60fcc7d6849342eff22c4350c8b9a989ee8ceabc4b481253e8946b9fe83d684" -[[package]] -name = "raw-window-handle" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" - [[package]] name = "raw-window-handle" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" -[[package]] -name = "rawpointer" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" - [[package]] name = "rayon" version = "1.10.0" @@ -4313,15 +4114,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" -[[package]] -name = "safe_arch" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3460605018fdc9612bce72735cba0d27efbcd9904780d44c7e3a9948f96148a" -dependencies = [ - "bytemuck", -] - [[package]] name = "same-file" version = "1.0.6" @@ -4415,19 +4207,6 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" -[[package]] -name = "simba" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a386a501cd104797982c15ae17aafe8b9261315b5d07e3ec803f2ea26be0fa" -dependencies = [ - "approx", - "num-complex", - "num-traits", - "paste", - "wide", -] - [[package]] name = "simd-adler32" version = "0.3.7" @@ -4878,12 +4657,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e13db2e0ccd5e14a544e8a246ba2312cd25223f616442d7f2cb0e3db614236e" -[[package]] -name = "typenum" -version = "1.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" - [[package]] name = "unicode-bidi" version = "0.3.18" @@ -4967,12 +4740,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "uuid" version = "1.11.0" @@ -5260,7 +5027,7 @@ dependencies = [ "naga 22.1.0", "parking_lot", "profiling", - "raw-window-handle 0.6.2", + "raw-window-handle", "smallvec", "static_assertions", "wasm-bindgen", @@ -5285,7 +5052,7 @@ dependencies = [ "naga 23.1.0", "parking_lot", "profiling", - "raw-window-handle 0.6.2", + "raw-window-handle", "smallvec", "static_assertions", "wasm-bindgen", @@ -5313,7 +5080,7 @@ dependencies = [ "once_cell", "parking_lot", "profiling", - "raw-window-handle 0.6.2", + "raw-window-handle", "rustc-hash", "smallvec", "thiserror", @@ -5338,7 +5105,7 @@ dependencies = [ "once_cell", "parking_lot", "profiling", - "raw-window-handle 0.6.2", + "raw-window-handle", "rustc-hash", "smallvec", "thiserror", @@ -5380,7 +5147,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.6.2", + "raw-window-handle", "renderdoc-sys", "rustc-hash", "smallvec", @@ -5424,7 +5191,7 @@ dependencies = [ "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.6.2", + "raw-window-handle", "renderdoc-sys", "rustc-hash", "smallvec", @@ -5458,16 +5225,6 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wide" -version = "0.7.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b828f995bf1e9622031f8009f8481a85406ce1f4d4588ff746d872043e855690" -dependencies = [ - "bytemuck", - "safe_arch", -] - [[package]] name = "widestring" version = "1.1.0" @@ -5905,8 +5662,7 @@ dependencies = [ "orbclient", "percent-encoding", "pin-project", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", + "raw-window-handle", "redox_syscall 0.4.1", "rustix", "sctk-adwaita", diff --git a/Cargo.toml b/Cargo.toml index 677ff9d..5fa05b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,36 +4,73 @@ version = "0.1.0" edition = "2021" [lib] -crate-type=["cdylib"] +name = "forestiles" +path = "src/lib.rs" +crate-type=[ + "staticlib", + "cdylib", + "rlib" +] [[bin]] path = "src/lib.rs" name = "forestiles" -[package.metadata.android] -package = "com.forestiles.arkitu" -build_targets = ["armv7-linux-androideabi", "aarch64-linux-android", "i686-linux-android", "x86_64-linux-android"] - [dependencies] # bevy = { version = "0.15", default-features = false, features = [ # "bevy_color","bevy_core_pipeline","bevy_render","bevy_winit","bevy_window","multi_threaded","wayland","bevy_sprite", # "bevy_picking","bevy_mesh_picking_backend","bevy_ui_picking_backend","bevy_sprite_picking_backend" # ]} -bevy = { version = "0.15" } +bevy = { version = "0.15", default-features = false, features = [ + "android-native-activity", + "android_shared_stdcxx", + "animation", + "bevy_asset", + "bevy_audio", + "bevy_color", + "bevy_core_pipeline", + "bevy_gilrs", + "bevy_gizmos", + "bevy_gltf", + "bevy_mesh_picking_backend", + "bevy_pbr", + "bevy_picking", + "bevy_render", + "bevy_scene", + "bevy_sprite", + "bevy_sprite_picking_backend", + "bevy_state", + "bevy_text", + "bevy_ui", + "bevy_ui_picking_backend", + "bevy_window", + "bevy_winit", + "custom_cursor", + "default_font", + "hdr", + "multi_threaded", + "png", + "smaa_luts", + "sysinfo_plugin", + "tonemapping_luts", + "vorbis", + "webgl2", + "wayland", +]} bevy-inspector-egui = { version = "0.28" } -winit = { version = "0.30", features = ["rwh_05", "android-native-activity"] } -env_logger = "0.11" +# winit = { version = "0.30", features = ["rwh_05", "android-native-activity"] } +# env_logger = "0.11" log = "0.4" -wgpu = "22.1" -cfg-if = "1" -pollster = "0.3" -bytemuck = { version = "1.18", features = [ "derive" ] } +# wgpu = "22.1" +# cfg-if = "1" +# pollster = "0.3" +# bytemuck = { version = "1.18", features = [ "derive" ] } rand = { version = "0.8", features = ["small_rng"] } -nalgebra = "0.33" +# nalgebra = "0.33" voronoice = "0.2" noise = "0.9" -lazy_static = "1.5" -image = { version = "0.25", default-features = false, features = ["rayon", "png"]} +# lazy_static = "1.5" +# image = { version = "0.25", default-features = false, features = ["rayon", "png"]} [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1.6" @@ -58,3 +95,17 @@ opt-level = 1 # Enable a large amount of optimization in the dev profile for dependencies. [profile.dev.package."*"] opt-level = 3 + +[package.metadata.android] +package = "org.forestiles.example" +apk_name = "forestiles" +# strip = "strip" +# see https://github.com/rust-mobile/cargo-apk +# assets = "assets" +build_targets = ["aarch64-linux-android", "armv7-linux-androideabi"] + +[package.metadata.android.sdk] +target_sdk_version = 31 + +[package.metadata.android.application] +label = "Forestiles" \ No newline at end of file diff --git a/src/camera.rs b/src/camera.rs index 14c0a00..c4449c8 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,4 +1,4 @@ -use bevy::{picking::{focus::HoverMap, pointer::PointerId}, prelude::*, utils::HashMap, window::PrimaryWindow}; +use bevy::{math::NormedVectorSpace, picking::{focus::HoverMap, pointer::PointerId}, prelude::*, utils::HashMap, window::PrimaryWindow}; use crate::ui; @@ -34,26 +34,40 @@ fn move_cam( let window = window.single(); let mut cam = cam.single_mut(); let map_ui_entity = map_ui_entity.single(); - for (id, hit_map) in hover_map.iter() { - if let Some((pressed, new_pos, old_pos)) = match id { - PointerId::Mouse => window.cursor_position().map(|p| (mouse_buttons.pressed(MouseButton::Left), p, None)), - PointerId::Touch(i) => touches.get_pressed(*i).map(|t| (true, t.position(), Some(t.previous_position()))), + let ps = hover_map.iter().filter_map(|(id, hit_map)| match id { + PointerId::Mouse => window.cursor_position().map(|p| (mouse_buttons.pressed(MouseButton::Left), p, pointers.0.get(id).map(|p| *p).unwrap_or(p))), + PointerId::Touch(i) => touches.get_pressed(*i).map(|t| (true, t.position(), t.previous_position())), _ => None - } { - let old_pos = old_pos.unwrap_or(pointers.0.get(id).map(|p| *p).unwrap_or_default()); - // dbg!(pressed, &new_pos, &old_pos); - if pressed { - // dbg!(hit_map); - for entity in hit_map.keys() { - dbg!(entity); - if *entity == map_ui_entity { - let delta = new_pos - old_pos; - cam.translation.x -= delta.x*cam.scale.x; - cam.translation.y += delta.y*cam.scale.y; - } - } - } - pointers.0.insert(*id, new_pos); - } + }.map(|(pressed,new_pos, old_pos)| (pressed,new_pos,old_pos,id,hit_map)) + ).collect::>(); + let pressed_on_map = ps.iter().filter(|p| p.0 && p.4.contains_key(&map_ui_entity)).collect::>(); + // let mut movement = Vec2::ZERO; + // for (pressed, new_pos, old_pos, id, hit_map) in pressed_on_map.iter() { + // let delta = new_pos - old_pos; + // cam.scale += delta.dot(movement)/delta.norm(); + // movement.x -= delta.x*cam.scale.x/pressed_num as f32; + // movement.y += delta.y*cam.scale.y/pressed_num as f32; + // pointers.0.insert(**id, *new_pos); + // } + let old_midpoint = pressed_on_map.iter().fold(Vec2::ZERO, |acc, (_, _, old_pos, _, _)| { + acc + (old_pos/pressed_on_map.len() as f32) + }); + let new_midpoint = pressed_on_map.iter().fold(Vec2::ZERO, |acc, (_, new_pos, _, _, _)| { + acc + (new_pos/pressed_on_map.len() as f32) + }); + cam.translation.x -= (new_midpoint.x - old_midpoint.x)*cam.scale.x; + cam.translation.y += (new_midpoint.y - old_midpoint.y)*cam.scale.y; + + if pressed_on_map.len() > 1 { + let old_d_to_midpoint = pressed_on_map.iter().fold(0., |acc, (_, _, old_pos, _, _)| { + acc + (old_midpoint-old_pos).norm() + }); + let new_d_to_midpoint = pressed_on_map.iter().fold(0., |acc, (_, new_pos, _, _, _)| { + acc + (new_midpoint-new_pos).norm() + }); + let zoom = new_d_to_midpoint/old_d_to_midpoint; + dbg!(zoom); + cam.scale.x /= zoom; + cam.scale.y /= zoom; } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index ab8b999..beba4e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,8 +80,10 @@ pub fn dbg(v: V) -> V { // } // } -#[cfg(not(target_os = "android"))] +// #[cfg(not(target_os = "android"))] +#[bevy_main] pub fn main() { + // #[cfg(target_family = "wasm")] // let (event_loop, window) = { // use winit::platform::web::WindowExtWebSys; @@ -118,23 +120,24 @@ pub fn main() { .run(); } -#[cfg(target_os = "android")] -#[no_mangle] -fn android_main(app: winit::platform::android::activity::AndroidApp) { - use winit::platform::android::{EventLoopBuilderExtAndroid, activity::WindowManagerFlags}; +// #[cfg(target_os = "android")] +// #[no_mangle] +// fn android_main(app: winit::platform::android::activity::AndroidApp) { +// println!("test"); +// // use winit::platform::android::{EventLoopBuilderExtAndroid, activity::WindowManagerFlags}; - android_logger::init_once( - android_logger::Config::default() - .with_max_level(log::LevelFilter::Debug) - .with_filter(android_logger::FilterBuilder::new().parse("app").build()) - ); +// // android_logger::init_once( +// // android_logger::Config::default() +// // .with_max_level(log::LevelFilter::Debug) +// // .with_filter(android_logger::FilterBuilder::new().parse("app").build()) +// // ); - app.set_window_flags(WindowManagerFlags::KEEP_SCREEN_ON | WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty()); +// // app.set_window_flags(WindowManagerFlags::KEEP_SCREEN_ON | WindowManagerFlags::FULLSCREEN, WindowManagerFlags::empty()); - let event_loop = winit::event_loop::EventLoopBuilder::new() - .with_android_app(app) - .build() - .unwrap(); +// // let event_loop = winit::event_loop::EventLoopBuilder::new() +// // .with_android_app(app) +// // .build() +// // .unwrap(); - event_loop.run_app(&mut App::new()).unwrap(); -} \ No newline at end of file +// // event_loop.run_app(&mut App::new()).unwrap(); +// } \ No newline at end of file