minor cleanup

This commit is contained in:
Joe Ardent 2024-08-04 12:44:22 -07:00
parent 2b58ac82c4
commit 0592ae588a
11 changed files with 150 additions and 230 deletions

223
Cargo.lock generated
View file

@ -182,9 +182,9 @@ dependencies = [
[[package]]
name = "arrayref"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545"
checksum = "9d151e35f61089500b617991b791fc8bfd237ae50cd5950803758a179b41e67a"
[[package]]
name = "arrayvec"
@ -231,9 +231,9 @@ dependencies = [
[[package]]
name = "async-executor"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8828ec6e544c02b0d6691d21ed9f9218d0384a82542855073c2a3f58304aaf0"
checksum = "d7ebdfa2ebdab6b1760375fa7d6f382b9f486eac35fc994625a00e89280bdbb7"
dependencies = [
"async-task",
"concurrent-queue",
@ -298,7 +298,6 @@ dependencies = [
"itertools 0.13.0",
"nalgebra",
"parry3d",
"parry3d-f64",
]
[[package]]
@ -309,7 +308,7 @@ checksum = "b4adeeecb6d4628d3ca11836ce9af8309f9552d4bd3e3f6e4368440d8163260c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -434,7 +433,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -518,7 +517,7 @@ checksum = "c8a8173bad3ed53fa158806b1beda147263337d6ef71a093780dd141b74386b1"
dependencies = [
"bevy_macro_utils",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -595,7 +594,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -655,7 +654,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -783,8 +782,8 @@ checksum = "c3ad860d35d74b35d4d6ae7f656d163b6f475aa2e64fc293ee86ac901977ddb7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"toml_edit 0.22.15",
"syn 2.0.72",
"toml_edit 0.22.17",
]
[[package]]
@ -871,7 +870,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"uuid",
]
@ -932,7 +931,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1004,7 +1003,7 @@ dependencies = [
"bevy_macro_utils",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1124,7 +1123,7 @@ checksum = "ad9db261ab33a046e1f54b35f885a44f21fcc80aa2bc9050319466b88fe58fe3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1188,7 +1187,7 @@ dependencies = [
"regex",
"rustc-hash",
"shlex",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1285,7 +1284,7 @@ checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1294,6 +1293,12 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "byteorder-lite"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1fe948ff07f4bd06c30984e69f5b4899c516a3ef74f34df92a2df2ab535495"
[[package]]
name = "bytes"
version = "1.6.1"
@ -1302,9 +1307,9 @@ checksum = "a12916984aab3fa6e39d655a33e09c0071eb36d6ab3aea5c2d78551f1df6d952"
[[package]]
name = "calloop"
version = "0.12.4"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298"
checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec"
dependencies = [
"bitflags 2.6.0",
"log",
@ -1316,9 +1321,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.1.5"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "324c74f2155653c90b04f25b2a47a8a631360cb908f92a772695f430c7e31052"
checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f"
dependencies = [
"jobserver",
"libc",
@ -1365,7 +1370,7 @@ checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
dependencies = [
"glob",
"libc",
"libloading 0.8.4",
"libloading 0.8.5",
]
[[package]]
@ -1578,25 +1583,6 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.20"
@ -1618,7 +1604,6 @@ dependencies = [
"hexasphere 14.0.0",
"noise",
"rand",
"wgpu",
]
[[package]]
@ -1628,7 +1613,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b28bfe653d79bd16c77f659305b195b82bb5ce0c0eb2a4846b82ddbd77586813"
dependencies = [
"bitflags 2.6.0",
"libloading 0.8.4",
"libloading 0.8.5",
"winapi",
]
@ -1654,7 +1639,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustc_version",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1669,7 +1654,7 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412"
dependencies = [
"libloading 0.8.4",
"libloading 0.8.5",
]
[[package]]
@ -1728,7 +1713,7 @@ checksum = "fd31dbbd9743684d339f907a87fe212cb7b51d75b9e8e74181fe363199ee9b47"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -1854,7 +1839,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2021,7 +2006,7 @@ dependencies = [
"inflections",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2144,7 +2129,7 @@ dependencies = [
"bitflags 2.6.0",
"com",
"libc",
"libloading 0.8.4",
"libloading 0.8.5",
"thiserror",
"widestring",
"winapi",
@ -2184,12 +2169,12 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
name = "image"
version = "0.25.1"
version = "0.25.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd54d660e773627692c524beaad361aca785a4f9f5730ce91f42aabe5bce3d11"
checksum = "99314c8a2152b8ddb211f924cdae532d8c5e4c8bb54728e12fff1b0cd5963a10"
dependencies = [
"bytemuck",
"byteorder",
"byteorder-lite",
"num-traits",
"png",
]
@ -2297,9 +2282,9 @@ checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
[[package]]
name = "jobserver"
version = "0.1.31"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e"
checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0"
dependencies = [
"libc",
]
@ -2320,7 +2305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76"
dependencies = [
"libc",
"libloading 0.8.4",
"libloading 0.8.5",
"pkg-config",
]
@ -2380,9 +2365,9 @@ dependencies = [
[[package]]
name = "libloading"
version = "0.8.4"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d"
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
dependencies = [
"cfg-if",
"windows-targets 0.52.6",
@ -2472,9 +2457,9 @@ dependencies = [
[[package]]
name = "matrixmultiply"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2"
checksum = "9380b911e3e96d10c1f415da0876389aaf1b56759054eeb0de7df940c456ba1a"
dependencies = [
"autocfg",
"rawpointer",
@ -2584,7 +2569,7 @@ checksum = "254a5372af8fc138e36684761d3c0cdb758a4410e938babcff1c860ce14ddbfc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2715,7 +2700,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -2765,7 +2750,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3086,30 +3071,6 @@ dependencies = [
"nalgebra",
"num-derive",
"num-traits",
"rayon",
"rustc-hash",
"simba",
"slab",
"smallvec",
"spade",
]
[[package]]
name = "parry3d-f64"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdc07fa374273eca29066d59d3ded520bf845ed582e38c0d60109459ea4ed76e"
dependencies = [
"approx",
"arrayvec",
"bitflags 1.3.2",
"downcast-rs",
"either",
"log",
"nalgebra",
"num-derive",
"num-traits",
"rayon",
"rustc-hash",
"simba",
"slab",
@ -3158,7 +3119,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3329,26 +3290,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]]
name = "rectangle-pack"
version = "0.4.2"
@ -3549,7 +3490,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3632,9 +3573,9 @@ dependencies = [
[[package]]
name = "spade"
version = "2.9.0"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f4ec45f91925e2c9ab3b6a857ee9ed36916990df76a1c475d783a328e247cc8"
checksum = "7d676a3ce6cfd1e455199fefcf82db082f970872ce017df660f076a4e07a0d64"
dependencies = [
"hashbrown",
"num-traits",
@ -3676,9 +3617,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.71"
version = "2.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af"
dependencies = [
"proc-macro2",
"quote",
@ -3723,22 +3664,22 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2675633b1499176c2dff06b0856a27976a8f9d436737b4cf4f312d4d91d8bbb"
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d20468752b09f49e909e55a5d338caa8bedf615594e9d80bc4c565d30faf798c"
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3768,9 +3709,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "toml_datetime"
version = "0.6.6"
version = "0.6.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
checksum = "f8fb9f64314842840f1d940ac544da178732128f1c78c21772e876579e0da1db"
[[package]]
name = "toml_edit"
@ -3785,13 +3726,13 @@ dependencies = [
[[package]]
name = "toml_edit"
version = "0.22.15"
version = "0.22.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59a3a72298453f564e2b111fa896f8d07fabb36f51f06d7e875fc5e0b5a3ef1"
checksum = "8d9f8729f5aea9562aac1cc0441f5d6de3cff1ee0c5d67293eeca5eb36ee7c16"
dependencies = [
"indexmap",
"toml_datetime",
"winnow 0.6.13",
"winnow 0.6.16",
]
[[package]]
@ -3813,7 +3754,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -3942,9 +3883,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "version_check"
version = "0.9.4"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "walkdir"
@ -3983,7 +3924,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"wasm-bindgen-shared",
]
@ -4017,7 +3958,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -4125,7 +4066,7 @@ dependencies = [
"js-sys",
"khronos-egl",
"libc",
"libloading 0.8.4",
"libloading 0.8.5",
"log",
"metal",
"naga",
@ -4159,9 +4100,9 @@ dependencies = [
[[package]]
name = "wide"
version = "0.7.25"
version = "0.7.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2caba658a80831539b30698ae9862a72db6697dfdd7151e46920f5f2755c3ce2"
checksum = "901e8597c777fa042e9e245bd56c0dc4418c5db3f845b6ff94fbac732c6a0692"
dependencies = [
"bytemuck",
"safe_arch",
@ -4276,7 +4217,7 @@ checksum = "942ac266be9249c84ca862f0a164a39533dc2f6f33dc98ec89c8da99b82ea0bd"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4287,7 +4228,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4298,7 +4239,7 @@ checksum = "da33557140a288fae4e1d5f8873aaf9eb6613a9cf82c3e070223ff177f598b60"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4309,7 +4250,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]
[[package]]
@ -4538,9 +4479,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winit"
version = "0.30.3"
version = "0.30.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f45a7b7e2de6af35448d7718dab6d95acec466eb3bb7a56f4d31d1af754004"
checksum = "4225ddd8ab67b8b59a2fee4b34889ebf13c0460c1c3fa297c58e21eb87801b33"
dependencies = [
"android-activity",
"atomic-waker",
@ -4591,9 +4532,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.6.13"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1"
checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c"
dependencies = [
"memchr",
]
@ -4618,7 +4559,7 @@ dependencies = [
"as-raw-xcb-connection",
"gethostname",
"libc",
"libloading 0.8.4",
"libloading 0.8.5",
"once_cell",
"rustix",
"x11rb-protocol",
@ -4678,5 +4619,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.71",
"syn 2.0.72",
]

View file

@ -8,7 +8,7 @@ rand = "0.8"
# bevy_polyline = "0.4"
noise = "0.9"
hexasphere = "14"
wgpu = "0.20"
#wgpu = "0.20"
# bevy-inspector-egui = "0.18"
[features]
@ -20,8 +20,9 @@ default-features = true
features = ["bevy_dev_tools"]
[dependencies.avian3d]
default-features = true
default-features = false
version = "0.1"
features = ["3d", "f32", "parry-f32", "debug-plugin", "default-collider", "collider-from-mesh"]
# Maybe also enable only a small amount of optimization for our code:
[profile.dev]

View file

@ -36,7 +36,7 @@ pub struct MovementSettings {
impl Default for MovementSettings {
fn default() -> Self {
Self {
accel: 2000.0,
accel: 40.0,
gravity: 9.8,
}
}

View file

@ -29,7 +29,7 @@ impl Plugin for CyberActionPlugin {
.register_type::<CyberLean>()
.register_type::<CatControllerSettings>()
.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin))
.insert_resource(SubstepCount(12))
.insert_resource(SubstepCount(24))
.add_systems(
FixedUpdate,
(set_gravity, calculate_lean, apply_lean, apply_inputs).chain(),

View file

@ -1,39 +1,16 @@
use std::f32::consts::{FRAC_PI_3, FRAC_PI_4};
use avian3d::{
dynamics::solver::xpbd::AngularConstraint,
prelude::{ExternalTorque, FixedJoint, Gravity, LinearVelocity, RigidBodyQuery},
};
use avian3d::prelude::{AngleLimit, ExternalTorque, Gravity, LinearVelocity, RevoluteJoint};
#[cfg(feature = "inspector")]
use bevy::prelude::Gizmos;
use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without};
use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With};
use super::{CatControllerSettings, CatControllerState, CyberLean, MovementSettings};
use crate::{
bike::{CyberBikeBody, CyberFork, CyberSteering, CyberWheel},
bike::{CyberBikeBody, CyberSteering, CyberWheel},
input::InputState,
};
fn yaw_to_angle(yaw: f32) -> f32 {
let v = yaw.powi(5) * FRAC_PI_4;
if v.is_normal() {
v
} else {
0.0
}
}
fn rotate_point(pt: &Vec3, rot: &Quat) -> Vec3 {
// thanks to https://danceswithcode.net/engineeringnotes/quaternions/quaternions.html
let [x, y, z] = pt.normalize().to_array();
let qpt = Quat::from_xyzw(x, y, z, 0.0);
// p' = rot^-1 * qpt * rot
let rot_qpt = rot.inverse() * qpt * *rot;
// why does this need to be inverted???
-Vec3::from_array([rot_qpt.x, rot_qpt.y, rot_qpt.z])
}
/// The gravity vector points from the cyberbike to the center of the planet.
pub(super) fn set_gravity(
xform: Query<&Transform, With<CyberBikeBody>>,
@ -110,24 +87,40 @@ pub(super) fn apply_lean(
pub(super) fn apply_inputs(
settings: Res<MovementSettings>,
input: Res<InputState>,
time: Res<Time>,
mut wheels: Query<(&Transform, &mut ExternalTorque), With<CyberWheel>>,
mut body_query: Query<RigidBodyQuery, (With<CyberBikeBody>, Without<CyberSteering>)>,
mut steering: Query<&mut RevoluteJoint, With<CyberSteering>>,
) {
let Ok(mut _bike) = body_query.get_single_mut() else {
bevy::log::debug!("no bike body found");
return;
};
let dt = time.delta_seconds();
// brake + thrust
for (xform, mut torque) in wheels.iter_mut() {
let factor = input.throttle * settings.accel;
let target = dt * factor;
let target = input.throttle * settings.accel;
let tork = target * *xform.left();
torque.apply_torque(tork);
}
// steering
let mut steering = steering.single_mut();
let angle = yaw_to_angle(input.yaw);
let angle = if angle.is_normal() { angle } else { 0.0 };
let limit = AngleLimit::new(angle - 0.01, angle + 0.01);
steering.angle_limit = Some(limit);
}
fn yaw_to_angle(yaw: f32) -> f32 {
let v = yaw.powi(5) * FRAC_PI_4;
if v.is_normal() {
v
} else {
0.0
}
}
fn rotate_point(pt: &Vec3, rot: &Quat) -> Vec3 {
// thanks to https://danceswithcode.net/engineeringnotes/quaternions/quaternions.html
let [x, y, z] = pt.normalize().to_array();
let qpt = Quat::from_xyzw(x, y, z, 0.0);
// p' = rot^-1 * qpt * rot
let rot_qpt = rot.inverse() * qpt * *rot;
// why does this need to be inverted???
-Vec3::from_array([rot_qpt.x, rot_qpt.y, rot_qpt.z])
}

View file

@ -17,7 +17,7 @@ pub(super) fn spawn_cyberbike(
let altitude = PLANET_RADIUS - 10.0;
let mut xform = Transform::from_translation(Vec3::X * altitude)
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));
.with_rotation(Quat::from_axis_angle(Vec3::Z, (-89.0f32).to_radians()));
let right = xform.right() * 350.0;
xform.translation += right;

View file

@ -1,5 +1,4 @@
use bevy::{
math::Vec3,
prelude::{Component, ReflectResource, Resource},
reflect::Reflect,
};
@ -13,9 +12,6 @@ pub struct CyberSteering;
#[derive(Clone, Copy, Debug, Component)]
pub struct CyberWheel;
#[derive(Clone, Debug, Component)]
pub struct CyberFork(pub Vec3);
#[derive(Resource, Reflect)]
#[reflect(Resource)]
pub struct WheelConfig {
@ -43,8 +39,8 @@ impl Default for WheelConfig {
damping: 8.0,
radius: 0.40,
thickness: 0.15,
friction: 0.9,
restitution: 0.5,
friction: 1.5,
restitution: 0.1,
density: 30.0,
}
}

View file

@ -1,7 +1,7 @@
use avian3d::prelude::*;
use avian3d::{math::FRAC_PI_2, prelude::*};
use bevy::prelude::*;
use super::{CyberFork, CyberSteering, CyberWheel, Meshterial, WheelConfig};
use super::{CyberSteering, CyberWheel, Meshterial, WheelConfig};
use crate::ColliderGroups;
pub fn spawn_wheels(
@ -34,7 +34,13 @@ pub fn spawn_wheels(
wheel_poses.push((offset, None));
}
let (mesh, collider) = gen_tire(conf);
// tires
let outer_radius = conf.radius;
let inner_radius = conf.radius - conf.thickness;
let mesh = Mesh::from(Torus::new(inner_radius, outer_radius))
.rotated_by(Quat::from_rotation_z(FRAC_PI_2));
let collider = Collider::convex_hull_from_mesh(&mesh).unwrap();
for (offset, steering) in wheel_poses {
let hub = wheels_helper(
commands,
@ -46,43 +52,21 @@ pub fn spawn_wheels(
conf,
);
let fork = commands
.spawn(FixedJoint::new(hub, bike).with_local_anchor_2(offset))
.id();
if let Some(steering) = steering {
let axis = CyberFork(rake_vec);
commands.entity(fork).insert((steering, axis));
commands.entity(hub).insert(steering);
commands.spawn((
RevoluteJoint::new(bike, hub)
.with_aligned_axis(rake_vec)
.with_angle_limits(-0.01, 0.01)
.with_local_anchor_2(Vec3::new(0.0, 0.08, -0.05))
.with_local_anchor_1(offset),
steering,
));
} else {
commands.spawn(FixedJoint::new(bike, hub).with_local_anchor_1(offset));
}
}
}
fn gen_tire(conf: &WheelConfig) -> (Mesh, Collider) {
let outer_radius = conf.radius;
let inner_radius = conf.radius - conf.thickness;
let mut tire_mesh: Mesh = Torus::new(inner_radius, outer_radius).into();
let tire_verts = tire_mesh
.attribute(Mesh::ATTRIBUTE_POSITION)
.unwrap()
.as_float3()
.unwrap()
.iter()
.map(|v| {
//
let v = Vec3::from_array(*v);
let m = Mat3::from_rotation_z(90.0f32.to_radians());
let p = m.mul_vec3(v);
p.to_array()
})
.collect::<Vec<[f32; 3]>>();
tire_mesh.remove_attribute(Mesh::ATTRIBUTE_POSITION);
tire_mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, tire_verts);
let collider = Collider::convex_hull_from_mesh(&tire_mesh).unwrap();
(tire_mesh, collider)
}
fn wheels_helper(
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,

View file

@ -140,8 +140,11 @@ fn common(app: &mut bevy::prelude::App) {
app.insert_resource(DebugCamOffset::default())
.add_systems(Startup, setup_cybercams)
.init_state::<CyberCameras>()
.add_systems(Update, (cycle_cam_state, update_active_camera))
.add_systems(
Update,
(cycle_cam_state, update_active_camera, follow_cyberbike),
PostUpdate,
follow_cyberbike
.after(avian3d::schedule::PhysicsSet::Sync)
.before(TransformSystem::TransformPropagate),
);
}

View file

@ -67,7 +67,7 @@ fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputS
istate.brake = false;
}
}
_ => info!("unhandled button press: {button_event:?}"),
_ => {}
}
}
GamepadEvent::Axis(axis_event) => {
@ -81,7 +81,7 @@ fn update_input(mut events: EventReader<GamepadEvent>, mut istate: ResMut<InputS
GamepadAxisType::RightStickY => {
istate.pitch = *value;
}
_ => info!("unhandled axis event: {axis_event:?}"),
_ => {}
}
}
GamepadEvent::Connection(_) => {}

View file

@ -1,12 +1,14 @@
use avian3d::prelude::*;
use bevy::{
prelude::*,
render::{mesh::Indices, render_asset::RenderAssetUsages},
render::{
mesh::{Indices, PrimitiveTopology},
render_asset::RenderAssetUsages,
},
};
use hexasphere::shapes::IcoSphere;
use noise::{HybridMulti, NoiseFn, SuperSimplex};
use rand::{Rng, SeedableRng};
use wgpu::PrimitiveTopology;
pub const PLANET_RADIUS: f32 = 4_000.0;
pub const PLANET_HUE: f32 = 31.0;