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7KOYBWTVBO7KWWMTG4KAC
HYJ4HJQVLLDTE6JYKEYQK2LBWREOQUATESGB3QP7WDJB3IMVS6OAC
HYU2P2RSYVVYNDSFXTOYCDOQHGHQGIMY6SFKT3SQDOTMOUNQFNFQC
EV477LPQ57FEHMFO6E3LL5MFWZC6NTGER42SKP5CJN73SWXGB5AQC
fn handle_collisions(
mut movable: Query<(&mut Movable, &mut Transform)>,
mut reader: EventReader<collision::CollisionEvent>,
) {
for event in reader.read() {
if let Some([adata, bdata]) = movable.get_many_mut([event.object_a, event.object_b]).ok() {
let (am, mut at) = adata;
let (bm, mut bt) = bdata;
let ima = am.mass.recip();
let imb = bm.mass.recip();
let im = ima + imb;
if ima.is_infinite() || imb.is_infinite() {
continue;
}
at.translation -= event.mtv.extend(0.) * (ima / im);
bt.translation += event.mtv.extend(0.) * (imb / im);
} else if let Some(adata) = movable.get_mut(event.object_a).ok() {
let (_am, mut at) = adata;
at.translation += event.mtv.extend(0.);
} else if let Some(bdata) = movable.get_mut(event.object_b).ok() {
let (_bm, mut bt) = bdata;
bt.translation += event.mtv.extend(0.);
} else {
// Nothing is movable of these events, do nothing
}
}
}
fn debug_log_collisions(mut reader: EventReader<CollisionEvent>) {
for event in reader.read() {
trace!(?event, "Collision Event!");
}
}
// fn debug_log_collisions(mut reader: EventReader<CollisionEvent>) {
// for event in reader.read() {
// trace!(?event, "Collision Event!");
// }
// }
while let Some(
[(entity, gtransform, collidable, movable), (oentity, ogtransform, ocollidable, omovable)],
) = iter.fetch_next()
while let Some([(entity, gtransform, collidable), (oentity, ogtransform, ocollidable)]) =
iter.fetch_next()
const IMPULSE: f32 = 21_000.0;
const STATIC_IMPULSE: f32 = 300.0;
// TODO This does not handle rotation, cuz we assume we can't do that.
match (movable, omovable) {
// If both are static, continue w/o emitting an event
(None, None) => continue,
(None, Some(mut omovable)) => {
// Move collidable entity
// otransform.translation += mtv;
let mass = omovable.mass.max(1.0);
let speed = omovable.velocity.length();
omovable.acceleration +=
mtv * mass.recip() * STATIC_IMPULSE * speed * time.delta_seconds();
}
(Some(mut movable), None) => {
// Ditto but ocollidable
let mass = movable.mass.max(1.0);
let speed = movable.velocity.length();
movable.acceleration +=
mtv * mass.recip() * STATIC_IMPULSE * speed * time.delta_seconds();
}
(Some(mut movable), Some(mut omovable)) => {
// Split the difference
// TODO Implement mass, so that we can scale this
let mass = movable.mass.max(1.0);
let omass = omovable.mass.max(1.0);
let tmass = mass + omass;
movable.acceleration +=
mtv * -IMPULSE * (mass / tmass).recip() * time.delta_seconds();
omovable.acceleration +=
mtv * IMPULSE * (omass / tmass).recip() * time.delta_seconds();
}
}
]
[[package]]
name = "jni"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec"
dependencies = [
"cesu8",
"combine",
"jni-sys",
"log",
"thiserror",
"walkdir",
]
[[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",
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0"
dependencies = [
"bitflags 1.3.2",
"jni-sys",
"ndk-sys 0.4.1+23.1.7779620",
"num_enum 0.5.11",
"raw-window-handle 0.5.2",
"thiserror",
]
[[package]]
name = "ndk"
version = "0.5.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799"
dependencies = [
"proc-macro-crate 1.3.1",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "num_enum_derive"
version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
name = "toml_edit"
"windows-core",
"windows-core 0.52.0",
"windows-targets 0.52.4",
]
[[package]]
name = "windows"
version = "0.54.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9252e5725dbed82865af151df558e754e4a3c2c30818359eb17465f1346a1b49"
dependencies = [
"windows-core 0.54.0",