Compare commits
119 Commits
master
...
point-phys
Author | SHA1 | Date | |
---|---|---|---|
4c05c01b6e | |||
b20f573f1d | |||
21e29aa63e | |||
48870b8a76 | |||
020c704968 | |||
8f63699d45 | |||
6071e23be1 | |||
46d6c31957 | |||
5b26304e95 | |||
d3cf75e0d5 | |||
2acf740898 | |||
816f786763 | |||
f7c613dfa6 | |||
4fc09806f6 | |||
3cbefbab03 | |||
717cf2290d | |||
756648c2fb | |||
44540853dd | |||
43e62e8f1d | |||
4af4dc669b | |||
24f6472e9f | |||
cff920ddcd | |||
053514fa4a | |||
27a46093ae | |||
6049aba716 | |||
b7998c7bd4 | |||
63cfbbfa9c | |||
f7072be5b4 | |||
4456ee29ec | |||
2d14e8ac8e | |||
176aaa069c | |||
a6dfa1d72b | |||
516510faa8 | |||
1d2de93b9e | |||
2988175436 | |||
03b21aa27f | |||
910d520c2b | |||
c321814b9b | |||
ce1e9df334 | |||
e6e7366e66 | |||
535ae1a5f0 | |||
432a38718c | |||
9aa7656278 | |||
823a16e08d | |||
82d84ee07c | |||
ffc19020b9 | |||
e0581390bd | |||
4b4ac0de19 | |||
d94ad475eb | |||
60eadd3156 | |||
ebca761dbc | |||
ab60fb2cf7 | |||
ec9b720138 | |||
7ad0270d2f | |||
d8e605d203 | |||
dc46cb3d45 | |||
a53d90f74b | |||
d9be4b8105 | |||
58c35ce364 | |||
2a033b87e0 | |||
d374a3d4c6 | |||
c37b990389 | |||
7311b1ae88 | |||
af7fcdd5cb | |||
bf51afcf1d | |||
fd9ca6cd3f | |||
d71f143d68 | |||
769f88eb9f | |||
cf9063bffc | |||
fc3d72393f | |||
a5ef0195e2 | |||
6fec6b9f59 | |||
895f9b82f8 | |||
6aa0e790d8 | |||
b897d4a662 | |||
49931a40fc | |||
e92eaed2d3 | |||
1ec9412b49 | |||
d9966a4eb0 | |||
cee6835af6 | |||
f1e0514ecb | |||
86d45252c7 | |||
9f948744d4 | |||
5e28c02640 | |||
5f1b93d9c4 | |||
d63a76269f | |||
354b96d98f | |||
d155517587 | |||
3c443b6b6a | |||
f73b4a0c52 | |||
c37194daf6 | |||
5317a0fafe | |||
941faf199d | |||
053bab9e24 | |||
89f7a2b9b9 | |||
dff2648cd3 | |||
d2d5a62458 | |||
89ea7f45f9 | |||
01d74102e3 | |||
ee4e6dbbaf | |||
19d4fed2a2 | |||
a9f6cc7c29 | |||
64657e718d | |||
3d5ac0cd61 | |||
72ebe5c9c8 | |||
e1fde9b507 | |||
0cb6236035 | |||
a8b1ced5cd | |||
bb46801610 | |||
06eeac6043 | |||
558febabc3 | |||
1b51e21ecd | |||
7ce08b0bbe | |||
19c7a8924e | |||
b215578c8d | |||
2bea7e210e | |||
f8a8cbf12a | |||
9f76611c18 | |||
4da3d78057 |
46
src/aabb.rs
46
src/aabb.rs
@ -1,14 +1,5 @@
|
|||||||
use crate::integer::Planar64Vec3;
|
use crate::integer::Planar64Vec3;
|
||||||
|
|
||||||
#[derive(Debug,Clone,Copy,Hash,Eq,PartialEq)]
|
|
||||||
pub enum AabbFace{
|
|
||||||
Right,//+X
|
|
||||||
Top,
|
|
||||||
Back,
|
|
||||||
Left,
|
|
||||||
Bottom,
|
|
||||||
Front,
|
|
||||||
}
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Aabb{
|
pub struct Aabb{
|
||||||
pub min:Planar64Vec3,
|
pub min:Planar64Vec3,
|
||||||
@ -22,17 +13,6 @@ impl Default for Aabb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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){
|
pub fn grow(&mut self,point:Planar64Vec3){
|
||||||
self.min=self.min.min(point);
|
self.min=self.min.min(point);
|
||||||
self.max=self.max.max(point);
|
self.max=self.max.max(point);
|
||||||
@ -48,32 +28,6 @@ impl Aabb{
|
|||||||
pub fn intersects(&self,aabb:&Aabb)->bool{
|
pub fn intersects(&self,aabb:&Aabb)->bool{
|
||||||
(self.min.cmplt(aabb.max)&aabb.min.cmplt(self.max)).all()
|
(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{
|
pub fn center(&self)->Planar64Vec3{
|
||||||
return self.min.midpoint(self.max)
|
return self.min.midpoint(self.max)
|
||||||
}
|
}
|
||||||
|
126
src/face_crawler.rs
Normal file
126
src/face_crawler.rs
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
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
|
||||||
|
}
|
@ -25,7 +25,10 @@ impl<I> InstructionCollector<I>{
|
|||||||
instruction:None
|
instruction:None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn time(&self)->Time{
|
||||||
|
self.time
|
||||||
|
}
|
||||||
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
pub fn collect(&mut self,instruction:Option<TimedInstruction<I>>){
|
||||||
match instruction{
|
match instruction{
|
||||||
Some(unwrap_instruction)=>{
|
Some(unwrap_instruction)=>{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
//integer units
|
//integer units
|
||||||
#[derive(Clone,Copy,Hash,PartialEq,PartialOrd,Debug)]
|
#[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)]
|
||||||
pub struct Time(i64);
|
pub struct Time(i64);
|
||||||
impl Time{
|
impl Time{
|
||||||
pub const ZERO:Self=Self(0);
|
pub const ZERO:Self=Self(0);
|
||||||
@ -414,6 +414,7 @@ pub struct Planar64(i64);
|
|||||||
impl Planar64{
|
impl Planar64{
|
||||||
pub const ZERO:Self=Self(0);
|
pub const ZERO:Self=Self(0);
|
||||||
pub const ONE:Self=Self(1<<32);
|
pub const ONE:Self=Self(1<<32);
|
||||||
|
pub const MAX:Self=Self(i64::MAX);
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn int(num:i32)->Self{
|
pub const fn int(num:i32)->Self{
|
||||||
Self(Self::ONE.0*num as i64)
|
Self(Self::ONE.0*num as i64)
|
||||||
@ -426,9 +427,14 @@ impl Planar64{
|
|||||||
pub const fn get(&self)->i64{
|
pub const fn get(&self)->i64{
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
pub fn sqrt(&self)->Self{
|
pub fn sqrt(&self)->Self{
|
||||||
Planar64(unsafe{(((self.0 as i128)<<32) as f64).sqrt().to_int_unchecked()})
|
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_ONE_FLOAT32:f32=(1u64<<32) as f32;
|
||||||
const PLANAR64_CONVERT_TO_FLOAT32:f32=1.0/PLANAR64_ONE_FLOAT32;
|
const PLANAR64_CONVERT_TO_FLOAT32:f32=1.0/PLANAR64_ONE_FLOAT32;
|
||||||
@ -518,6 +524,12 @@ impl std::ops::Add<Planar64> for Planar64{
|
|||||||
Planar64(self.0+rhs.0)
|
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{
|
impl std::ops::Sub<Planar64> for Planar64{
|
||||||
type Output=Planar64;
|
type Output=Planar64;
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -582,6 +594,10 @@ impl Planar64Vec3{
|
|||||||
pub const MIN:Self=Planar64Vec3(glam::I64Vec3::MIN);
|
pub const MIN:Self=Planar64Vec3(glam::I64Vec3::MIN);
|
||||||
pub const MAX:Self=Planar64Vec3(glam::I64Vec3::MAX);
|
pub const MAX:Self=Planar64Vec3(glam::I64Vec3::MAX);
|
||||||
#[inline]
|
#[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{
|
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))
|
Self(glam::i64vec3((x as i64)<<32,(y as i64)<<32,(z as i64)<<32))
|
||||||
}
|
}
|
||||||
@ -634,6 +650,26 @@ impl Planar64Vec3{
|
|||||||
)>>32) as i64)
|
)>>32) as i64)
|
||||||
}
|
}
|
||||||
#[inline]
|
#[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{
|
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);
|
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()})
|
Planar64(unsafe{(radicand as f64).sqrt().to_int_unchecked()})
|
||||||
@ -781,7 +817,7 @@ impl std::ops::Div<i64> for Planar64Vec3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
///[-1.0,1.0] = [-2^32,2^32]
|
///[-1.0,1.0] = [-2^32,2^32]
|
||||||
#[derive(Clone,Copy)]
|
#[derive(Clone,Copy,Hash,Eq,PartialEq)]
|
||||||
pub struct Planar64Mat3{
|
pub struct Planar64Mat3{
|
||||||
x_axis:Planar64Vec3,
|
x_axis:Planar64Vec3,
|
||||||
y_axis:Planar64Vec3,
|
y_axis:Planar64Vec3,
|
||||||
@ -853,6 +889,41 @@ impl Planar64Mat3{
|
|||||||
Planar64Vec3(glam::i64vec3(s,0,c)),
|
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{
|
impl Into<glam::Mat3> for Planar64Mat3{
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -897,7 +968,7 @@ impl std::ops::Div<i64> for Planar64Mat3{
|
|||||||
}
|
}
|
||||||
|
|
||||||
///[-1.0,1.0] = [-2^32,2^32]
|
///[-1.0,1.0] = [-2^32,2^32]
|
||||||
#[derive(Clone,Copy,Default)]
|
#[derive(Clone,Copy,Default,Hash,Eq,PartialEq)]
|
||||||
pub struct Planar64Affine3{
|
pub struct Planar64Affine3{
|
||||||
pub matrix3:Planar64Mat3,//includes scale above 1
|
pub matrix3:Planar64Mat3,//includes scale above 1
|
||||||
pub translation:Planar64Vec3,
|
pub translation:Planar64Vec3,
|
||||||
|
@ -45,14 +45,19 @@ fn get_attributes(name:&str,can_collide:bool,velocity:Planar64Vec3,force_interse
|
|||||||
"Water"=>{
|
"Water"=>{
|
||||||
force_can_collide=false;
|
force_can_collide=false;
|
||||||
//TODO: read stupid CustomPhysicalProperties
|
//TODO: read stupid CustomPhysicalProperties
|
||||||
intersecting.water=Some(crate::model::IntersectingWater{density:Planar64::ONE,viscosity:Planar64::ONE/10,current:velocity});
|
intersecting.water=Some(crate::model::IntersectingWater{density:Planar64::ONE,viscosity:Planar64::ONE/10,velocity});
|
||||||
},
|
},
|
||||||
"Accelerator"=>{
|
"Accelerator"=>{
|
||||||
//although the new game supports collidable accelerators, this is a roblox compatability map loader
|
//although the new game supports collidable accelerators, this is a roblox compatability map loader
|
||||||
force_can_collide=false;
|
force_can_collide=false;
|
||||||
general.accelerator=Some(crate::model::GameMechanicAccelerator{acceleration:velocity});
|
general.accelerator=Some(crate::model::GameMechanicAccelerator{acceleration:velocity});
|
||||||
},
|
},
|
||||||
"UnorderedCheckpoint"=>general.checkpoint=Some(crate::model::GameMechanicCheckpoint::Unordered{mode_id:0}),
|
// "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
|
||||||
|
// })),
|
||||||
"SetVelocity"=>general.trajectory=Some(crate::model::GameMechanicSetTrajectory::Velocity(velocity)),
|
"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})},
|
"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})},
|
"MapAnticheat"=>{force_can_collide=false;general.zone=Some(crate::model::GameMechanicZone{mode_id:0,behaviour:crate::model::ZoneBehaviour::Anitcheat})},
|
||||||
@ -111,13 +116,14 @@ 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()})),
|
"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"),
|
_=>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
|
//need some way to skip this
|
||||||
|
@ -12,7 +12,9 @@ mod settings;
|
|||||||
mod primitives;
|
mod primitives;
|
||||||
mod instruction;
|
mod instruction;
|
||||||
mod load_roblox;
|
mod load_roblox;
|
||||||
|
mod face_crawler;
|
||||||
mod compat_worker;
|
mod compat_worker;
|
||||||
|
mod model_physics;
|
||||||
mod model_graphics;
|
mod model_graphics;
|
||||||
mod physics_worker;
|
mod physics_worker;
|
||||||
mod graphics_worker;
|
mod graphics_worker;
|
||||||
|
119
src/model.rs
119
src/model.rs
@ -83,73 +83,78 @@ pub enum TempIndexedAttributes{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//you have this effect while in contact
|
//you have this effect while in contact
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct ContactingLadder{
|
pub struct ContactingLadder{
|
||||||
pub sticky:bool
|
pub sticky:bool
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum ContactingBehaviour{
|
pub enum ContactingBehaviour{
|
||||||
Surf,
|
Surf,
|
||||||
Ladder(ContactingLadder),
|
Cling,//usable as a zipline, or other weird and wonderful things
|
||||||
Elastic(u32),//[1/2^32,1] 0=None (elasticity+1)/2^32
|
Ladder(ContactingLadder),
|
||||||
|
Elastic(u32),//[1/2^32,1] 0=None (elasticity+1)/2^32
|
||||||
}
|
}
|
||||||
//you have this effect while intersecting
|
//you have this effect while intersecting
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct IntersectingWater{
|
pub struct IntersectingWater{
|
||||||
pub viscosity:Planar64,
|
pub viscosity:Planar64,
|
||||||
pub density:Planar64,
|
pub density:Planar64,
|
||||||
pub current:Planar64Vec3,
|
pub velocity:Planar64Vec3,
|
||||||
}
|
}
|
||||||
//All models can be given these attributes
|
//All models can be given these attributes
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct GameMechanicAccelerator{
|
pub struct GameMechanicAccelerator{
|
||||||
pub acceleration:Planar64Vec3
|
pub acceleration:Planar64Vec3
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum GameMechanicBooster{
|
pub enum GameMechanicBooster{
|
||||||
Affine(Planar64Affine3),//capable of SetVelocity,DotVelocity,normal booster,bouncy part,redirect velocity, and much more
|
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
|
Velocity(Planar64Vec3),//straight up boost velocity adds to your current velocity
|
||||||
Energy{direction:Planar64Vec3,energy:Planar64},//increase energy in direction
|
Energy{direction:Planar64Vec3,energy:Planar64},//increase energy in direction
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum GameMechanicCheckpoint{
|
|
||||||
Ordered{
|
|
||||||
mode_id:u32,
|
|
||||||
checkpoint_id:u32,
|
|
||||||
},
|
|
||||||
Unordered{
|
|
||||||
mode_id:u32,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub enum TrajectoryChoice{
|
pub enum TrajectoryChoice{
|
||||||
HighArcLongDuration,//underhand lob at target: less horizontal speed and more air time
|
HighArcLongDuration,//underhand lob at target: less horizontal speed and more air time
|
||||||
LowArcShortDuration,//overhand throw at target: more horizontal speed and less air time
|
LowArcShortDuration,//overhand throw at target: more horizontal speed and less air time
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum GameMechanicSetTrajectory{
|
pub enum GameMechanicSetTrajectory{
|
||||||
|
//Speed-type SetTrajectory
|
||||||
AirTime(Time),//air time (relative to gravity direction) is invariant across mass and gravity changes
|
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
|
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
|
TargetPointTime{//launch on a trajectory that will land at a target point in a set amount of time
|
||||||
target_point:Planar64Vec3,
|
target_point:Planar64Vec3,
|
||||||
time:Time,//short time = fast and direct, long time = launch high in the air, negative time = wrong way
|
time:Time,//short time = fast and direct, long time = launch high in the air, negative time = wrong way
|
||||||
},
|
},
|
||||||
TrajectoryTargetPoint{//launch at a fixed speed and land at a target point
|
TargetPointSpeed{//launch at a fixed speed and land at a target point
|
||||||
target_point:Planar64Vec3,
|
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
|
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,
|
trajectory_choice:TrajectoryChoice,
|
||||||
},
|
},
|
||||||
Velocity(Planar64Vec3),//SetVelocity
|
Velocity(Planar64Vec3),//SetVelocity
|
||||||
DotVelocity{direction:Planar64Vec3,dot:Planar64},//set your velocity in a specific direction without touching other directions
|
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
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)]
|
||||||
pub enum ZoneBehaviour{
|
pub enum ZoneBehaviour{
|
||||||
//Start is indexed
|
//Start is indexed
|
||||||
//Checkpoints are indexed
|
//Checkpoints are indexed
|
||||||
Finish,
|
Finish,
|
||||||
Anitcheat,
|
Anitcheat,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct GameMechanicZone{
|
pub struct GameMechanicZone{
|
||||||
pub mode_id:u32,
|
pub mode_id:u32,
|
||||||
pub behaviour:ZoneBehaviour,
|
pub behaviour:ZoneBehaviour,
|
||||||
@ -160,31 +165,36 @@ pub struct GameMechanicZone{
|
|||||||
// InRange(Planar64,Planar64),
|
// InRange(Planar64,Planar64),
|
||||||
// OutsideRange(Planar64,Planar64),
|
// OutsideRange(Planar64,Planar64),
|
||||||
// }
|
// }
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum StageElementBehaviour{
|
pub enum StageElementBehaviour{
|
||||||
//Spawn,//The behaviour of stepping on a spawn setting the spawnid
|
//Spawn,//The behaviour of stepping on a spawn setting the spawnid
|
||||||
SpawnAt,
|
SpawnAt,//must be standing on top to get effect. except cancollide false
|
||||||
Trigger,
|
Trigger,
|
||||||
Teleport,
|
Teleport,
|
||||||
Platform,
|
Platform,
|
||||||
//Acts like a trigger if you haven't hit all the checkpoints.
|
//Checkpoint acts like a trigger if you haven't hit all the checkpoints yet.
|
||||||
Checkpoint{
|
//Note that all stage elements act like this for the next stage.
|
||||||
//if this is 2 you must have hit OrderedCheckpoint(0) OrderedCheckpoint(1) OrderedCheckpoint(2) to pass
|
Checkpoint,
|
||||||
ordered_checkpoint_id:Option<u32>,
|
//OrderedCheckpoint. You must pass through all of these in ascending order.
|
||||||
//if this is 2 you must have hit at least 2 UnorderedCheckpoints to pass
|
//If you hit them out of order it acts like a trigger.
|
||||||
unordered_checkpoint_count:u32,
|
//Do not support backtracking at all for now.
|
||||||
},
|
Ordered{
|
||||||
JumpLimit(u32),
|
checkpoint_id:u32,
|
||||||
//Speedtrap(TrapCondition),//Acts as a trigger with a speed condition
|
},
|
||||||
|
//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
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct GameMechanicStageElement{
|
pub struct GameMechanicStageElement{
|
||||||
pub mode_id:u32,
|
pub mode_id:u32,
|
||||||
pub stage_id:u32,//which spawn to send to
|
pub stage_id:u32,//which spawn to send to
|
||||||
pub force:bool,//allow setting to lower spawn id i.e. 7->3
|
pub force:bool,//allow setting to lower spawn id i.e. 7->3
|
||||||
pub behaviour:StageElementBehaviour
|
pub behaviour:StageElementBehaviour
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct GameMechanicWormhole{
|
pub struct GameMechanicWormhole{
|
||||||
//destination does not need to be another wormhole
|
//destination does not need to be another wormhole
|
||||||
//this defines a one way portal to a destination model transform
|
//this defines a one way portal to a destination model transform
|
||||||
@ -192,17 +202,16 @@ pub struct GameMechanicWormhole{
|
|||||||
pub destination_model_id:u32,
|
pub destination_model_id:u32,
|
||||||
//(position,angles)*=origin.transform.inverse()*destination.transform
|
//(position,angles)*=origin.transform.inverse()*destination.transform
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone,Hash,Eq,PartialEq)]
|
||||||
pub enum TeleportBehaviour{
|
pub enum TeleportBehaviour{
|
||||||
StageElement(GameMechanicStageElement),
|
StageElement(GameMechanicStageElement),
|
||||||
Wormhole(GameMechanicWormhole),
|
Wormhole(GameMechanicWormhole),
|
||||||
}
|
}
|
||||||
//attributes listed in order of handling
|
//attributes listed in order of handling
|
||||||
#[derive(Default,Clone)]
|
#[derive(Default,Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct GameMechanicAttributes{
|
pub struct GameMechanicAttributes{
|
||||||
pub zone:Option<GameMechanicZone>,
|
pub zone:Option<GameMechanicZone>,
|
||||||
pub booster:Option<GameMechanicBooster>,
|
pub booster:Option<GameMechanicBooster>,
|
||||||
pub checkpoint:Option<GameMechanicCheckpoint>,
|
|
||||||
pub trajectory:Option<GameMechanicSetTrajectory>,
|
pub trajectory:Option<GameMechanicSetTrajectory>,
|
||||||
pub teleport_behaviour:Option<TeleportBehaviour>,
|
pub teleport_behaviour:Option<TeleportBehaviour>,
|
||||||
pub accelerator:Option<GameMechanicAccelerator>,
|
pub accelerator:Option<GameMechanicAccelerator>,
|
||||||
@ -211,13 +220,26 @@ impl GameMechanicAttributes{
|
|||||||
pub fn any(&self)->bool{
|
pub fn any(&self)->bool{
|
||||||
self.zone.is_some()
|
self.zone.is_some()
|
||||||
||self.booster.is_some()
|
||self.booster.is_some()
|
||||||
||self.checkpoint.is_some()
|
|
||||||
||self.trajectory.is_some()
|
||self.trajectory.is_some()
|
||||||
||self.teleport_behaviour.is_some()
|
||self.teleport_behaviour.is_some()
|
||||||
||self.accelerator.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)]
|
#[derive(Default,Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct ContactingAttributes{
|
pub struct ContactingAttributes{
|
||||||
//friction?
|
//friction?
|
||||||
pub contact_behaviour:Option<ContactingBehaviour>,
|
pub contact_behaviour:Option<ContactingBehaviour>,
|
||||||
@ -227,7 +249,7 @@ impl ContactingAttributes{
|
|||||||
self.contact_behaviour.is_some()
|
self.contact_behaviour.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[derive(Default,Clone)]
|
#[derive(Default,Clone,Hash,Eq,PartialEq)]
|
||||||
pub struct IntersectingAttributes{
|
pub struct IntersectingAttributes{
|
||||||
pub water:Option<IntersectingWater>,
|
pub water:Option<IntersectingWater>,
|
||||||
}
|
}
|
||||||
@ -237,6 +259,7 @@ impl IntersectingAttributes{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Spawn(u32) NO! spawns are indexed in the map header instead of marked with attibutes
|
//Spawn(u32) NO! spawns are indexed in the map header instead of marked with attibutes
|
||||||
|
//TODO: deduplicate attributes
|
||||||
pub enum CollisionAttributes{
|
pub enum CollisionAttributes{
|
||||||
Decoration,//visual only
|
Decoration,//visual only
|
||||||
Contact{//track whether you are contacting the object
|
Contact{//track whether you are contacting the object
|
||||||
|
@ -1 +1,766 @@
|
|||||||
//
|
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);
|
||||||
|
}
|
1129
src/physics.rs
1129
src/physics.rs
File diff suppressed because it is too large
Load Diff
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
//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
|
|
||||||
}
|
|
||||||
}
|
|
@ -177,8 +177,8 @@ impl<'a,Task:Send+'a> INWorker<'a,Task>{
|
|||||||
fn test_worker() {
|
fn test_worker() {
|
||||||
println!("hiiiii");
|
println!("hiiiii");
|
||||||
// Create the worker thread
|
// Create the worker thread
|
||||||
let worker=QRWorker::new(crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO,crate::integer::Planar64Vec3::ZERO),
|
let worker=QRWorker::new(crate::physics::Body::default(),
|
||||||
|_|crate::physics::Body::with_pva(crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE)
|
|_|crate::physics::Body::new(crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Planar64Vec3::ONE,crate::integer::Time::ZERO)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Send tasks to the worker
|
// Send tasks to the worker
|
||||||
@ -194,7 +194,7 @@ fn test_worker() {
|
|||||||
// sender.send("STOP".to_string()).unwrap();
|
// sender.send("STOP".to_string()).unwrap();
|
||||||
|
|
||||||
// Sleep to allow the worker thread to finish processing
|
// Sleep to allow the worker thread to finish processing
|
||||||
thread::sleep(std::time::Duration::from_secs(2));
|
thread::sleep(std::time::Duration::from_millis(10));
|
||||||
|
|
||||||
// Send a new task
|
// Send a new task
|
||||||
let task = crate::instruction::TimedInstruction{
|
let task = crate::instruction::TimedInstruction{
|
||||||
@ -206,5 +206,5 @@ fn test_worker() {
|
|||||||
println!("value={}",worker.grab_clone());
|
println!("value={}",worker.grab_clone());
|
||||||
|
|
||||||
// wait long enough to see print from final task
|
// wait long enough to see print from final task
|
||||||
thread::sleep(std::time::Duration::from_secs(1));
|
thread::sleep(std::time::Duration::from_millis(10));
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,12 @@ pub fn zeroes2(a0:Planar64,a1:Planar64,a2:Planar64) -> Vec<Planar64>{
|
|||||||
//start with f64 sqrt
|
//start with f64 sqrt
|
||||||
let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()});
|
let planar_radicand=Planar64::raw(unsafe{(radicand as f64).sqrt().to_int_unchecked()});
|
||||||
//TODO: one or two newtons
|
//TODO: one or two newtons
|
||||||
if Planar64::ZERO<a2 {
|
//sort roots ascending and avoid taking the difference of large numbers
|
||||||
return vec![(-a1-planar_radicand)/(a2*2),(-a1+planar_radicand)/(a2*2)];
|
match (Planar64::ZERO<a2,Planar64::ZERO<a1){
|
||||||
} else {
|
(true, true )=>vec![(-a1-planar_radicand)/(a2*2),(a0*2)/(-a1-planar_radicand)],
|
||||||
return vec![(-a1+planar_radicand)/(a2*2),(-a1-planar_radicand)/(a2*2)];
|
(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)],
|
||||||
}
|
}
|
||||||
} else if radicand==0 {
|
} else if radicand==0 {
|
||||||
return vec![a1/(a2*-2)];
|
return vec![a1/(a2*-2)];
|
||||||
|
Loading…
Reference in New Issue
Block a user