From beb2298fe3f5e5b9fcbb48da5eec938f3c35006a Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Mon, 7 Feb 2022 20:28:06 -0800 Subject: [PATCH 1/3] Use Rapier directly for collision handling and gravity. Input still not working. Also, make the cybersphere transparent. --- Cargo.lock | 251 +++++++++++++++++++++--------------------------- Cargo.toml | 6 +- src/action.rs | 118 ++++++++++++----------- src/geometry.rs | 22 ++--- src/main.rs | 4 +- 5 files changed, 184 insertions(+), 217 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62085c6..009256f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -134,9 +134,9 @@ checksum = "677d306121baf53310a3fd342d88dc0824f6bbeace68347593658525565abee8" [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base-x" @@ -449,15 +449,26 @@ dependencies = [ [[package]] name = "bevy_polyline" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5c82e6ea20642e4d8aa120bcf0ae09d7cae067825d7f954228c246bb8c948b" +checksum = "0973d599ae862049333b74cb5216de1be07cf7db675b6dcc0e055006ab41be26" dependencies = [ "bevy", "bitflags", "naga", ] +[[package]] +name = "bevy_rapier3d" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5186c735d7aa202e982f93c71b444d34bf15fed44aca942f9b5f2940e3d06764" +dependencies = [ + "bevy", + "nalgebra", + "rapier3d", +] + [[package]] name = "bevy_reflect" version = "0.6.0" @@ -804,7 +815,7 @@ dependencies = [ "bitflags", "block", "cocoa-foundation", - "core-foundation 0.9.2", + "core-foundation 0.9.3", "core-graphics 0.22.3", "foreign-types", "libc", @@ -819,7 +830,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" dependencies = [ "bitflags", "block", - "core-foundation 0.9.2", + "core-foundation 0.9.3", "core-graphics-types", "foreign-types", "libc", @@ -889,9 +900,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys 0.8.3", "libc", @@ -934,7 +945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" dependencies = [ "bitflags", - "core-foundation 0.9.2", + "core-foundation 0.9.3", "core-graphics-types", "foreign-types", "libc", @@ -947,7 +958,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", - "core-foundation 0.9.2", + "core-foundation 0.9.3", "foreign-types", "libc", ] @@ -1011,9 +1022,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.6" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762" +checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1024,9 +1035,9 @@ dependencies = [ [[package]] name = "crossbeam-queue" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b979d76c9fcb84dffc80a73f7290da0f83e4c95773494674cb44b76d13a7a110" +checksum = "4dd435b205a4842da59efd07628f921c096bc1cc0a156835b4fa0bcb9a19bcce" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1034,9 +1045,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120" +checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6" dependencies = [ "cfg-if 1.0.0", "lazy_static", @@ -1054,7 +1065,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy_polyline", - "heron", + "bevy_rapier3d", "rand", ] @@ -1132,16 +1143,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "duplicate" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cdaf23abc9bcc47fda1ae3af68425a22b4dfbd745f9077be0eaad5320f75f52" -dependencies = [ - "heck", - "proc-macro-error", -] - [[package]] name = "either" version = "1.6.1" @@ -1220,15 +1221,15 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "futures-core" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" +checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" [[package]] name = "futures-io" -version = "0.3.19" +version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" +checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" [[package]] name = "futures-lite" @@ -1428,15 +1429,6 @@ dependencies = [ "ahash", ] -[[package]] -name = "heck" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1446,54 +1438,6 @@ dependencies = [ "libc", ] -[[package]] -name = "heron" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54579e36436e33827e21f046ea6752b3a93dbd0b05884bffe982568af7b3bebd" -dependencies = [ - "bevy", - "cfg_aliases", - "heron_core", - "heron_macros", - "heron_rapier", -] - -[[package]] -name = "heron_core" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7099a07736abf70026b1e474fff8d74a8fa88a834cfd33e974541e6b056abb41" -dependencies = [ - "bevy", - "cfg_aliases", - "duplicate", -] - -[[package]] -name = "heron_macros" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a09c1e02655f04faf8d6b485f6c27422f3769343c30c39e51a2cd25f3f2869c3" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "heron_rapier" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf94fface67dce71dfd0ab2c0a8b211cacf7b1d02532669671892350765b340" -dependencies = [ - "bevy", - "cfg_aliases", - "crossbeam", - "fnv", - "heron_core", - "rapier3d", -] - [[package]] name = "hex" version = "0.4.3" @@ -1621,9 +1565,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.114" +version = "0.2.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0005d08a8f7b65fb8073cb697aa0b12b631ed251ce73d862ce50eeb52ce3b50" +checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c" [[package]] name = "libloading" @@ -1641,6 +1585,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" +[[package]] +name = "libm" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33a33a362ce288760ec6a508b94caaec573ae7d3bbbd91b87aa0bad4456839db" + [[package]] name = "libudev-sys" version = "0.1.4" @@ -1653,9 +1603,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712a4d093c9976e24e7dbca41db895dabcbac38eb5f4045393d17a95bdfb1109" +checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" dependencies = [ "scopeguard", ] @@ -1745,9 +1695,9 @@ dependencies = [ [[package]] name = "mint" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162e591484b4b8fe9e1ca16ebf07ab584fdc3334508d76a788cd54d89cfc20dc" +checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" [[package]] name = "mio" @@ -1793,11 +1743,12 @@ dependencies = [ [[package]] name = "nalgebra" -version = "0.29.0" +version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d506eb7e08d6329505faa8a3a00a5dcc6de9f76e0c77e4b75763ae3c770831ff" +checksum = "4fb2d0de08694bed883320212c18ee3008576bfe8c306f4c3c4a58b4876998be" dependencies = [ "approx", + "glam", "matrixmultiply", "nalgebra-macros", "num-complex", @@ -1957,6 +1908,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" dependencies = [ "autocfg", + "libm 0.2.2", ] [[package]] @@ -2024,6 +1976,16 @@ dependencies = [ "ttf-parser", ] +[[package]] +name = "packed_simd_2" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defdcfef86dcc44ad208f71d9ff4ce28df6537a4e0d6b0e8e845cb8ca10059a6" +dependencies = [ + "cfg-if 1.0.0", + "libm 0.1.4", +] + [[package]] name = "parking" version = "2.0.0" @@ -2057,9 +2019,9 @@ dependencies = [ [[package]] name = "parry3d" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "067fa44bf7f7cc4022756ef9796c5f8d67c7a63041df71e6eeb09ad08ab1ece8" +checksum = "c418a03e2ba297c931c530a690b305ce3b3dcc675caf16777f4f8565c8e84732" dependencies = [ "approx", "bitflags", @@ -2145,30 +2107,6 @@ dependencies = [ "toml", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.36" @@ -2241,9 +2179,9 @@ checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6" [[package]] name = "rapier3d" -version = "0.11.1" +version = "0.12.0-alpha.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfc8dde2352efdbc0813938fcc41d12651b4bb05211e81d2b44ff6c09d39b2ac" +checksum = "3f0590e74514004c7313934d092ed071302146323124efde9d30d6aa517186bf" dependencies = [ "approx", "arrayvec", @@ -2256,8 +2194,10 @@ dependencies = [ "num-derive", "num-traits", "parry3d", + "rayon", "rustc-hash", "simba", + "vec_map", ] [[package]] @@ -2275,6 +2215,31 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + [[package]] name = "rectangle-pack" version = "0.4.2" @@ -2458,13 +2423,14 @@ dependencies = [ [[package]] name = "simba" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b7840f121a46d63066ee7a99fc81dcabbc6105e437cae43528cea199b5a05f" +checksum = "13a2609e876d4f77f6ab7ff5254fc39b4f1927ba8e6db3d18be7c32534d3725e" dependencies = [ "approx", "num-complex", "num-traits", + "packed_simd_2", "paste", "wide", ] @@ -2561,7 +2527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b0dc6d20ce137f302edf90f9cd3d278866fd7fb139efca6f246161222ad6d87" dependencies = [ "lazy_static", - "libm", + "libm 0.1.4", ] [[package]] @@ -2637,9 +2603,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.29" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +checksum = "2d8d93354fe2a8e50d5953f5ae2e47a3fc2ef03292e7ea46e3cc38f549525fb9" dependencies = [ "cfg-if 1.0.0", "pin-project-lite", @@ -2649,9 +2615,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +checksum = "8276d9a4a3a558d7b7ad5303ad50b53d58264641b82914b7ada36bd762e7a716" dependencies = [ "proc-macro2", "quote", @@ -2660,11 +2626,12 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +checksum = "03cfcb51380632a72d3111cb8d3447a8d908e577d31beeac006f836383d29a23" dependencies = [ "lazy_static", + "valuable", ] [[package]] @@ -2680,9 +2647,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5312f325fe3588e277415f5a6cca1f4ccad0f248c4cd5a4bd33032d7286abc22" +checksum = "74786ce43333fcf51efe947aed9718fbe46d5c7328ec3f1029e818083966d9aa" dependencies = [ "ansi_term", "lazy_static", @@ -2719,12 +2686,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" -[[package]] -name = "unicode-segmentation" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" - [[package]] name = "unicode-width" version = "0.1.9" @@ -2747,6 +2708,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "vec_map" version = "0.8.2" @@ -2987,7 +2954,7 @@ checksum = "9b43cc931d58b99461188607efd7acb2a093e65fc621f54cad78517a6063e73a" dependencies = [ "bitflags", "cocoa", - "core-foundation 0.9.2", + "core-foundation 0.9.3", "core-graphics 0.22.3", "core-video-sys", "dispatch", diff --git a/Cargo.toml b/Cargo.toml index bf7330a..85fd106 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,9 +19,9 @@ features = [ "x11", ] -[dependencies.heron] -version = "1.1" -features = ["3d"] +[dependencies.bevy_rapier3d] +version = "0.12" +features = ["parallel", "simd-nightly"] # Enable optimizations for dependencies (incl. Bevy), but not for our code: [profile.dev.package."*"] diff --git a/src/action.rs b/src/action.rs index c38edca..b5c242c 100644 --- a/src/action.rs +++ b/src/action.rs @@ -1,7 +1,10 @@ use bevy::prelude::*; -use heron::prelude::*; +use bevy_rapier3d::prelude::*; -use crate::{geometry::CyberBike, input::InputState}; +use crate::{ + geometry::{CyberBike, CyberSphere, PLANET_RADIUS}, + input::InputState, +}; /// Mouse sensitivity and movement speed pub struct MovementSettings { @@ -25,13 +28,21 @@ impl Default for MovementSettings { #[derive(Component, Default)] pub(crate) struct CyberBikeState { pub velocity: Vec3, - pub colliding: bool, + pub _colliding: bool, } -fn falling_cat(time: Res