From 9d2e41a9713ac389a5c64cd89ed6c9b521a5624f Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Sun, 22 Jan 2023 21:06:08 -0800 Subject: [PATCH 1/9] add offset resource for debug camera --- Cargo.lock | 452 +++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/action.rs | 24 +-- src/bike.rs | 22 +-- src/camera.rs | 50 +++++- src/lights.rs | 6 +- src/planet.rs | 20 +-- src/ui.rs | 12 +- 8 files changed, 530 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2932fa7..8cedfe4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "ahash" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf6ccdb167abbf410dcb915cabd428929d7f6a04980b54a11f26a39f1c7f7107" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", +] + [[package]] name = "aho-corasick" version = "0.7.20" @@ -86,6 +97,26 @@ dependencies = [ "num-traits", ] +[[package]] +name = "arboard" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6041616acea41d67c4a984709ddab1587fd0b10efe5cc563fee954d2f011854" +dependencies = [ + "clipboard-win", + "core-graphics", + "image", + "log", + "objc", + "objc-foundation", + "objc_id", + "once_cell", + "parking_lot", + "thiserror", + "winapi", + "x11rb", +] + [[package]] name = "arrayvec" version = "0.7.2" @@ -142,6 +173,12 @@ version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" +[[package]] +name = "atomic_refcell" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "857253367827bd9d0fd973f0ef15506a96e79e41b0ad7aa691203a4e3214f6c8" + [[package]] name = "autocfg" version = "1.1.0" @@ -163,6 +200,44 @@ dependencies = [ "bevy_internal", ] +[[package]] +name = "bevy-inspector-egui" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be4f9fa859e4840e7cbcc0ddf2c8a1441ff8f663c317769c5ccc70cdf13bcf2" +dependencies = [ + "bevy-inspector-egui-derive", + "bevy_app", + "bevy_asset", + "bevy_core", + "bevy_core_pipeline", + "bevy_ecs", + "bevy_egui", + "bevy_hierarchy", + "bevy_log", + "bevy_math", + "bevy_pbr", + "bevy_reflect", + "bevy_render", + "bevy_utils", + "egui", + "image", + "once_cell", + "pretty-type-name", + "smallvec", +] + +[[package]] +name = "bevy-inspector-egui-derive" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97826e6225a5b56e77683e7b99418171f7531d48682b8531252dc6b8ef3e8113" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "bevy_app" version = "0.9.1" @@ -297,6 +372,19 @@ dependencies = [ "syn", ] +[[package]] +name = "bevy_egui" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb8036050af170243e803eb68e0b5d34f549828a8de92479619fb6dac842f85" +dependencies = [ + "arboard", + "bevy", + "egui", + "thread_local", + "webbrowser", +] + [[package]] name = "bevy_encase_derive" version = "0.9.1" @@ -745,7 +833,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16750aae52cd35bd7b60eb61cee883420b250e11b4a290b8d44b2b2941795739" dependencies = [ - "ahash", + "ahash 0.7.6", "getrandom", "hashbrown", "instant", @@ -847,6 +935,12 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "bytes" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" + [[package]] name = "cache-padded" version = "1.2.0" @@ -859,6 +953,12 @@ version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a20104e2335ce8a659d6dd92a51a767a0c062599c73b343fd152cb401e828c3d" +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + [[package]] name = "cfg-if" version = "1.0.0" @@ -871,6 +971,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "clipboard-win" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + [[package]] name = "cocoa" version = "0.24.1" @@ -918,6 +1029,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + [[package]] name = "concurrent-queue" version = "1.2.4" @@ -1046,7 +1167,7 @@ dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", - "memoffset", + "memoffset 0.7.1", "scopeguard", ] @@ -1080,6 +1201,7 @@ name = "cyber_rider" version = "0.1.0" dependencies = [ "bevy", + "bevy-inspector-egui", "bevy_polyline", "bevy_rapier3d", "hexasphere 7.2.1", @@ -1134,6 +1256,26 @@ dependencies = [ "syn", ] +[[package]] +name = "dirs" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1146,12 +1288,41 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +[[package]] +name = "ecolor" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b601108bca3af7650440ace4ca55b2daf52c36f2635be3587d77b16efd8d0691" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "egui" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65a5e883a316e53866977450eecfbcac9c48109c2ab3394af29feb83fcde4ea9" +dependencies = [ + "ahash 0.8.2", + "epaint", + "nohash-hasher", +] + [[package]] name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "emath" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5277249c8c3430e7127e4f2c40a77485e7baf11ae132ce9b3253a8ed710df0a0" +dependencies = [ + "bytemuck", +] + [[package]] name = "encase" version = "0.4.1" @@ -1194,6 +1365,22 @@ dependencies = [ "regex", ] +[[package]] +name = "epaint" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de14b65fe5e423e0058f77a8beb2c863b056d0566d6c4ce0d097aa5814cb705a" +dependencies = [ + "ab_glyph", + "ahash 0.8.2", + "atomic_refcell", + "bytemuck", + "ecolor", + "emath", + "nohash-hasher", + "parking_lot", +] + [[package]] name = "erased-serde" version = "0.3.24" @@ -1203,6 +1390,16 @@ dependencies = [ "serde", ] +[[package]] +name = "error-code" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" +dependencies = [ + "libc", + "str-buf", +] + [[package]] name = "euclid" version = "0.22.7" @@ -1264,6 +1461,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + [[package]] name = "futures-core" version = "0.3.25" @@ -1300,6 +1506,16 @@ dependencies = [ "byteorder", ] +[[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "getrandom" version = "0.2.8" @@ -1338,7 +1554,7 @@ dependencies = [ "libc", "libudev-sys", "log", - "nix", + "nix 0.25.1", "uuid", "vec_map", "wasm-bindgen", @@ -1495,7 +1711,7 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" dependencies = [ - "ahash", + "ahash 0.7.6", "serde", ] @@ -1537,6 +1753,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "image" version = "0.24.5" @@ -1550,6 +1776,7 @@ dependencies = [ "num-traits", "png", "scoped_threadpool", + "tiff", ] [[package]] @@ -1596,12 +1823,32 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +[[package]] +name = "jni" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "039022cdf4d7b1cf548d31f60ae783138e5fd42013f6271049d7df7afadef96c" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + [[package]] name = "jni-sys" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130" +[[package]] +name = "jpeg-decoder" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e" + [[package]] name = "js-sys" version = "0.3.60" @@ -1727,6 +1974,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + [[package]] name = "memoffset" version = "0.7.1" @@ -1880,6 +2136,18 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "nix" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa52e972a9a719cecb6864fb88568781eb706bac2cd1d4f04a648542dbf78069" +dependencies = [ + "bitflags", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "nix" version = "0.25.1" @@ -1892,6 +2160,12 @@ dependencies = [ "libc", ] +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + [[package]] name = "noise" version = "0.8.2" @@ -1994,6 +2268,17 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -2003,6 +2288,15 @@ dependencies = [ "cc", ] +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "once_cell" version = "1.17.0" @@ -2151,6 +2445,12 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "pretty-type-name" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8815d101cfb4cb491154896bdab292a395a7ac9ab185a9941a2f5be0135900d" + [[package]] name = "proc-macro-crate" version = "1.2.1" @@ -2297,6 +2597,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom", + "redox_syscall", + "thiserror", +] + [[package]] name = "regex" version = "1.7.1" @@ -2367,6 +2678,15 @@ dependencies = [ "bytemuck", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scoped_threadpool" version = "0.1.9" @@ -2488,6 +2808,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "str-buf" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" + [[package]] name = "strsim" version = "0.10.0" @@ -2562,6 +2888,32 @@ dependencies = [ "once_cell", ] +[[package]] +name = "tiff" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471" +dependencies = [ + "flate2", + "jpeg-decoder", + "weezl", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + [[package]] name = "toml" version = "0.5.11" @@ -2656,12 +3008,27 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +[[package]] +name = "unicode-bidi" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-width" version = "0.1.10" @@ -2674,6 +3041,17 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "uuid" version = "1.2.2" @@ -2708,6 +3086,17 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2790,6 +3179,30 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webbrowser" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e74f5ff7786c4c21f61ba8e30ea29c9745f06fca0a4a02d083b3c662583399e8" +dependencies = [ + "core-foundation", + "dirs", + "jni", + "log", + "ndk-context", + "objc", + "raw-window-handle 0.5.0", + "url", + "web-sys", + "windows", +] + +[[package]] +name = "weezl" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" + [[package]] name = "wgpu" version = "0.14.2" @@ -2919,6 +3332,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -3080,6 +3502,28 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "x11rb" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" +dependencies = [ + "gethostname", + "nix 0.24.3", + "winapi", + "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" +dependencies = [ + "nix 0.24.3", +] + [[package]] name = "xi-unicode" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index 6e05936..07ab615 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ bevy_polyline = "0.4" noise = { git = "https://github.com/Razaekel/noise-rs" } hexasphere = "7" wgpu = "0.14" +bevy-inspector-egui = "0.17.0" # wgpu = "0.12" [features] diff --git a/src/action.rs b/src/action.rs index 6860e80..443b394 100644 --- a/src/action.rs +++ b/src/action.rs @@ -2,11 +2,8 @@ use bevy::{ diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin}, prelude::*, }; -use bevy_rapier3d::{ - prelude::{ - ExternalForce, Friction, NoUserData, RapierConfiguration, RapierPhysicsPlugin, Velocity, - }, - render::{DebugRenderMode, RapierDebugRenderPlugin}, +use bevy_rapier3d::prelude::{ + ExternalForce, Friction, NoUserData, RapierConfiguration, RapierPhysicsPlugin, Velocity, }; use crate::{ @@ -39,8 +36,8 @@ fn gravity( mut query: Query<(&Transform, &mut ExternalForce), With>, settings: Res, ) { - let (xform, mut forces) = query.single_mut(); - let grav = xform.translation.normalize() * -settings.gravity; + let (_xform, mut forces) = query.single_mut(); + let grav = Vec3::Y * -settings.gravity; forces.force = grav; } @@ -49,7 +46,7 @@ fn falling_cat_pid( diagnostics: Res, ) { let (xform, mut forces, mut control_vars) = bike_query.single_mut(); - let up = xform.translation.normalize(); + let up = Vec3::Y; let bike_up = xform.up(); let torque = bike_up.cross(up).normalize_or_zero(); @@ -114,19 +111,8 @@ fn drag(mut query: Query<(&Velocity, &mut ExternalForce), With>) pub struct CyberActionPlugin; impl Plugin for CyberActionPlugin { fn build(&self, app: &mut App) { - let mut mode = DebugRenderMode::RIGID_BODY_AXES; - //mode.insert(DebugRenderMode::COLLIDER_SHAPES); - mode.insert(DebugRenderMode::CONTACTS); - mode.insert(DebugRenderMode::JOINTS); - let rplugin = RapierDebugRenderPlugin { - always_on_top: true, - enabled: true, - mode, - ..Default::default() - }; app.init_resource::() .add_plugin(RapierPhysicsPlugin::::default()) - .add_plugin(rplugin) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_startup_system(zero_gravity) .add_system(gravity.before("cat")) diff --git a/src/bike.rs b/src/bike.rs index 5b3632a..5fcc3a6 100644 --- a/src/bike.rs +++ b/src/bike.rs @@ -1,9 +1,16 @@ use bevy::prelude::*; -use bevy_rapier3d::{geometry::Group, prelude::*}; +use bevy_rapier3d::{ + geometry::Group, + prelude::{ + Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction, + ImpulseJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping, + TransformInterpolation, Velocity, + }, +}; use crate::planet::PLANET_RADIUS; -pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.01; +pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 0.2; #[derive(Component)] pub struct CyberBikeBody; @@ -24,8 +31,8 @@ const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_ const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10); fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { - let xform = Transform::from_translation(Vec3::X * SPAWN_ALTITUDE) - .with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); + let xform = Transform::from_translation(Vec3::Y * SPAWN_ALTITUDE); + //.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); let damping = Damping { angular_damping: 0.5, @@ -141,13 +148,6 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { pub struct CyberBikePlugin; impl Plugin for CyberBikePlugin { - #[cfg(feature = "debug_render")] - fn build(&self, app: &mut App) { - app.add_plugin(RapierDebugRenderPlugin::default()) - .add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); - } - - #[cfg(not(feature = "debug_render"))] fn build(&self, app: &mut App) { app.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); } diff --git a/src/camera.rs b/src/camera.rs index 8e3937c..51f1593 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -1,4 +1,5 @@ use bevy::prelude::*; +use bevy_rapier3d::render::{DebugRenderMode, DebugRenderStyle, RapierDebugRenderPlugin}; use crate::{bike::CyberBikeModel, input::InputState}; @@ -11,6 +12,21 @@ enum CyberCameras { Debug, } +#[derive(Debug, Resource)] +pub struct DebugCamOffset { + pub rot: f32, + pub dist: f32, +} + +impl Default for DebugCamOffset { + fn default() -> Self { + DebugCamOffset { + rot: 60.0, + dist: 10.0, + } + } +} + impl CyberCameras { fn next(self) -> Self { match self { @@ -45,9 +61,10 @@ fn follow_cyberbike( Query<(&mut Transform, &CyberCameras)>, )>, input: Res, + offset: Res, ) { let bike_xform = *query.p0().single(); - let up = bike_xform.translation.normalize(); + let up = Vec3::Y; for (mut cam_xform, cam_type) in query.p1().iter_mut() { match *cam_type { @@ -64,11 +81,10 @@ fn follow_cyberbike( cam_xform.rotate(Quat::from_axis_angle(axis, angle)); } CyberCameras::Debug => { - let pos = bike_xform.translation - + (bike_xform.forward() * 20.0) - + (bike_xform.left() * 2.0) - + (bike_xform.up() * 5.0); - cam_xform.translation = pos; + let mut ncx = bike_xform.to_owned(); + ncx.rotate(Quat::from_axis_angle(up, offset.rot.to_radians())); + ncx.translation += ncx.forward() * offset.dist; + *cam_xform = ncx; cam_xform.look_at(bike_xform.translation, up); } } @@ -101,7 +117,27 @@ fn cycle_cam_state(mut state: ResMut>, mut keys: ResMut, mut query: Query<(&mut Transform, &AnimatedCybe pub struct CyberSpaceLightsPlugin; impl Plugin for CyberSpaceLightsPlugin { fn build(&self, app: &mut App) { - app.add_startup_system(spawn_static_lights) - .add_startup_system(spawn_moving_lights) - .add_system(orbit_lights); + app.add_startup_system(spawn_static_lights); + //.add_startup_system(spawn_moving_lights) + //.add_system(orbit_lights); } } diff --git a/src/planet.rs b/src/planet.rs index 00a1268..dcf5317 100644 --- a/src/planet.rs +++ b/src/planet.rs @@ -1,15 +1,13 @@ use bevy::{ - prelude::{shape::Icosphere, *}, + prelude::{shape::Plane, *}, render::mesh::Indices, }; use bevy_rapier3d::prelude::*; -use hexasphere::shapes::IcoSphere; -use noise::{HybridMulti, NoiseFn, SuperSimplex}; use wgpu::PrimitiveTopology; use crate::Label; -pub const PLANET_RADIUS: f32 = 6000.0; +pub const PLANET_RADIUS: f32 = 600.0; #[derive(Component)] pub struct CyberPlanet; @@ -20,12 +18,12 @@ fn spawn_planet( mut materials: ResMut>, ) { let color = Color::rgb(0.2, 0.1, 0.2); - let isphere = Icosphere { - radius: PLANET_RADIUS, - subdivisions: 88, + let plane = Plane { + size: PLANET_RADIUS, }; - - let (mesh, shape) = gen_planet(isphere); + //let (mesh, shape) = gen_planet(plane); + let mesh = Mesh::from(plane); + let shape = Collider::from_bevy_mesh(&mesh, &ComputedColliderShape::TriMesh).unwrap(); let pbody = (RigidBody::Fixed, Ccd { enabled: true }); @@ -67,7 +65,8 @@ impl Plugin for CyberPlanetPlugin { // utils //--------------------------------------------------------------------- -fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) { +/* +fn gen_planet(sphere: Plane) -> (Mesh, Collider) { // straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the // displacement before normals are calculated. let generated = IcoSphere::new(sphere.subdivisions, |point| { @@ -120,3 +119,4 @@ fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) { mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); (mesh, shape) } +*/ diff --git a/src/ui.rs b/src/ui.rs index 50c5a3b..8b82213 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,5 +1,9 @@ -use bevy::prelude::*; -use bevy_rapier3d::prelude::*; +use bevy::prelude::{ + AlignSelf, App, AssetServer, Color, Commands, Component, Plugin, Query, Res, Style, Text, + TextBundle, TextSection, TextStyle, With, +}; +use bevy_inspector_egui::quick::WorldInspectorPlugin; +use bevy_rapier3d::prelude::Velocity; use crate::bike::CyberBikeBody; @@ -46,6 +50,8 @@ pub struct CyberUIPlugin; impl Plugin for CyberUIPlugin { fn build(&self, app: &mut App) { - app.add_startup_system(setup_ui).add_system(update_ui); + app.add_plugin(WorldInspectorPlugin) + .add_startup_system(setup_ui) + .add_system(update_ui); } } From bf35c963b213fefc61f7d870e5445895e49417ba Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Mon, 23 Jan 2023 20:12:15 -0800 Subject: [PATCH 2/9] add debug cam orbit controls --- src/camera.rs | 3 +++ src/glamor.rs | 3 ++- src/input.rs | 36 ++++++++++++++++++++++++++++++++++-- src/lights.rs | 4 ++-- src/main.rs | 1 - src/planet.rs | 2 +- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 51f1593..65a3586 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -16,6 +16,7 @@ enum CyberCameras { pub struct DebugCamOffset { pub rot: f32, pub dist: f32, + pub alt: f32, } impl Default for DebugCamOffset { @@ -23,6 +24,7 @@ impl Default for DebugCamOffset { DebugCamOffset { rot: 60.0, dist: 10.0, + alt: 4.0, } } } @@ -84,6 +86,7 @@ fn follow_cyberbike( let mut ncx = bike_xform.to_owned(); ncx.rotate(Quat::from_axis_angle(up, offset.rot.to_radians())); ncx.translation += ncx.forward() * offset.dist; + ncx.translation += ncx.up() * offset.alt; *cam_xform = ncx; cam_xform.look_at(bike_xform.translation, up); } diff --git a/src/glamor.rs b/src/glamor.rs index ab3a259..bd4d46d 100644 --- a/src/glamor.rs +++ b/src/glamor.rs @@ -74,7 +74,8 @@ fn wireframify_lights(mut lights: Query<&mut AnimateCyberLightWireframe>) { pub struct CyberGlamorPlugin; impl Plugin for CyberGlamorPlugin { fn build(&self, app: &mut App) { - app.add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet) + app.insert_resource(ClearColor(Color::rgb(0.408, 0.6236, 0.925))) + .add_startup_system_to_stage(StartupStage::PostStartup, wireframe_planet) .add_system(wireframify_lights) .add_plugin(PolylinePlugin); } diff --git a/src/input.rs b/src/input.rs index e075b4e..a0a8014 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,4 +1,7 @@ -use bevy::prelude::*; +use bevy::{prelude::*, utils::HashSet}; + +use crate::camera::DebugCamOffset; + #[derive(Default, Debug, Resource)] pub(crate) struct InputState { pub yaw: f32, @@ -7,6 +10,33 @@ pub(crate) struct InputState { pub pitch: f32, } +fn update_debug_cam(mut offset: ResMut, mut keys: ResMut>) { + let keyset: HashSet<_> = keys.get_pressed().collect(); + let shifted = keyset.contains(&KeyCode::LShift) || keyset.contains(&KeyCode::RShift); + + for key in keyset { + match key { + KeyCode::Left => offset.rot += 5.0, + KeyCode::Right => offset.rot -= 5.0, + KeyCode::Up => { + if shifted { + offset.alt += 0.5; + } else { + offset.dist -= 0.5; + } + } + KeyCode::Down => { + if shifted { + offset.alt -= 0.5; + } else { + offset.dist += 0.5; + } + } + _ => continue, + } + } +} + fn update_input(mut events: EventReader, mut istate: ResMut) { for GamepadEvent { gamepad: _, @@ -46,6 +76,8 @@ fn update_input(mut events: EventReader, mut istate: ResMut().add_system(update_input); + app.init_resource::() + .add_system(update_input) + .add_system(update_debug_cam); } } diff --git a/src/lights.rs b/src/lights.rs index e531eb0..65320bb 100644 --- a/src/lights.rs +++ b/src/lights.rs @@ -122,7 +122,7 @@ fn spawn_static_lights( // up light commands .spawn(PointLightBundle { - transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0), + transform: Transform::from_xyz(20.0, 100.0, 20.0), point_light: pink_light, ..Default::default() }) @@ -143,7 +143,7 @@ fn spawn_static_lights( // down light commands .spawn(PointLightBundle { - transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0), + transform: Transform::from_xyz(-20.0, 100.0, -20.0), point_light: blue_light, ..Default::default() }) diff --git a/src/main.rs b/src/main.rs index 8ee6143..e9c6965 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,6 @@ const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { fn main() { let mut app = App::new(); app.insert_resource(Msaa { samples: 4 }) - .insert_resource(ClearColor(Color::rgb(0.07, 0.001, 0.02))) .add_plugins(DefaultPlugins.set(WindowPlugin { window: WindowDescriptor { width: 2560.0, diff --git a/src/planet.rs b/src/planet.rs index dcf5317..0b2b68d 100644 --- a/src/planet.rs +++ b/src/planet.rs @@ -17,7 +17,7 @@ fn spawn_planet( mut meshes: ResMut>, mut materials: ResMut>, ) { - let color = Color::rgb(0.2, 0.1, 0.2); + let color = Color::rgba(0.7, 0.7, 0.8, 0.3); let plane = Plane { size: PLANET_RADIUS, }; From 9b12967abd62656394e19e4ae54a7ec98a5f6759 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Mon, 23 Jan 2023 22:21:16 -0800 Subject: [PATCH 3/9] added wheelconfig struct and hooked in egui inspector --- src/bike.rs | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/bike.rs b/src/bike.rs index 5fcc3a6..0cbe3a3 100644 --- a/src/bike.rs +++ b/src/bike.rs @@ -1,3 +1,5 @@ +use std::fmt::Debug; + use bevy::prelude::*; use bevy_rapier3d::{ geometry::Group, @@ -27,6 +29,32 @@ pub struct CyberBikeControl { pub prev_error: f32, } +#[derive(Resource, Reflect)] +#[reflect(Resource)] +pub struct WheelConfig { + pub front_forward: f32, + pub front_stance: f32, + pub rear_back: f32, + pub y: f32, + pub limits: [f32; 2], + pub stiffness: f32, + pub damping: f32, +} + +impl Default for WheelConfig { + fn default() -> Self { + Self { + front_forward: 0.9, + front_stance: 1.2, + rear_back: 1.1, + y: -1.0, + limits: [0.1, 1.0], + stiffness: 10.0, + damping: 0.7, + } + } +} + const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1); const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10); @@ -117,7 +145,7 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { let trans = xform.translation + offset; let wheel_pos_in_world = Transform::from_rotation(xform.rotation).with_translation(trans); let wheel_damping = Damping { - angular_damping: 0.8, + linear_damping: 0.8, ..Default::default() }; let wheel_collider = Collider::ball(wheel_rad); @@ -149,6 +177,8 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { pub struct CyberBikePlugin; impl Plugin for CyberBikePlugin { fn build(&self, app: &mut App) { - app.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); + app.insert_resource(WheelConfig::default()) + .register_type::() + .add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); } } From 3e9b079b580c3a9c96fe80e60f907c04916cf356 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 24 Jan 2023 19:50:33 -0800 Subject: [PATCH 4/9] checkpoint --- src/action.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/action.rs b/src/action.rs index 443b394..4f9d64d 100644 --- a/src/action.rs +++ b/src/action.rs @@ -28,6 +28,14 @@ impl Default for MovementSettings { } } +#[derive(Debug, Default, Resource, Reflect)] +#[reflect(Resource)] +struct CatControllerSettings { + pub kp: f32, + pub kd: f32, + pub kws: f32, +} + fn zero_gravity(mut config: ResMut) { config.gravity = Vec3::ZERO; } @@ -41,9 +49,10 @@ fn gravity( forces.force = grav; } -fn falling_cat_pid( +fn falling_cat( mut bike_query: Query<(&Transform, &mut ExternalForce, &mut CyberBikeControl)>, diagnostics: Res, + settings: Res, ) { let (xform, mut forces, mut control_vars) = bike_query.single_mut(); let up = Vec3::Y; @@ -51,19 +60,17 @@ fn falling_cat_pid( let torque = bike_up.cross(up).normalize_or_zero(); let cos = up.dot(bike_up); - let cos = if cos.is_finite() { cos } else { 0.0 }; + let cos = if cos.is_finite() { cos } else { 1.0 }; let error = 1.0 - cos; + let derivative = error - control_vars.prev_error; control_vars.prev_error = error; // this integral term is not an integral, it's more like a weighted moving sum - let integral = (control_vars.error_sum + error) * 0.8; - control_vars.error_sum = integral; //.min(2.0).max(-2.0); + let weighted_sum = control_vars.error_sum + error; + control_vars.error_sum = weighted_sum * 0.8; - let kp = 13.1; - let ki = 1.1; - let kd = 8.1; - let mag = (kp * error) + (ki * integral) + (kd * derivative); + let mag = (settings.kp * error) + (settings.kws * weighted_sum) + (settings.kd * derivative); if let Some(count) = diagnostics .get(FrameTimeDiagnosticsPlugin::FRAME_COUNT) @@ -71,7 +78,7 @@ fn falling_cat_pid( .map(|x| x as u64) { if count % 30 == 0 { - dbg!(&control_vars, mag); + dbg!(&control_vars, mag, cos); } } @@ -112,11 +119,13 @@ pub struct CyberActionPlugin; impl Plugin for CyberActionPlugin { fn build(&self, app: &mut App) { app.init_resource::() + .init_resource::() + .register_type::() .add_plugin(RapierPhysicsPlugin::::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_startup_system(zero_gravity) .add_system(gravity.before("cat")) - .add_system(falling_cat_pid.label("cat")) + .add_system(falling_cat.label("cat")) .add_system(input_forces.label("iforces").after("cat")) .add_system(drag.label("drag").after("iforces")); } From ff64bbeff396dbc052846be6cb18233950b24873 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Tue, 24 Jan 2023 23:04:33 -0800 Subject: [PATCH 5/9] add wheels maybe --- Cargo.toml | 2 +- src/action.rs | 12 ++++- src/bike.rs | 122 +++++++++++++++++++++++++++++++++++++++++++------- src/planet.rs | 6 +-- 4 files changed, 118 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 07ab615..6794651 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ features = [ ] [dependencies.bevy_rapier3d] -features = ["simd-nightly"] +features = ["simd-nightly", "debug-render-3d"] version = "0.20" # Maybe also enable only a small amount of optimization for our code: diff --git a/src/action.rs b/src/action.rs index 4f9d64d..eac4151 100644 --- a/src/action.rs +++ b/src/action.rs @@ -28,7 +28,7 @@ impl Default for MovementSettings { } } -#[derive(Debug, Default, Resource, Reflect)] +#[derive(Debug, Resource, Reflect)] #[reflect(Resource)] struct CatControllerSettings { pub kp: f32, @@ -36,6 +36,16 @@ struct CatControllerSettings { pub kws: f32, } +impl Default for CatControllerSettings { + fn default() -> Self { + Self { + kp: 10.0, + kd: 4.0, + kws: 0.85, + } + } +} + fn zero_gravity(mut config: ResMut) { config.gravity = Vec3::ZERO; } diff --git a/src/bike.rs b/src/bike.rs index 0cbe3a3..9237fd3 100644 --- a/src/bike.rs +++ b/src/bike.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; -use bevy::prelude::*; +use bevy::prelude::{shape::Capsule as Tire, *}; use bevy_rapier3d::{ geometry::Group, prelude::{ @@ -14,6 +14,11 @@ use crate::planet::PLANET_RADIUS; pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 0.2; +type Meshterial<'a> = ( + ResMut<'a, Assets>, + ResMut<'a, Assets>, +); + #[derive(Component)] pub struct CyberBikeBody; @@ -23,6 +28,9 @@ pub struct CyberBikeCollider; #[derive(Component, Debug)] pub struct CyberBikeModel; +#[derive(Debug, Component)] +pub struct CyberWheel; + #[derive(Component, Debug, Default, Clone, Copy)] pub struct CyberBikeControl { pub error_sum: f32, @@ -39,6 +47,7 @@ pub struct WheelConfig { pub limits: [f32; 2], pub stiffness: f32, pub damping: f32, + pub radius: f32, } impl Default for WheelConfig { @@ -51,6 +60,7 @@ impl Default for WheelConfig { limits: [0.1, 1.0], stiffness: 10.0, damping: 0.7, + radius: 0.3, } } } @@ -58,7 +68,12 @@ impl Default for WheelConfig { const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1); const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10); -fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { +fn spawn_cyberbike( + mut commands: Commands, + asset_server: Res, + wheel_conf: Res, + mut meshterials: Meshterial, +) { let xform = Transform::from_translation(Vec3::Y * SPAWN_ALTITUDE); //.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); @@ -67,11 +82,10 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { linear_damping: 0.1, }; let not_sleeping = Sleeping::disabled(); - let ccd = Ccd { enabled: true }; let bcollider_shape = - Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.7); + Collider::capsule(Vec3::new(0.0, 0.0, -1.0), Vec3::new(0.0, 0.0, 1.0), 0.50); let friction = Friction { coefficient: 0.0, @@ -127,21 +141,78 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { .id(); //return; - let wheel_z_positions = vec![-1.0, 1.2, -1.0]; - let wheel_y = -1.0f32; + re_tire(&mut commands, &xform, bike, &wheel_conf, &mut meshterials); +} +fn re_tire( + commands: &mut Commands, + xform: &Transform, + bike: Entity, + conf: &WheelConfig, + meshterials: &mut Meshterial, +) { // re-set the collision group let (membership, filter) = BIKE_WHEEL_COLLISION_GROUP; let wheels_collision_group = CollisionGroups::new(membership, filter); + let wheel_y = conf.y; + let wheel_rad = conf.radius; + let stiffness = conf.stiffness; + let not_sleeping = Sleeping::disabled(); + let ccd = Ccd { enabled: true }; + let limits = conf.limits; + let (meshes, materials) = meshterials; - for (i, &wheel_z) in wheel_z_positions.iter().enumerate() { - let (wheel_x, wheel_rad, stiffness) = match i { - 0 => (-1.1, 0.5, 2.0), - 2 => (1.1, 0.5, 2.0), - 1 => (0.0, 0.5, 1.8), - _ => unreachable!(), - }; + let tire = Tire { + radius: wheel_rad, + rings: 1, + depth: 0.2, + ..Default::default() + }; + let material = StandardMaterial { + base_color: Color::Rgba { + red: 0.01, + green: 0.01, + blue: 0.01, + alpha: 1.0, + }, + alpha_mode: AlphaMode::Opaque, + perceptual_roughness: 0.5, + ..Default::default() + }; + + let pbr_bundle = PbrBundle { + material: materials.add(material), + mesh: meshes.add(Mesh::from(tire)), + ..Default::default() + }; + + let mut wheel_poses = Vec::with_capacity(3); + + // left front + { + let wheel_x = -conf.front_stance; + let wheel_z = conf.front_forward; let offset = Vec3::new(wheel_x, wheel_y, wheel_z); + wheel_poses.push(offset); + } + + // right front + { + let wheel_x = conf.front_stance; + let wheel_z = conf.front_forward; + let offset = Vec3::new(wheel_x, wheel_y, wheel_z); + wheel_poses.push(offset); + } + + // rear + { + let wheel_x = -conf.front_stance; + let wheel_z = conf.front_forward; + let offset = Vec3::new(wheel_x, wheel_y, wheel_z); + wheel_poses.push(offset); + } + + for offset in wheel_poses { let trans = xform.translation + offset; let wheel_pos_in_world = Transform::from_rotation(xform.rotation).with_translation(trans); let wheel_damping = Damping { @@ -154,13 +225,27 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { let damping = 0.3; let prismatic = PrismaticJointBuilder::new(Vec3::Y) .local_anchor2(offset) - .limits([-1.0, 0.9]) + .limits(limits) .motor_position(0.0, stiffness, damping); let joint = ImpulseJoint::new(bike, prismatic); - let _wheel_rb = commands + let spatial_bundle = SpatialBundle { + transform: wheel_pos_in_world, + ..Default::default() + }; + + let txform = wheel_pos_in_world.with_rotation(Quat::from_axis_angle( + wheel_pos_in_world.forward(), + 90.0f32.to_radians(), + )); + let tire_spundle = SpatialBundle { + transform: txform, + ..Default::default() + }; + + commands .spawn(RigidBody::Dynamic) - .insert((wheel_pos_in_world, GlobalTransform::default())) + .insert(spatial_bundle) .insert(( wheel_collider, mass_props, @@ -170,7 +255,10 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { joint, wheels_collision_group, )) - .id(); + .with_children(|wheel| { + wheel.spawn(tire_spundle).insert(pbr_bundle.clone()); + }) + .insert(CyberWheel); } } diff --git a/src/planet.rs b/src/planet.rs index 0b2b68d..8709d9c 100644 --- a/src/planet.rs +++ b/src/planet.rs @@ -1,9 +1,5 @@ -use bevy::{ - prelude::{shape::Plane, *}, - render::mesh::Indices, -}; +use bevy::prelude::{shape::Plane, *}; use bevy_rapier3d::prelude::*; -use wgpu::PrimitiveTopology; use crate::Label; From 738dd6569a47fc6b42b0fe17a32a5ed03287be51 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 25 Jan 2023 15:35:28 -0800 Subject: [PATCH 6/9] shut the linter up --- src/lights.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lights.rs b/src/lights.rs index 65320bb..b512587 100644 --- a/src/lights.rs +++ b/src/lights.rs @@ -9,8 +9,8 @@ pub const LIGHT_RANGE: f32 = 90.0; #[derive(Component)] struct AnimatedCyberLight { - axis: Vec3, - rate: f32, + _axis: Vec3, + _rate: f32, } #[derive(Component, Default)] @@ -18,7 +18,7 @@ pub(crate) struct AnimateCyberLightWireframe { pub wired: bool, } -fn spawn_moving_lights( +fn _spawn_moving_lights( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, @@ -27,13 +27,13 @@ fn spawn_moving_lights( // spawn orbiting bisexual lights for _ in 0..655 { // mechanics - let axis = crate::random_unit_vec(rng); + let _axis = crate::random_unit_vec(rng); let angle = rng.gen_range(0.0..TAU); - let rate: f32 = rng.gen_range(7.0..10.0); - let rate = rate.to_radians(); - let rotation = Quat::from_axis_angle(axis, angle); + let _rate: f32 = rng.gen_range(7.0..10.0); + let _rate = _rate.to_radians(); + let rotation = Quat::from_axis_angle(_axis, angle); let altitude = PLANET_RADIUS + rng.gen_range(8.0..20.0); - let perp = axis.any_orthonormal_vector(); + let perp = _axis.any_orthonormal_vector(); let translation = perp * altitude; let transform = Transform::from_translation(translation); @@ -59,7 +59,7 @@ fn spawn_moving_lights( }; commands // first, spawn an entity with a transform we can rotate - .spawn((AnimatedCyberLight { axis, rate },)) + .spawn((AnimatedCyberLight { _axis, _rate },)) .insert(sbundle) .with_children(|parent| { parent @@ -163,12 +163,12 @@ fn spawn_static_lights( }); } -fn orbit_lights(time: Res