Compare commits

..

2 Commits

Author SHA1 Message Date
1881ee2b16 dynamic objects 2023-11-22 04:37:55 -08:00
c239bbefba update deps 2023-11-18 16:14:40 -08:00
14 changed files with 835 additions and 1709 deletions

159
Cargo.lock generated
View File

@@ -4,9 +4,9 @@ version = 3
[[package]]
name = "ab_glyph"
version = "0.2.22"
version = "0.2.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1061f3ff92c2f65800df1f12fc7b4ff44ee14783104187dd04dfee6f11b0fd2"
checksum = "80179d7dd5d7e8c285d67c4a1e652972a92de7475beddfb92028c76463b13225"
dependencies = [
"ab_glyph_rasterizer",
"owned_ttf_parser",
@@ -245,7 +245,7 @@ checksum = "965ab7eb5f8f97d2a083c799f3a1b994fc397b2fe2da5d1da1626ce15a39f2b1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -351,9 +351,9 @@ dependencies = [
[[package]]
name = "configparser"
version = "3.0.2"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5458d9d1a587efaf5091602c59d299696a3877a439c8f6d461a2d3cce11df87a"
checksum = "e0e56e414a2a52ab2a104f85cd40933c2fbc278b83637facf646ecf451b49237"
[[package]]
name = "constant_time_eq"
@@ -412,9 +412,9 @@ dependencies = [
[[package]]
name = "cursor-icon"
version = "1.0.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "740bb192a8e2d1350119916954f4409ee7f62f149b536911eeb78ba5a20526bf"
checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
[[package]]
name = "d3d12"
@@ -479,9 +479,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.5"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3e13f66a2f95e32a39eaa81f6b95d42878ca0e1db0c7543723dfe12557e860"
checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8"
dependencies = [
"libc",
"windows-sys 0.48.0",
@@ -517,7 +517,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -550,9 +550,9 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.10"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"js-sys",
@@ -702,9 +702,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.0.2"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
@@ -743,9 +743,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.64"
version = "0.3.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
checksum = "54c0c35952f67de54bb584e9fd912b3023117cbafc0a77d8f3dee1fb5f572fe8"
dependencies = [
"wasm-bindgen",
]
@@ -769,9 +769,9 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "lazy-regex"
version = "3.0.2"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e723bd417b2df60a0f6a2b6825f297ea04b245d4ba52b5a22cb679bdf58b05fa"
checksum = "5d12be4595afdf58bd19e4a9f4e24187da2a66700786ff660a418e9059937a4c"
dependencies = [
"lazy-regex-proc_macros",
"once_cell",
@@ -780,14 +780,14 @@ dependencies = [
[[package]]
name = "lazy-regex-proc_macros"
version = "3.0.1"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f"
checksum = "44bcd58e6c97a7fcbaffcdc95728b393b8d98933bfadad49ed4097845b57ef0b"
dependencies = [
"proc-macro2",
"quote",
"regex",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -798,9 +798,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.149"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "libloading"
@@ -823,10 +823,21 @@ dependencies = [
]
[[package]]
name = "linux-raw-sys"
version = "0.4.10"
name = "libredox"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f"
checksum = "3af92c55d7d839293953fcd0fda5ecfe93297cfde6ffbdec13b41d99c0ba6607"
dependencies = [
"bitflags 2.4.1",
"libc",
"redox_syscall 0.4.1",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829"
[[package]]
name = "lock_api"
@@ -929,9 +940,9 @@ dependencies = [
[[package]]
name = "naga"
version = "0.14.0"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61d829abac9f5230a85d8cc83ec0879b4c09790208ae25b5ea031ef84562e071"
checksum = "6cd05939c491da968a42986204b7431678be21fdcd4b10cc84997ba130ada5a4"
dependencies = [
"bit-set",
"bitflags 2.4.1",
@@ -1036,7 +1047,7 @@ dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -1103,18 +1114,18 @@ checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "orbclient"
version = "0.3.46"
version = "0.3.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8378ac0dfbd4e7895f2d2c1f1345cab3836910baf3a300b000d04250f0c8428f"
checksum = "52f0d54bde9774d3a51dcf281a5def240c71996bc6ca05d2c847ec8b2b216166"
dependencies = [
"redox_syscall 0.3.5",
"libredox",
]
[[package]]
name = "owned_ttf_parser"
version = "0.19.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4"
checksum = "d4586edfe4c648c71797a74c84bacb32b52b212eff5dfe2bb9f2c599844023e7"
dependencies = [
"ttf-parser",
]
@@ -1232,7 +1243,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb156a45b6b9fe8027497422179fb65afc84d36707a7ca98297bf06bccb8d43f"
dependencies = [
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -1467,9 +1478,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustix"
version = "0.38.21"
version = "0.38.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234"
dependencies = [
"bitflags 2.4.1",
"errno",
@@ -1514,22 +1525,22 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.190"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.190"
version = "1.0.192"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -1552,9 +1563,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.11.1"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "smithay-client-toolkit"
@@ -1654,9 +1665,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.38"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
@@ -1665,9 +1676,9 @@ dependencies = [
[[package]]
name = "termcolor"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64"
checksum = "ff1bc3d3f05aff0403e8ac0d92ced918ec05b666a43f83297ccef5bea8a3d449"
dependencies = [
"winapi-util",
]
@@ -1689,7 +1700,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]
[[package]]
@@ -1752,9 +1763,9 @@ checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
[[package]]
name = "ttf-parser"
version = "0.19.2"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49d64318d8311fc2668e48b63969f4343e0a85c4a109aa8460d6672e364b8bd1"
checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4"
[[package]]
name = "unicode-ident"
@@ -1804,9 +1815,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
checksum = "7daec296f25a1bae309c0cd5c29c4b260e510e6d813c286b19eaadf409d40fce"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -1814,24 +1825,24 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
checksum = "e397f4664c0e4e428e8313a469aaa58310d302159845980fd23b0f22a847f217"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.37"
version = "0.4.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c02dbc21516f9f1f04f187958890d7e6026df8d16540b7ad9492bc34a67cea03"
checksum = "9afec9963e3d0994cac82455b2b3502b81a7f40f9a0d32181f7528d9f4b43e02"
dependencies = [
"cfg-if",
"js-sys",
@@ -1841,9 +1852,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
checksum = "5961017b3b08ad5f3fe39f1e79877f8ee7c23c5e5fd5eb80de95abc41f1f16b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1851,22 +1862,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
checksum = "c5353b8dab669f5e10f5bd76df26a9360c748f054f862ff5f3f8aae0c7fb3907"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.87"
version = "0.2.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
checksum = "0d046c5d029ba91a1ed14da14dca44b68bf2f124cfbaf741c54151fdb3e0750b"
[[package]]
name = "wayland-backend"
@@ -2024,9 +2035,9 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "0.18.0"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "837e02ddcdc6d4a9b56ba4598f7fd4202a7699ab03f6ef4dcdebfad2c966aea6"
checksum = "ef91c1d62d1e9e81c79e600131a258edf75c9531cbdbde09c44a011a47312726"
dependencies = [
"arrayvec",
"bit-vec",
@@ -2347,9 +2358,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.5.17"
version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c"
checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b"
dependencies = [
"memchr",
]
@@ -2427,20 +2438,20 @@ checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a"
[[package]]
name = "zerocopy"
version = "0.7.18"
version = "0.7.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7d7c7970ca2215b8c1ccf4d4f354c4733201dfaaba72d44ae5b37472e4901"
checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.18"
version = "0.7.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b27b1bb92570f989aac0ab7e9cbfbacdd65973f7ee920d9f0e71ebac878fd0b"
checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.38",
"syn 2.0.39",
]

View File

@@ -1,5 +1,14 @@
use crate::integer::Planar64Vec3;
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub enum AabbFace{
Right,//+X
Top,
Back,
Left,
Bottom,
Front,
}
#[derive(Clone)]
pub struct Aabb{
pub min:Planar64Vec3,
@@ -13,6 +22,17 @@ impl Default for Aabb {
}
impl Aabb{
const VERTEX_DATA:[Planar64Vec3;8]=[
Planar64Vec3::int( 1,-1,-1),
Planar64Vec3::int( 1, 1,-1),
Planar64Vec3::int( 1, 1, 1),
Planar64Vec3::int( 1,-1, 1),
Planar64Vec3::int(-1,-1, 1),
Planar64Vec3::int(-1, 1, 1),
Planar64Vec3::int(-1, 1,-1),
Planar64Vec3::int(-1,-1,-1),
];
pub fn grow(&mut self,point:Planar64Vec3){
self.min=self.min.min(point);
self.max=self.max.max(point);
@@ -28,6 +48,32 @@ impl Aabb{
pub fn intersects(&self,aabb:&Aabb)->bool{
(self.min.cmplt(aabb.max)&aabb.min.cmplt(self.max)).all()
}
pub fn normal(face:AabbFace)->Planar64Vec3{
match face {
AabbFace::Right=>Planar64Vec3::int(1,0,0),
AabbFace::Top=>Planar64Vec3::int(0,1,0),
AabbFace::Back=>Planar64Vec3::int(0,0,1),
AabbFace::Left=>Planar64Vec3::int(-1,0,0),
AabbFace::Bottom=>Planar64Vec3::int(0,-1,0),
AabbFace::Front=>Planar64Vec3::int(0,0,-1),
}
}
pub fn unit_vertices()->[Planar64Vec3;8] {
return Self::VERTEX_DATA;
}
// pub fn face(&self,face:AabbFace)->Aabb {
// let mut aabb=self.clone();
// //in this implementation face = worldspace aabb face
// match face {
// AabbFace::Right => aabb.min.x=aabb.max.x,
// AabbFace::Top => aabb.min.y=aabb.max.y,
// AabbFace::Back => aabb.min.z=aabb.max.z,
// AabbFace::Left => aabb.max.x=aabb.min.x,
// AabbFace::Bottom => aabb.max.y=aabb.min.y,
// AabbFace::Front => aabb.max.z=aabb.min.z,
// }
// return aabb;
// }
pub fn center(&self)->Planar64Vec3{
return self.min.midpoint(self.max)
}

View File

@@ -1,126 +0,0 @@
use crate::physics::Body;
use crate::model_physics::{FEV,MeshQuery};
use crate::integer::{Time,Planar64,Planar64Vec3};
use crate::zeroes::zeroes2;
struct State<FEV>{
fev:FEV,
time:Time,
}
enum Transition<F,E,V>{
Miss,
Next(FEV<F,E,V>,Time),
Hit(F,Time),
}
impl<F:Copy,E:Copy,V:Copy> State<FEV<F,E,V>>{
fn next_transition(&self,mesh:&impl MeshQuery<F,E,V>,body:&Body,time_limit:Time)->Transition<F,E,V>{
//conflicting derivative means it crosses in the wrong direction.
//if the transition time is equal to an already tested transition, do not replace the current best.
let mut best_time=time_limit;
let mut best_transtition=Transition::Miss;
match &self.fev{
&FEV::<F,E,V>::Face(face_id)=>{
//test own face collision time, ignoring roots with zero or conflicting derivative
//n=face.normal d=face.dot
//n.a t^2+n.v t+n.p-d==0
let (n,d)=mesh.face_nd(face_id);
for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+Time::from(t);
if self.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
best_time=t;
best_transtition=Transition::Hit(face_id,t);
}
}
//test each edge collision time, ignoring roots with zero or conflicting derivative
for &(edge_id,test_face_id) in mesh.face_edges(face_id).iter(){
let edge_n=mesh.edge_n(edge_id);
let n=n.cross(edge_n);
//picking a vert randomly is terrible
let d=n.dot(mesh.vert(mesh.edge_verts(edge_id)[0]));
for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+Time::from(t);
if self.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
best_time=t;
best_transtition=Transition::Next(FEV::<F,E,V>::Edge(edge_id),t);
break;
}
}
}
//if none:
},
&FEV::<F,E,V>::Edge(edge_id)=>{
//test each face collision time, ignoring roots with zero or conflicting derivative
let edge_n=mesh.edge_n(edge_id);
for &test_face_id in mesh.edge_faces(edge_id).iter(){
let face_n=mesh.face_nd(test_face_id).0;
let n=edge_n.cross(face_n);
let d=n.dot(mesh.vert(mesh.edge_verts(edge_id)[0]));
for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+Time::from(t);
if self.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
best_time=t;
best_transtition=Transition::Next(FEV::<F,E,V>::Face(test_face_id),t);
break;
}
}
}
//test each vertex collision time, ignoring roots with zero or conflicting derivative
let n=mesh.edge_n(edge_id);
for &vert_id in mesh.edge_verts(edge_id).iter(){
let d=n.dot(mesh.vert(vert_id));
for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+Time::from(t);
if self.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
best_time=t;
best_transtition=Transition::Next(FEV::<F,E,V>::Vert(vert_id),t);
break;
}
}
}
//if none:
},
&FEV::<F,E,V>::Vert(vert_id)=>{
//test each edge collision time, ignoring roots with zero or conflicting derivative
for &edge_id in mesh.vert_edges(vert_id).iter(){
let n=mesh.edge_n(edge_id);
let d=n.dot(mesh.vert(vert_id));
for t in zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+Time::from(t);
if self.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
best_time=t;
best_transtition=Transition::Next(FEV::<F,E,V>::Edge(edge_id),t);
break;
}
}
}
//if none:
},
}
best_transtition
}
}
pub fn predict_collision<F:Copy,E:Copy,V:Copy>(mesh:&impl MeshQuery<F,E,V>,relative_body:&Body,time_limit:Time)->Option<(F,Time)>{
let mut state=State{
fev:mesh.closest_fev(relative_body.position),
time:relative_body.time,
};
//it would be possible to write down the point of closest approach...
loop{
match state.next_transition(mesh,relative_body,time_limit){
Transition::Miss=>return None,
Transition::Next(fev,time)=>(state.fev,state.time)=(fev,time),
Transition::Hit(face,time)=>return Some((face,time)),
}
}
}
pub fn predict_collision_end<F:Copy,E:Copy,V:Copy>(mesh:&impl MeshQuery<F,E,V>,relative_body:&Body,time_limit:Time,ignore_face_id:F)->Option<(F,Time)>{
//imagine the mesh without the collision face
//no algorithm needed, there is only one state and three cases (Face,Edge,None)
//determine when it passes an edge ("sliding off" case) or if it leaves the surface directly
//the state can be constructed from the ContactCollision directly
None
}

View File

@@ -25,10 +25,7 @@ impl<I> InstructionCollector<I>{
instruction:None
}
}
#[inline]
pub fn time(&self)->Time{
self.time
}
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
match instruction{
Some(unwrap_instruction)=>{

View File

@@ -1,5 +1,5 @@
//integer units
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
#[derive(Clone,Copy,Hash,PartialEq,PartialOrd,Debug)]
pub struct Time(i64);
impl Time{
pub const ZERO:Self=Self(0);
@@ -414,7 +414,6 @@ pub struct Planar64(i64);
impl Planar64{
pub const ZERO:Self=Self(0);
pub const ONE:Self=Self(1<<32);
pub const MAX:Self=Self(i64::MAX);
#[inline]
pub const fn int(num:i32)->Self{
Self(Self::ONE.0*num as i64)
@@ -427,14 +426,9 @@ impl Planar64{
pub const fn get(&self)->i64{
self.0
}
#[inline]
pub fn sqrt(&self)->Self{
Planar64(unsafe{(((self.0 as i128)<<32) as f64).sqrt().to_int_unchecked()})
}
#[inline]
pub const fn signum_i64(&self)->i64{
((self.0&(1<<63)!=0) as i64)*2-1
}
}
const PLANAR64_ONE_FLOAT32:f32=(1u64<<32) as f32;
const PLANAR64_CONVERT_TO_FLOAT32:f32=1.0/PLANAR64_ONE_FLOAT32;
@@ -524,12 +518,6 @@ impl std::ops::Add<Planar64> for Planar64{
Planar64(self.0+rhs.0)
}
}
impl std::ops::AddAssign<Planar64> for Planar64{
#[inline]
fn add_assign(&mut self,rhs:Self){
*self=*self+rhs;
}
}
impl std::ops::Sub<Planar64> for Planar64{
type Output=Planar64;
#[inline]
@@ -594,10 +582,6 @@ impl Planar64Vec3{
pub const MIN:Self=Planar64Vec3(glam::I64Vec3::MIN);
pub const MAX:Self=Planar64Vec3(glam::I64Vec3::MAX);
#[inline]
pub const fn new(x:Planar64,y:Planar64,z:Planar64)->Self{
Self(glam::i64vec3(x.0,y.0,z.0))
}
#[inline]
pub const fn int(x:i32,y:i32,z:i32)->Self{
Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32))
}
@@ -650,26 +634,6 @@ impl Planar64Vec3{
)>>32) as i64)
}
#[inline]
pub fn dot128(&self,rhs:Self)->i128{
(self.0.x as i128)*(rhs.0.x as i128)+
(self.0.y as i128)*(rhs.0.y as i128)+
(self.0.z as i128)*(rhs.0.z as i128)
}
#[inline]
pub fn cross(&self,rhs:Self)->Planar64Vec3{
Planar64Vec3(glam::i64vec3(
(((self.0.y as i128)*(rhs.0.z as i128)-(self.0.z as i128)*(rhs.0.y as i128))>>32) as i64,
(((self.0.z as i128)*(rhs.0.x as i128)-(self.0.x as i128)*(rhs.0.z as i128))>>32) as i64,
(((self.0.x as i128)*(rhs.0.y as i128)-(self.0.y as i128)*(rhs.0.x as i128))>>32) as i64,
))
}
#[inline]
pub fn walkable(&self,slope:Planar64,up:Self)->bool{
let y=self.dot(up);
let x=self.cross(up).length();
x*slope<y
}
#[inline]
pub fn length(&self)->Planar64{
let radicand=(self.0.x as i128)*(self.0.x as i128)+(self.0.y as i128)*(self.0.y as i128)+(self.0.z as i128)*(self.0.z as i128);
Planar64(unsafe{(radicand as f64).sqrt().to_int_unchecked()})
@@ -817,7 +781,7 @@ impl std::ops::Div<i64> for Planar64Vec3{
}
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
#[derive(Clone,Copy)]
pub struct Planar64Mat3{
x_axis:Planar64Vec3,
y_axis:Planar64Vec3,
@@ -889,41 +853,6 @@ impl Planar64Mat3{
Planar64Vec3(glam::i64vec3(s,0,c)),
)
}
#[inline]
pub const fn inverse(&self)->Self{
let det=(
-self.x_axis.0.z as i128*self.y_axis.0.y as i128*self.z_axis.0.x as i128
+self.x_axis.0.y as i128*self.y_axis.0.z as i128*self.z_axis.0.x as i128
+self.x_axis.0.z as i128*self.y_axis.0.x as i128*self.z_axis.0.y as i128
-self.x_axis.0.x as i128*self.y_axis.0.z as i128*self.z_axis.0.y as i128
-self.x_axis.0.y as i128*self.y_axis.0.x as i128*self.z_axis.0.z as i128
+self.x_axis.0.x as i128*self.y_axis.0.y as i128*self.z_axis.0.z as i128
)>>32;
Self{
x_axis:Planar64Vec3::raw((((-(self.y_axis.0.z as i128*self.z_axis.0.y as i128)+self.y_axis.0.y as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((self.x_axis.0.z as i128*self.z_axis.0.y as i128-self.x_axis.0.y as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((-(self.x_axis.0.z as i128*self.y_axis.0.y as i128)+self.x_axis.0.y as i128*self.y_axis.0.z as i128)<<32)/det) as i64),
y_axis:Planar64Vec3::raw((((self.y_axis.0.z as i128*self.z_axis.0.x as i128-self.y_axis.0.x as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((-(self.x_axis.0.z as i128*self.z_axis.0.x as i128)+self.x_axis.0.x as i128*self.z_axis.0.z as i128)<<32)/det) as i64,(((self.x_axis.0.z as i128*self.y_axis.0.x as i128-self.x_axis.0.x as i128*self.y_axis.0.z as i128)<<32)/det) as i64),
z_axis:Planar64Vec3::raw((((-(self.y_axis.0.y as i128*self.z_axis.0.x as i128)+self.y_axis.0.x as i128*self.z_axis.0.y as i128)<<32)/det) as i64,(((self.x_axis.0.y as i128*self.z_axis.0.x as i128-self.x_axis.0.x as i128*self.z_axis.0.y as i128)<<32)/det) as i64,(((-(self.x_axis.0.y as i128*self.y_axis.0.x as i128)+self.x_axis.0.x as i128*self.y_axis.0.y as i128)<<32)/det) as i64),
}
}
#[inline]
pub const fn transpose(&self)->Self{
Self{
x_axis:Planar64Vec3::raw(self.x_axis.0.x,self.y_axis.0.x,self.z_axis.0.x),
y_axis:Planar64Vec3::raw(self.x_axis.0.y,self.y_axis.0.y,self.z_axis.0.y),
z_axis:Planar64Vec3::raw(self.x_axis.0.z,self.y_axis.0.z,self.z_axis.0.z),
}
}
#[inline]
pub const fn determinant(&self)->Planar64{
Planar64(((
-self.x_axis.0.z as i128*self.y_axis.0.y as i128*self.z_axis.0.x as i128
+self.x_axis.0.y as i128*self.y_axis.0.z as i128*self.z_axis.0.x as i128
+self.x_axis.0.z as i128*self.y_axis.0.x as i128*self.z_axis.0.y as i128
-self.x_axis.0.x as i128*self.y_axis.0.z as i128*self.z_axis.0.y as i128
-self.x_axis.0.y as i128*self.y_axis.0.x as i128*self.z_axis.0.z as i128
+self.x_axis.0.x as i128*self.y_axis.0.y as i128*self.z_axis.0.z as i128
)>>64) as i64)
}
}
impl Into<glam::Mat3> for Planar64Mat3{
#[inline]
@@ -968,7 +897,7 @@ impl std::ops::Div<i64> for Planar64Mat3{
}
///[-1.0,1.0] = [-2^32,2^32]
#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)]
#[derive(Clone,Copy,Default)]
pub struct Planar64Affine3{
pub matrix3:Planar64Mat3,//includes scale above 1
pub translation:Planar64Vec3,

View File

@@ -45,19 +45,14 @@ fn get_attributes(name:&str,can_collide:bool,velocity:Planar64Vec3,force_interse
"Water"=>{
force_can_collide=false;
//TODO: read stupid CustomPhysicalProperties
intersecting.water=Some(crate::model::IntersectingWater{density:Planar64::ONE,viscosity:Planar64::ONE/10,velocity});
intersecting.water=Some(crate::model::IntersectingWater{density:Planar64::ONE,viscosity:Planar64::ONE/10,current:velocity});
},
"Accelerator"=>{
//although the new game supports collidable accelerators, this is a roblox compatability map loader
force_can_collide=false;
general.accelerator=Some(crate::model::GameMechanicAccelerator{acceleration:velocity});
},
// "UnorderedCheckpoint"=>general.teleport_behaviour=Some(crate::model::TeleportBehaviour::StageElement(crate::model::GameMechanicStageElement{
// mode_id:0,
// stage_id:0,
// force:false,
// behaviour:crate::model::StageElementBehaviour::Unordered
// })),
"UnorderedCheckpoint"=>general.checkpoint=Some(crate::model::GameMechanicCheckpoint::Unordered{mode_id:0}),
"SetVelocity"=>general.trajectory=Some(crate::model::GameMechanicSetTrajectory::Velocity(velocity)),
"MapFinish"=>{force_can_collide=false;general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Finish})},
"MapAnticheat"=>{force_can_collide=false;general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Anitcheat})},
@@ -116,14 +111,13 @@ fn get_attributes(name:&str,can_collide:bool,velocity:Planar64Vec3,force_interse
"WormholeIn"=>general.teleport_behaviour=Some(crate::model::TeleportBehaviour::Wormhole(crate::model::GameMechanicWormhole{destination_model_id:captures[2].parse::<u32>().unwrap()})),
_=>panic!("regex3[1] messed up bad"),
}
}else if let Some(captures)=lazy_regex::regex!(r"^(OrderedCheckpoint)(\d+)$")
.captures(other){
match &captures[1]{
"OrderedCheckpoint"=>general.checkpoint=Some(crate::model::GameMechanicCheckpoint::Ordered{mode_id:0,checkpoint_id:captures[2].parse::<u32>().unwrap()}),
_=>panic!("regex3[1] messed up bad"),
}
}
// else if let Some(captures)=lazy_regex::regex!(r"^(OrderedCheckpoint)(\d+)$")
// .captures(other){
// match &captures[1]{
// "OrderedCheckpoint"=>general.checkpoint=Some(crate::model::GameMechanicCheckpoint::Ordered{mode_id:0,checkpoint_id:captures[2].parse::<u32>().unwrap()}),
// _=>panic!("regex3[1] messed up bad"),
// }
// }
}
}
//need some way to skip this

View File

@@ -2,6 +2,7 @@ mod bvh;
mod aabb;
mod model;
mod setup;
mod world;
mod window;
mod worker;
mod zeroes;
@@ -12,9 +13,7 @@ mod settings;
mod primitives;
mod instruction;
mod load_roblox;
mod face_crawler;
mod compat_worker;
mod model_physics;
mod model_graphics;
mod physics_worker;
mod graphics_worker;

View File

@@ -83,78 +83,73 @@ pub enum TempIndexedAttributes{
}
//you have this effect while in contact
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct ContactingLadder{
pub sticky:bool
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum ContactingBehaviour{
Surf,
Cling,//usable as a zipline, or other weird and wonderful things
Ladder(ContactingLadder),
Elastic(u32),//[1/2^32,1] 0=None (elasticity+1)/2^32
Surf,
Ladder(ContactingLadder),
Elastic(u32),//[1/2^32,1] 0=None (elasticity+1)/2^32
}
//you have this effect while intersecting
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct IntersectingWater{
pub viscosity:Planar64,
pub density:Planar64,
pub velocity:Planar64Vec3,
pub current:Planar64Vec3,
}
//All models can be given these attributes
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct GameMechanicAccelerator{
pub acceleration:Planar64Vec3
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum GameMechanicBooster{
Affine(Planar64Affine3),//capable of SetVelocity,DotVelocity,normal booster,bouncy part,redirect velocity, and much more
Velocity(Planar64Vec3),//straight up boost velocity adds to your current velocity
Energy{direction:Planar64Vec3,energy:Planar64},//increase energy in direction
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum GameMechanicCheckpoint{
Ordered{
mode_id:u32,
checkpoint_id:u32,
},
Unordered{
mode_id:u32,
},
}
#[derive(Clone)]
pub enum TrajectoryChoice{
HighArcLongDuration,//underhand lob at target: less horizontal speed and more air time
LowArcShortDuration,//overhand throw at target: more horizontal speed and less air time
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum GameMechanicSetTrajectory{
//Speed-type SetTrajectory
AirTime(Time),//air time (relative to gravity direction) is invariant across mass and gravity changes
Height(Planar64),//boost height (relative to gravity direction) is invariant across mass and gravity changes
DotVelocity{direction:Planar64Vec3,dot:Planar64},//set your velocity in a specific direction without touching other directions
//Velocity-type SetTrajectory
TargetPointTime{//launch on a trajectory that will land at a target point in a set amount of time
target_point:Planar64Vec3,
time:Time,//short time = fast and direct, long time = launch high in the air, negative time = wrong way
},
TargetPointSpeed{//launch at a fixed speed and land at a target point
TrajectoryTargetPoint{//launch at a fixed speed and land at a target point
target_point:Planar64Vec3,
speed:Planar64,//if speed is too low this will fail to reach the target. The closest-passing trajectory will be chosen instead
trajectory_choice:TrajectoryChoice,
},
Velocity(Planar64Vec3),//SetVelocity
DotVelocity{direction:Planar64Vec3,dot:Planar64},//set your velocity in a specific direction without touching other directions
}
impl GameMechanicSetTrajectory{
fn is_velocity(&self)->bool{
match self{
GameMechanicSetTrajectory::AirTime(_)
|GameMechanicSetTrajectory::Height(_)
|GameMechanicSetTrajectory::DotVelocity{direction:_,dot:_}=>false,
GameMechanicSetTrajectory::TargetPointTime{target_point:_,time:_}
|GameMechanicSetTrajectory::TargetPointSpeed{target_point:_,speed:_,trajectory_choice:_}
|GameMechanicSetTrajectory::Velocity(_)=>true,
}
}
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum ZoneBehaviour{
//Start is indexed
//Checkpoints are indexed
Finish,
Anitcheat,
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct GameMechanicZone{
pub mode_id:u32,
pub behaviour:ZoneBehaviour,
@@ -165,36 +160,31 @@ pub struct GameMechanicZone{
// InRange(Planar64,Planar64),
// OutsideRange(Planar64,Planar64),
// }
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum StageElementBehaviour{
//Spawn,//The behaviour of stepping on a spawn setting the spawnid
SpawnAt,//must be standing on top to get effect. except cancollide false
Trigger,
Teleport,
Platform,
//Checkpoint acts like a trigger if you haven't hit all the checkpoints yet.
//Note that all stage elements act like this for the next stage.
Checkpoint,
//OrderedCheckpoint. You must pass through all of these in ascending order.
//If you hit them out of order it acts like a trigger.
//Do not support backtracking at all for now.
Ordered{
checkpoint_id:u32,
},
//UnorderedCheckpoint. You must pass through all of these in any order.
Unordered,
//If you get reset by a jump limit
JumpLimit(u32),
//Speedtrap(TrapCondition),//Acts as a trigger with a speed condition
//Spawn,//The behaviour of stepping on a spawn setting the spawnid
SpawnAt,
Trigger,
Teleport,
Platform,
//Acts like a trigger if you haven't hit all the checkpoints.
Checkpoint{
//if this is 2 you must have hit OrderedCheckpoint(0) OrderedCheckpoint(1) OrderedCheckpoint(2) to pass
ordered_checkpoint_id:Option<u32>,
//if this is 2 you must have hit at least 2 UnorderedCheckpoints to pass
unordered_checkpoint_count:u32,
},
JumpLimit(u32),
//Speedtrap(TrapCondition),//Acts as a trigger with a speed condition
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct GameMechanicStageElement{
pub mode_id:u32,
pub stage_id:u32,//which spawn to send to
pub force:bool,//allow setting to lower spawn id i.e. 7->3
pub behaviour:StageElementBehaviour
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub struct GameMechanicWormhole{
//destination does not need to be another wormhole
//this defines a one way portal to a destination model transform
@@ -202,16 +192,17 @@ pub struct GameMechanicWormhole{
pub destination_model_id:u32,
//(position,angles)*=origin.transform.inverse()*destination.transform
}
#[derive(Clone,Hash,Eq,PartialEq)]
#[derive(Clone)]
pub enum TeleportBehaviour{
StageElement(GameMechanicStageElement),
Wormhole(GameMechanicWormhole),
}
//attributes listed in order of handling
#[derive(Default,Clone,Hash,Eq,PartialEq)]
#[derive(Default,Clone)]
pub struct GameMechanicAttributes{
pub zone:Option<GameMechanicZone>,
pub booster:Option<GameMechanicBooster>,
pub checkpoint:Option<GameMechanicCheckpoint>,
pub trajectory:Option<GameMechanicSetTrajectory>,
pub teleport_behaviour:Option<TeleportBehaviour>,
pub accelerator:Option<GameMechanicAccelerator>,
@@ -220,26 +211,13 @@ impl GameMechanicAttributes{
pub fn any(&self)->bool{
self.zone.is_some()
||self.booster.is_some()
||self.checkpoint.is_some()
||self.trajectory.is_some()
||self.teleport_behaviour.is_some()
||self.accelerator.is_some()
}
pub fn is_wrcp(&self,current_mode_id:u32)->bool{
self.trajectory.as_ref().map_or(false,|t|t.is_velocity())
&&match &self.teleport_behaviour{
Some(TeleportBehaviour::StageElement(
GameMechanicStageElement{
mode_id,
stage_id:_,
force:true,
behaviour:StageElementBehaviour::Trigger|StageElementBehaviour::Teleport
}
))=>current_mode_id==*mode_id,
_=>false,
}
}
}
#[derive(Default,Clone,Hash,Eq,PartialEq)]
#[derive(Default,Clone)]
pub struct ContactingAttributes{
//friction?
pub contact_behaviour:Option<ContactingBehaviour>,
@@ -249,7 +227,7 @@ impl ContactingAttributes{
self.contact_behaviour.is_some()
}
}
#[derive(Default,Clone,Hash,Eq,PartialEq)]
#[derive(Default,Clone)]
pub struct IntersectingAttributes{
pub water:Option<IntersectingWater>,
}
@@ -259,7 +237,6 @@ impl IntersectingAttributes{
}
}
//Spawn(u32) NO! spawns are indexed in the map header instead of marked with attibutes
//TODO: deduplicate attributes
pub enum CollisionAttributes{
Decoration,//visual only
Contact{//track whether you are contacting the object

View File

@@ -1,766 +1 @@
use crate::integer::{Planar64,Planar64Vec3};
use std::borrow::{Borrow,Cow};
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub struct VertId(usize);
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub struct EdgeId(usize);
impl EdgeId{
fn as_directed_edge_id(&self,parity:bool)->DirectedEdgeId{
DirectedEdgeId(self.0|((parity as usize)<<(usize::BITS-1)))
}
}
/// DirectedEdgeId refers to an EdgeId when undirected.
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub struct DirectedEdgeId(usize);
impl DirectedEdgeId{
fn as_edge_id(&self)->EdgeId{
EdgeId(self.0&!(1<<(usize::BITS-1)))
}
fn signum(&self)->isize{
((self.0&(1<<(usize::BITS-1))!=0) as isize)*2-1
}
}
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub struct FaceId(usize);
//Vertex <-> Edge <-> Face -> Collide
pub enum FEV<F,E,V>{
Face(F),
Edge(E),
Vert(V),
}
//use Unit32 #[repr(C)] for map files
struct Face{
normal:Planar64Vec3,
dot:Planar64,
}
impl Face{
fn nd(&self)->(Planar64Vec3,Planar64){
(self.normal,self.dot)
}
}
struct Vert(Planar64Vec3);
struct FaceRefs{
edges:Vec<(EdgeId,FaceId)>,
//verts:Vec<VertId>,
}
struct EdgeRefs{
faces:[FaceId;2],//left, right
verts:[VertId;2],//bottom, top
}
struct VertRefs{
faces:Vec<FaceId>,
edges:Vec<DirectedEdgeId>,
}
pub struct PhysicsMesh{
faces:Vec<Face>,
verts:Vec<Vert>,
face_topology:Vec<FaceRefs>,
edge_topology:Vec<EdgeRefs>,
vert_topology:Vec<VertRefs>,
}
#[derive(Default,Clone)]
struct VertRefGuy{
edges:std::collections::HashSet<DirectedEdgeId>,
faces:std::collections::HashSet<FaceId>,
}
#[derive(Clone,Hash,Eq,PartialEq)]
struct EdgeIdGuy([VertId;2]);
impl EdgeIdGuy{
fn new(v0:VertId,v1:VertId)->(Self,bool){
(if v0.0<v1.0{
Self([v0,v1])
}else{
Self([v1,v0])
},v0.0<v1.0)
}
}
struct EdgeRefGuy([FaceId;2]);
impl EdgeRefGuy{
fn new()->Self{
Self([FaceId(0);2])
}
fn push(&mut self,i:usize,face_id:FaceId){
self.0[i]=face_id;
}
}
struct FaceRefGuy(Vec<EdgeId>);
#[derive(Default)]
struct EdgePool{
edge_guys:Vec<(EdgeIdGuy,EdgeRefGuy)>,
edge_id_from_guy:std::collections::HashMap<EdgeIdGuy,usize>,
}
impl EdgePool{
fn push(&mut self,edge_id_guy:EdgeIdGuy)->(&mut EdgeRefGuy,EdgeId){
let edge_id=if let Some(&edge_id)=self.edge_id_from_guy.get(&edge_id_guy){
edge_id
}else{
let edge_id=self.edge_guys.len();
self.edge_guys.push((edge_id_guy.clone(),EdgeRefGuy::new()));
self.edge_id_from_guy.insert(edge_id_guy,edge_id);
edge_id
};
(&mut unsafe{self.edge_guys.get_unchecked_mut(edge_id)}.1,EdgeId(edge_id))
}
}
impl From<&crate::model::IndexedModel> for PhysicsMesh{
fn from(indexed_model:&crate::model::IndexedModel)->Self{
let verts=indexed_model.unique_pos.iter().map(|v|Vert(v.clone())).collect();
let mut vert_ref_guys=vec![VertRefGuy::default();indexed_model.unique_pos.len()];
let mut edge_pool=EdgePool::default();
let mut face_i=0;
let mut faces=Vec::new();
let mut face_ref_guys=Vec::new();
for group in indexed_model.groups.iter(){for poly in group.polys.iter(){
let face_id=FaceId(face_i);
//one face per poly
let mut normal=Planar64Vec3::ZERO;
let len=poly.vertices.len();
let face_edges=poly.vertices.iter().enumerate().map(|(i,&vert_id)|{
let vert0_id=indexed_model.unique_vertices[vert_id as usize].pos as usize;
let vert1_id=indexed_model.unique_vertices[poly.vertices[(i+1)%len] as usize].pos as usize;
//https://www.khronos.org/opengl/wiki/Calculating_a_Surface_Normal (Newell's Method)
let v0=indexed_model.unique_pos[vert0_id];
let v1=indexed_model.unique_pos[vert1_id];
normal+=Planar64Vec3::new(
(v0.y()-v1.y())*(v0.z()+v1.z()),
(v0.z()-v1.z())*(v0.x()+v1.x()),
(v0.x()-v1.x())*(v0.y()+v1.y()),
);
//get/create edge and push face into it
let (edge_id_guy,is_sorted)=EdgeIdGuy::new(VertId(vert0_id),VertId(vert1_id));
let (edge_ref_guy,edge_id)=edge_pool.push(edge_id_guy);
//polygon vertices as assumed to be listed clockwise
//populate the edge face on the left or right depending on how the edge vertices got sorted
edge_ref_guy.push(is_sorted as usize,face_id);
//index edges & face into vertices
{
let vert_ref_guy=unsafe{vert_ref_guys.get_unchecked_mut(vert0_id)};
vert_ref_guy.edges.insert(edge_id.as_directed_edge_id(!is_sorted));
vert_ref_guy.faces.insert(face_id);
unsafe{vert_ref_guys.get_unchecked_mut(vert1_id)}.edges.insert(edge_id.as_directed_edge_id(is_sorted));
}
//return edge_id
edge_id
}).collect();
//choose precision loss randomly idk
normal=normal/len as i64;
let mut dot=Planar64::ZERO;
for &v in poly.vertices.iter(){
dot+=normal.dot(indexed_model.unique_pos[indexed_model.unique_vertices[v as usize].pos as usize]);
}
faces.push(Face{normal,dot:dot/len as i64});
face_ref_guys.push(FaceRefGuy(face_edges));
face_i+=1;
}}
//conceivably faces, edges, and vertices exist now
Self{
faces,
verts,
face_topology:face_ref_guys.into_iter().enumerate().map(|(i,face_ref_guy)|{
let face_id=FaceId(i);
FaceRefs{edges:face_ref_guy.0.into_iter().map(|edge_id|{
//get the edge face that's not this face
let edge_faces=&edge_pool.edge_guys[edge_id.0].1.0;
if edge_faces[0]==face_id{
(edge_id,edge_faces[1])
}else if edge_faces[1]==face_id{
(edge_id,edge_faces[0])
}else{
panic!("edge does not contain face edge_faces={:?} face={:?}",edge_faces,face_id)
}
}).collect()}
}).collect(),
edge_topology:edge_pool.edge_guys.into_iter().map(|(edge_id_guy,edge_ref_guy)|
EdgeRefs{faces:edge_ref_guy.0,verts:edge_id_guy.0}
).collect(),
vert_topology:vert_ref_guys.into_iter().map(|vert_ref_guy|
VertRefs{
edges:vert_ref_guy.edges.into_iter().collect(),
faces:vert_ref_guy.faces.into_iter().collect(),
}
).collect(),
}
}
}
pub trait MeshQuery<FACE:Clone,EDGE:Clone,VERT:Clone>{
fn closest_fev(&self,point:Planar64Vec3)->FEV<FACE,EDGE,VERT>;
fn edge_n(&self,edge_id:EDGE)->Planar64Vec3{
let verts=self.edge_verts(edge_id);
self.vert(verts[1].clone())-self.vert(verts[0].clone())
}
fn vert(&self,vert_id:VERT)->Planar64Vec3;
fn face_nd(&self,face_id:FACE)->(Planar64Vec3,Planar64);
fn face_edges(&self,face_id:FACE)->Cow<Vec<(EDGE,FACE)>>;
fn edge_faces(&self,edge_id:EDGE)->Cow<[FACE;2]>;
fn edge_verts(&self,edge_id:EDGE)->Cow<[VERT;2]>;
fn vert_edges(&self,vert_id:VERT)->Cow<Vec<EDGE>>;
fn vert_faces(&self,vert_id:VERT)->Cow<Vec<FACE>>;
}
impl PhysicsMesh{
pub fn verts<'a>(&'a self)->impl Iterator<Item=Planar64Vec3>+'a{
self.verts.iter().map(|Vert(pos)|*pos)
}
pub fn brute(&self,body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(FaceId,crate::integer::Time)>{
//check each face
let mut best_time=time_limit;
let mut best_face=None;
for (i,face) in self.faces.iter().enumerate(){
let face_id=FaceId(i);
let (n,d)=face.nd();
for t in crate::zeroes::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+crate::integer::Time::from(t);
if body.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
let p=body.extrapolated_position(t);
if self.face_edges(face_id).iter().all(|&(_,face_id)|{
let (n,d)=self.face_nd(face_id);
n.dot(p)<=d
}){
best_time=t;
best_face=Some(face_id);
}
}
}
}
best_face.map(|f|(f,best_time))
}
fn vert_directed_edges(&self,vert_id:VertId)->Cow<Vec<DirectedEdgeId>>{
Cow::Borrowed(&self.vert_topology[vert_id.0].edges)
}
fn directed_edge_n(&self,directed_edge_id:DirectedEdgeId)->Planar64Vec3{
let verts=self.edge_verts(directed_edge_id.as_edge_id());
(self.vert(verts[1].clone())-self.vert(verts[0].clone()))*(directed_edge_id.signum() as i64)
}
}
impl MeshQuery<FaceId,EdgeId,VertId> for PhysicsMesh{
fn closest_fev(&self,point:Planar64Vec3)->FEV<FaceId,EdgeId,VertId>{
//TODO: put some genius code right here
//brute force for now
let mut best_distance_squared=Planar64::MAX;
//make something up as default ret
//hopefully empty meshes don't make their way through here
let mut best_fev=FEV::<FaceId,EdgeId,VertId>::Vert(VertId(0));
//check each vert
for (i,v) in self.verts.iter().enumerate(){
let d=(v.0-point).dot(v.0-point);
if d<best_distance_squared{
best_distance_squared=d;
best_fev=FEV::<FaceId,EdgeId,VertId>::Vert(VertId(i));
}
}
//check each edge
for (i,e) in self.edge_topology.iter().enumerate(){
let v0=self.vert(e.verts[0]);
let v1=self.vert(e.verts[1]);
let n=v1-v0;
//n.cross(point-v0)=sin(t)*n*dis
let d=n.dot(point-v0);
if d<n.dot(v1)&&n.dot(v0)<d{
let c=n.cross(point-v0);
let edge_distance_squared=c.dot(c)/n.dot(n);
if edge_distance_squared<best_distance_squared{
best_distance_squared=edge_distance_squared;
best_fev=FEV::<FaceId,EdgeId,VertId>::Edge(EdgeId(i));
}
}
}
let face_dots:Vec<Planar64>=self.faces.iter().map(|f|f.normal.dot(point)).collect();
//check each face
for (i,f) in self.face_topology.iter().enumerate(){
if face_dots[i]<best_distance_squared&&f.edges.iter().all(|&(_,face_id)|face_dots[face_id.0]<=Planar64::ZERO){
best_distance_squared=face_dots[i];
best_fev=FEV::<FaceId,EdgeId,VertId>::Face(FaceId(i));
}
}
best_fev
}
fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){
(self.faces[face_id.0].normal,self.faces[face_id.0].dot)
}
//ideally I never calculate the vertex position, but I have to for the graphical meshes...
fn vert(&self,vert_id:VertId)->Planar64Vec3{
self.verts[vert_id.0].0
}
fn face_edges(&self,face_id:FaceId)->Cow<Vec<(EdgeId,FaceId)>>{
Cow::Borrowed(&self.face_topology[face_id.0].edges)
}
fn edge_faces(&self,edge_id:EdgeId)->Cow<[FaceId;2]>{
Cow::Borrowed(&self.edge_topology[edge_id.0].faces)
}
fn edge_verts(&self,edge_id:EdgeId)->Cow<[VertId;2]>{
Cow::Borrowed(&self.edge_topology[edge_id.0].verts)
}
fn vert_edges(&self,vert_id:VertId)->Cow<Vec<EdgeId>>{
//not poggers
Cow::Owned(self.vert_topology[vert_id.0].edges.iter().map(|directed_edge_id|directed_edge_id.as_edge_id()).collect())
}
fn vert_faces(&self,vert_id:VertId)->Cow<Vec<FaceId>>{
Cow::Borrowed(&self.vert_topology[vert_id.0].faces)
}
}
pub struct TransformedMesh<'a>{
mesh:&'a PhysicsMesh,
transform:&'a crate::integer::Planar64Affine3,
normal_transform:&'a crate::integer::Planar64Mat3,
}
impl TransformedMesh<'_>{
pub fn new<'a>(
mesh:&'a PhysicsMesh,
transform:&'a crate::integer::Planar64Affine3,
normal_transform:&'a crate::integer::Planar64Mat3,
)->TransformedMesh<'a>{
TransformedMesh{
mesh,
transform,
normal_transform,
}
}
pub fn brute_in(&self,body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(FaceId,crate::integer::Time)>{
//check each face
let mut best_time=time_limit;
let mut best_face=None;
for i in 0..self.mesh.faces.len(){
let face_id=FaceId(i);
let (n,d)=self.face_nd(face_id);
for t in crate::zeroes::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+crate::integer::Time::from(t);
if body.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))<Planar64::ZERO{
let p=body.extrapolated_position(t);
if self.face_edges(face_id).iter().all(|&(_,face_id)|{
let (n,d)=self.face_nd(face_id);
n.dot(p)<=d
}){
best_time=t;
best_face=Some(face_id);
}
}
}
}
best_face.map(|f|(f,best_time))
}
pub fn brute_out(&self,body:&crate::physics::Body,time_limit:crate::integer::Time)->Option<(FaceId,crate::integer::Time)>{
//check each face
let mut best_time=time_limit;
let mut best_face=None;
for i in 0..self.mesh.faces.len(){
let face_id=FaceId(i);
let (n,d)=self.face_nd(face_id);
for t in crate::zeroes::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+crate::integer::Time::from(t);
if body.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))>Planar64::ZERO{
let p=body.extrapolated_position(t);
if self.face_edges(face_id).iter().all(|&(_,test_face_id)|{
let (n,d)=self.face_nd(test_face_id);
n.dot(p)<=d
}){
best_time=t;
best_face=Some(face_id);
}
}
}
}
best_face.map(|f|(f,best_time))
}
pub fn brute_out_face(&self,body:&crate::physics::Body,time_limit:crate::integer::Time,face_id:FaceId)->Option<(FaceId,crate::integer::Time)>{
//check each face
let mut best_time=time_limit;
let mut best_face=None;
for &(_,test_face_id) in self.mesh.face_edges(face_id).iter(){
let (n,d)=self.face_nd(test_face_id);
for t in crate::zeroes::zeroes2((n.dot(body.position)-d)*2,n.dot(body.velocity)*2,n.dot(body.acceleration)){
let t=body.time+crate::integer::Time::from(t);
if body.time<t&&t<best_time&&n.dot(body.extrapolated_velocity(t))>Planar64::ZERO{
best_time=t;
best_face=Some(test_face_id);
}
}
}
best_face.map(|f|(f,best_time))
}
#[inline]
fn vert_directed_edges(&self,vert_id:VertId)->Cow<Vec<DirectedEdgeId>>{
self.mesh.vert_directed_edges(vert_id)
}
#[inline]
fn directed_edge_n(&self,directed_edge_id:DirectedEdgeId)->Planar64Vec3{
self.mesh.directed_edge_n(directed_edge_id)
}
}
impl MeshQuery<FaceId,EdgeId,VertId> for TransformedMesh<'_>{
fn closest_fev(&self,point:Planar64Vec3)->FEV<FaceId,EdgeId,VertId>{
//TODO: put some genius code right here
//brute force for now
let mut best_distance_squared=Planar64::MAX;
//make something up as default ret
//hopefully empty meshes don't make their way through here
let mut best_fev=FEV::<FaceId,EdgeId,VertId>::Vert(VertId(0));
//check each vert
for i in 0..self.mesh.verts.len(){
let v=self.vert(VertId(i));
let d=(v-point).dot(v-point);
if d<best_distance_squared{
best_distance_squared=d;
best_fev=FEV::<FaceId,EdgeId,VertId>::Vert(VertId(i));
}
}
//check each edge
for (i,e) in self.mesh.edge_topology.iter().enumerate(){
let v0=self.vert(e.verts[0]);
let v1=self.vert(e.verts[1]);
let n=v1-v0;
//n.cross(point-v0)=sin(t)*n*dis
let d=n.dot(point-v0);
if d<n.dot(v1)&&n.dot(v0)<d{
let c=n.cross(point-v0);
let edge_distance_squared=c.dot(c)/n.dot(n);
if edge_distance_squared<best_distance_squared{
best_distance_squared=edge_distance_squared;
best_fev=FEV::<FaceId,EdgeId,VertId>::Edge(EdgeId(i));
}
}
}
let face_dots:Vec<Planar64>=self.mesh.faces.iter().map(|f|(*self.normal_transform*f.normal).dot(point)).collect();
//check each face
for (i,f) in self.mesh.face_topology.iter().enumerate(){
if face_dots[i]<best_distance_squared&&f.edges.iter().all(|&(_,face_id)|face_dots[face_id.0]<=Planar64::ZERO){
best_distance_squared=face_dots[i];
best_fev=FEV::<FaceId,EdgeId,VertId>::Face(FaceId(i));
}
}
best_fev
}
fn face_nd(&self,face_id:FaceId)->(Planar64Vec3,Planar64){
let (n,d)=self.mesh.face_nd(face_id);
let transformed_n=*self.normal_transform*n;
let transformed_d=Planar64::raw(((transformed_n.dot128(self.transform.matrix3*(n*d))<<32)/n.dot128(n)) as i64)+transformed_n.dot(self.transform.translation);
(transformed_n,transformed_d)
}
fn vert(&self,vert_id:VertId)->Planar64Vec3{
self.transform.transform_point3(self.mesh.vert(vert_id))
}
#[inline]
fn face_edges(&self,face_id:FaceId)->Cow<Vec<(EdgeId,FaceId)>>{
self.mesh.face_edges(face_id)
}
#[inline]
fn edge_faces(&self,edge_id:EdgeId)->Cow<[FaceId;2]>{
self.mesh.edge_faces(edge_id)
}
#[inline]
fn edge_verts(&self,edge_id:EdgeId)->Cow<[VertId;2]>{
self.mesh.edge_verts(edge_id)
}
#[inline]
fn vert_edges(&self,vert_id:VertId)->Cow<Vec<EdgeId>>{
self.mesh.vert_edges(vert_id)
}
#[inline]
fn vert_faces(&self,vert_id:VertId)->Cow<Vec<FaceId>>{
self.mesh.vert_faces(vert_id)
}
}
//Note that a face on a minkowski mesh refers to a pair of fevs on the meshes it's summed from
//(face,vertex)
//(edge,edge)
//(vertex,face)
#[derive(Clone,Copy)]
enum MinkowskiVert{
VertVert(VertId,VertId),
}
#[derive(Clone,Copy)]
enum MinkowskiEdge{
VertEdge(VertId,EdgeId),
EdgeVert(EdgeId,VertId),
}
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
pub enum MinkowskiFace{
VertFace(VertId,FaceId),
EdgeEdge(EdgeId,EdgeId),
FaceVert(FaceId,VertId),
}
pub struct MinkowskiMesh<'a>{
mesh0:&'a TransformedMesh<'a>,
mesh1:&'a TransformedMesh<'a>,
}
impl MinkowskiMesh<'_>{
pub fn minkowski_sum<'a>(mesh0:&'a TransformedMesh,mesh1:&'a TransformedMesh)->MinkowskiMesh<'a>{
MinkowskiMesh{
mesh0,
mesh1,
}
}
}
impl MeshQuery<MinkowskiFace,MinkowskiEdge,MinkowskiVert> for MinkowskiMesh<'_>{
fn closest_fev(&self,point:Planar64Vec3)->FEV<MinkowskiFace,MinkowskiEdge,MinkowskiVert>{
//put some genius code right here
todo!()
}
fn face_nd(&self,face_id:MinkowskiFace)->(Planar64Vec3,Planar64){
match face_id{
MinkowskiFace::VertFace(v0,f1)=>{
let (n,d)=self.mesh1.face_nd(f1);
(-n,d-n.dot(self.mesh0.vert(v0)))
},
MinkowskiFace::EdgeEdge(e0,e1)=>{
let edge0_n=self.mesh0.edge_n(e0);
let edge1_n=self.mesh1.edge_n(e1);
let &[e0v0,e0v1]=self.mesh0.edge_verts(e0).borrow();
let &[e1v0,e1v1]=self.mesh1.edge_verts(e1).borrow();
let n=edge0_n.cross(edge1_n);
let e0d=n.dot(self.mesh0.vert(e0v0)+self.mesh0.vert(e0v1));
let e1d=n.dot(self.mesh0.vert(e1v0)+self.mesh0.vert(e1v1));
let sign=e0d.signum_i64();
(n*(sign*2),(e0d-e1d)*sign)
},
MinkowskiFace::FaceVert(f0,v1)=>{
let (n,d)=self.mesh0.face_nd(f0);
(n,d+n.dot(self.mesh1.vert(v1)))
},
}
}
fn vert(&self,vert_id:MinkowskiVert)->Planar64Vec3{
match vert_id{
MinkowskiVert::VertVert(v0,v1)=>{
self.mesh0.vert(v0)-self.mesh1.vert(v1)
},
}
}
fn face_edges(&self,face_id:MinkowskiFace)->Cow<Vec<(MinkowskiEdge,MinkowskiFace)>>{
match face_id{
MinkowskiFace::VertFace(v0,f1)=>{
let face1_n=self.mesh1.face_nd(f1).0;
Cow::Owned(self.mesh1.face_edges(f1).iter().map(|&(edge_id1,edge_face_id1)|{
//same as above
(MinkowskiEdge::VertEdge(v0,edge_id1),{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face1_n=self.mesh1.face_nd(edge_face_id1).0;
let v0e=self.mesh0.vert_directed_edges(v0);
for &directed_edge_id0 in v0e.iter(){
let edge0_n=self.mesh0.directed_edge_n(directed_edge_id0);
if edge_face1_n.dot(edge0_n)<Planar64::ZERO{
let d=face1_n.dot(edge0_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id0);
}
}
}
best_edge.map_or(
MinkowskiFace::VertFace(v0,edge_face_id1),
|directed_edge_id0|MinkowskiFace::EdgeEdge(directed_edge_id0.as_edge_id(),edge_id1)
)
})
}).collect())
},
MinkowskiFace::EdgeEdge(e0,e1)=>{
let e0v=self.mesh0.edge_verts(e0);
let e0f=self.mesh0.edge_faces(e0);
let edge0_n=self.mesh0.edge_n(e0);
let e1v=self.mesh1.edge_verts(e1);
let e1f=self.mesh1.edge_faces(e1);
let edge1_n=self.mesh1.edge_n(e1);
//populate algorithm variables based on known parity
//I don't like that this arbitrarily picks a face to test against!
let (e0v0_face_id1,e0v1_face_id1)=if edge0_n.dot(self.mesh1.face_nd(e1f[0]).0)<=Planar64::ZERO{
(e1f[1],e1f[0])
}else{
(e1f[0],e1f[1])
};
let [r0,r1]=[(e0v[0],e0v0_face_id1),(e0v[1],e0v1_face_id1)].map(|(vert_id0,edge_face_id1)|{
(MinkowskiEdge::VertEdge(vert_id0,e1),{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face1_n=self.mesh1.face_nd(edge_face_id1).0;
let v0e=self.mesh0.vert_directed_edges(vert_id0);
for &directed_edge_id0 in v0e.iter(){
let edge0_n=self.mesh0.directed_edge_n(directed_edge_id0);
if edge_face1_n.dot(edge0_n)<Planar64::ZERO{
//I think face_id1 == edge_face_id1 in this case
let d=edge_face1_n.dot(edge0_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id0);
}
}
}
best_edge.map_or(
MinkowskiFace::VertFace(vert_id0,edge_face_id1),
|directed_edge_id0|MinkowskiFace::EdgeEdge(directed_edge_id0.as_edge_id(),e1)
)
})
});
let (e1v0_face_id0,e1v1_face_id0)=if edge1_n.dot(self.mesh0.face_nd(e0f[0]).0)<=Planar64::ZERO{
(e0f[1],e0f[0])
}else{
(e0f[0],e0f[1])
};
let [r2,r3]=[(e1v0_face_id0,e1v[0]),(e1v1_face_id0,e1v[1])].map(|(edge_face_id0,vert_id1)|{
(MinkowskiEdge::EdgeVert(e0,vert_id1),{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face0_n=self.mesh0.face_nd(edge_face_id0).0;
let v1e=self.mesh1.vert_directed_edges(vert_id1);
for &directed_edge_id1 in v1e.iter(){
let edge1_n=self.mesh1.directed_edge_n(directed_edge_id1);
if edge_face0_n.dot(edge1_n)<Planar64::ZERO{
let d=edge_face0_n.dot(edge1_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id1);
}
}
}
best_edge.map_or(
MinkowskiFace::FaceVert(edge_face_id0,vert_id1),
|directed_edge_id1|MinkowskiFace::EdgeEdge(e0,directed_edge_id1.as_edge_id())
)
})
});
//could sort this if ordered edges are needed
Cow::Owned(vec![r0,r1,r2,r3])
},
MinkowskiFace::FaceVert(f0,v1)=>{
let face0_n=self.mesh0.face_nd(f0).0;
Cow::Owned(self.mesh0.face_edges(f0).iter().map(|&(edge_id0,edge_face_id0)|{
//compare v1 edges
//candidate edges have negative dot with edge_face_id0 normal
//choose the edge with the smallest edgedir dot with f0 normal
//MinkowskiFace::EdgeEdge(edge_id0,edge_id1)
//if there is no candidate edges
//MinkowskiFace::FaceVert(edge_face_id0,v1)
(MinkowskiEdge::EdgeVert(edge_id0,v1),{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face0_n=self.mesh0.face_nd(edge_face_id0).0;
let v1e=self.mesh1.vert_directed_edges(v1);
for &directed_edge_id1 in v1e.iter(){
let edge1_n=self.mesh1.directed_edge_n(directed_edge_id1);
if edge_face0_n.dot(edge1_n)<Planar64::ZERO{
let d=face0_n.dot(edge1_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id1);
}
}
}
best_edge.map_or(
MinkowskiFace::FaceVert(edge_face_id0,v1),
|directed_edge_id1|MinkowskiFace::EdgeEdge(edge_id0,directed_edge_id1.as_edge_id())
)
})
}).collect())
},
}
}
fn edge_faces(&self,edge_id:MinkowskiEdge)->Cow<[MinkowskiFace;2]>{
match edge_id{
MinkowskiEdge::VertEdge(v0,e1)=>{
let e1f=self.mesh1.edge_faces(e1);
Cow::Owned([(e1f[0],e1f[1]),(e1f[1],e1f[0])].map(|(edge_face_id1,other_edge_face_id1)|{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face1_n=self.mesh1.face_nd(edge_face_id1).0;
let other_edge_face1_n=self.mesh1.face_nd(other_edge_face_id1).0;
let v0e=self.mesh0.vert_directed_edges(v0);
for &directed_edge_id0 in v0e.iter(){
let edge0_n=self.mesh0.directed_edge_n(directed_edge_id0);
if edge_face1_n.dot(edge0_n)<Planar64::ZERO{
let d=other_edge_face1_n.dot(edge0_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id0);
}
}
}
best_edge.map_or(
MinkowskiFace::VertFace(v0,edge_face_id1),
|directed_edge_id0|MinkowskiFace::EdgeEdge(directed_edge_id0.as_edge_id(),e1)
)
}))
},
MinkowskiEdge::EdgeVert(e0,v1)=>{
let e0f=self.mesh0.edge_faces(e0);
Cow::Owned([(e0f[0],e0f[1]),(e0f[1],e0f[0])].map(|(edge_face_id0,other_edge_face_id0)|{
let mut best_edge=None;
let mut best_d=Planar64::MAX;
let edge_face0_n=self.mesh0.face_nd(edge_face_id0).0;
let other_edge_face0_n=self.mesh0.face_nd(other_edge_face_id0).0;
let v1e=self.mesh1.vert_directed_edges(v1);
for &directed_edge_id1 in v1e.iter(){
let edge1_n=self.mesh1.directed_edge_n(directed_edge_id1);
if edge_face0_n.dot(edge1_n)<Planar64::ZERO{
let d=other_edge_face0_n.dot(edge1_n);
if d<best_d{
best_d=d;
best_edge=Some(directed_edge_id1);
}
}
}
best_edge.map_or(
MinkowskiFace::FaceVert(edge_face_id0,v1),
|directed_edge_id1|MinkowskiFace::EdgeEdge(e0,directed_edge_id1.as_edge_id())
)
}))
},
}
}
fn edge_verts(&self,edge_id:MinkowskiEdge)->Cow<[MinkowskiVert;2]>{
match edge_id{
MinkowskiEdge::VertEdge(v0,e1)=>{
Cow::Owned(self.mesh1.edge_verts(e1).map(|vert_id1|{
MinkowskiVert::VertVert(v0,vert_id1)
}))
},
MinkowskiEdge::EdgeVert(e0,v1)=>{
Cow::Owned(self.mesh0.edge_verts(e0).map(|vert_id0|{
MinkowskiVert::VertVert(vert_id0,v1)
}))
},
}
}
fn vert_edges(&self,vert_id:MinkowskiVert)->Cow<Vec<MinkowskiEdge>>{
match vert_id{
MinkowskiVert::VertVert(v0,v1)=>{
let mut edges=Vec::new();
let v0e=self.mesh0.vert_directed_edges(v0);
let v1f=self.mesh1.vert_faces(v1);
for &directed_edge_id in v0e.iter(){
let n=self.mesh0.directed_edge_n(directed_edge_id);
if v1f.iter().all(|&face_id|n.dot(self.mesh1.face_nd(face_id).0)<Planar64::ZERO){
edges.push(MinkowskiEdge::EdgeVert(directed_edge_id.as_edge_id(),v1));
}
}
let v1e=self.mesh1.vert_directed_edges(v1);
let v0f=self.mesh0.vert_faces(v0);
for &directed_edge_id in v1e.iter(){
let n=self.mesh1.directed_edge_n(directed_edge_id);
if v0f.iter().all(|&face_id|n.dot(self.mesh0.face_nd(face_id).0)<Planar64::ZERO){
edges.push(MinkowskiEdge::VertEdge(v0,directed_edge_id.as_edge_id()));
}
}
Cow::Owned(edges)
},
}
}
fn vert_faces(&self,vert_id:MinkowskiVert)->Cow<Vec<MinkowskiFace>>{
todo!()
}
}
#[test]
fn build_me_a_cube(){
let unit_cube=crate::primitives::unit_cube();
let mesh=PhysicsMesh::from(&unit_cube);
println!("mesh={:?}",mesh);
}
//

File diff suppressed because it is too large Load Diff

8
src/sweep.rs Normal file
View File

@@ -0,0 +1,8 @@
//something that implements body + hitbox + transform can predict collision
impl crate::sweep::PredictCollision for Model {
fn predict_collision(&self,other:&Model) -> Option<crate::event::EventStruct> {
//math!
None
}
}

View File

@@ -177,8 +177,8 @@ impl<'a,Task:Send+'a> INWorker<'a,Task>{
fn test_worker() {
println!("hiiiii");
// Create the worker thread
let worker=QRWorker::new(crate::physics::Body::default(),
|_|crate::physics::Body::new(crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Time::ZERO)
let worker=QRWorker::new(crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO),
|_|crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE)
);
// Send tasks to the worker
@@ -194,7 +194,7 @@ fn test_worker() {
// sender.send("STOP".to_string()).unwrap();
// Sleep to allow the worker thread to finish processing
thread::sleep(std::time::Duration::from_millis(10));
thread::sleep(std::time::Duration::from_secs(2));
// Send a new task
let task = crate::instruction::TimedInstruction{
@@ -206,5 +206,5 @@ fn test_worker() {
println!("value={}",worker.grab_clone());
// wait long enough to see print from final task
thread::sleep(std::time::Duration::from_millis(10));
thread::sleep(std::time::Duration::from_secs(1));
}

69
src/world.rs Normal file
View File

@@ -0,0 +1,69 @@
use crate::integer::{Time,Planar64Vec3};
use crate::instruction::TimedInstruction;
/// A C0 continuous trajectory change.
enum TrajectoryC0{
TargetPointFuture(Planar64Vec3,Time),
TargetVelocityFuture(Planar64Vec3,Time),
UseAcceleration(Planar64Vec3),
}
/// A C1 continuous trajectory change.
enum TrajectoryC1{
TargetPointVelocityFuture(Planar64Vec3,Planar64Vec3,Time),
UseVelocityAcceleration(Planar64Vec3,Planar64Vec3),
TargetPointAcceleration(Planar64Vec3,Planar64Vec3),
}
struct Trajectory{
position:Planar64Vec3,
velocity:Planar64Vec3,
acceleration:Planar64Vec3,
}
impl Trajectory{
pub fn into_body(self,time:Time)->crate::physics::Body{
crate::physics::Body::new(self.position,self.velocity,self.acceleration,time)
}
}
//literally option... Option<Option<T>> doesn't seem ergonomic but is effectively what's needed
enum Edit<T>{
Change(T),
Unchanged,
}
/// Each property is specified as either changed or staying the same
struct EditAttributes{}
struct EditStyleModifiers{}
enum Instruction{
/// Keep Position, edit Velocity and Acceleration
ContinueTrajectoryC0(TrajectoryC0),
/// Keep Position and Velocity, edit acceleration
ContinueTrajectoryC1(TrajectoryC1),
/// Teleport to a new Position, Velocity, and Acceleration
NewTrajectory(Trajectory),
/// Change the object transform (teleport) This is also how the object must rotate!
EditTransform(crate::integer::Planar64Affine3),
/// Change specific attributes
EditAttributes(EditAttributes),
/// Change specific style modifiers
EditStyleModifiers(EditStyleModifiers),
}
// The moving platform script init function returns this object's initial state
struct Dynamic{
/// somehow allow a mutable state function to control the whole thing
pub next_instruction:Option<TimedInstruction<Instruction>>,
pub update:Box<dyn FnMut(TimedInstruction<Instruction>)->Option<TimedInstruction<Instruction>>>,
}
impl crate::instruction::InstructionEmitter<Instruction> for Dynamic{
fn next_instruction(&self,time_limit:Time)->Option<TimedInstruction<Instruction>>{
self.next_instruction
}
}
impl crate::instruction::InstructionConsumer<Instruction> for Dynamic{
fn process_instruction(&mut self,instruction:TimedInstruction<Instruction>){
self.next_instruction=(self.update)(instruction);
}
}

View File

@@ -11,12 +11,10 @@ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{
//start with f64 sqrt
let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()});
//TODO: one or two newtons
//sort roots ascending and avoid taking the difference of large numbers
match (Planar64::ZERO<a2,Planar64::ZERO<a1){
(true, true )=>vec![(-a1-planar_radicand)/(a2*2),(a0*2)/(-a1-planar_radicand)],
(true, false)=>vec![(a0*2)/(-a1+planar_radicand),(-a1+planar_radicand)/(a2*2)],
(false,true )=>vec![(a0*2)/(-a1-planar_radicand),(-a1-planar_radicand)/(a2*2)],
(false,false)=>vec![(-a1+planar_radicand)/(a2*2),(a0*2)/(-a1+planar_radicand)],
if Planar64::ZERO<a2 {
return vec![(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)];
} else {
return vec![(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)];
}
} else if radicand==0 {
return vec![a1/(a2*-2)];