collision hit point result coordinate fix
This commit is contained in:
parent
6d26f3f416
commit
471ce62c35
|
@ -720,6 +720,7 @@ pub fn sphere_obb_intersection(
|
|||
None
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OctTreeCollisionPoint {
|
||||
pos_in_oct: Vec3,
|
||||
pos_in_global: Vec3,
|
||||
|
@ -811,6 +812,7 @@ fn visitor_octtree_x_octtree<T: Clone>(
|
|||
);
|
||||
}
|
||||
} else {
|
||||
// special case for roots being leaves
|
||||
if first_node.is_leaf() && second_node.is_leaf() {
|
||||
// do an intersection on them with OBBxOBB
|
||||
let x = first_trans.as_transform().transform_point(first_pos);
|
||||
|
@ -819,11 +821,11 @@ fn visitor_octtree_x_octtree<T: Clone>(
|
|||
obb1.half_size = y;
|
||||
obb1.position = x;
|
||||
|
||||
let a = second_trans.as_transform().transform_point(first_pos);
|
||||
let a = second_trans.as_transform().transform_point(second_pos);
|
||||
let b = second_trans.half_size * second_size as f32;
|
||||
let mut obb2 = second_trans.clone();
|
||||
obb2.half_size = a;
|
||||
obb2.position = b;
|
||||
obb2.half_size = b;
|
||||
obb2.position = a;
|
||||
let res = obb_obb_overlap(&obb1, &obb2);
|
||||
if res {
|
||||
// well,
|
||||
|
@ -846,11 +848,11 @@ fn visitor_octtree_x_octtree<T: Clone>(
|
|||
if first_el.is_some() && second_el.is_some() {
|
||||
for (first_count, first_iter) in first_el.unwrap().iter().enumerate() {
|
||||
for (second_count, second_iter) in second_el.unwrap().iter().enumerate() {
|
||||
let (first_center, first_bound) =
|
||||
constants::sub_region(first_pos, first_size, first_count as i32);
|
||||
let (second_center, second_bound) =
|
||||
constants::sub_region(second_pos, second_size, second_count as i32);
|
||||
if first_iter.is_branch() && second_iter.is_branch() {
|
||||
let (first_center, first_bound) =
|
||||
constants::sub_region(first_pos, first_size, first_count as i32);
|
||||
let (second_center, second_bound) =
|
||||
constants::sub_region(second_pos, second_size, second_count as i32);
|
||||
let (first_sa_center, first_sa_radius) =
|
||||
obb_to_global_sphere(first_center, first_bound, first_trans);
|
||||
let (second_sa_center, second_sa_radius) =
|
||||
|
@ -876,27 +878,23 @@ fn visitor_octtree_x_octtree<T: Clone>(
|
|||
}
|
||||
} else if first_iter.is_leaf() && second_iter.is_leaf() {
|
||||
// do an intersection on them with OBBxOBB
|
||||
let x = first_trans.as_transform().transform_point(first_pos);
|
||||
let y = first_trans.half_size * first_size as f32;
|
||||
let mut obb1 = first_trans.clone();
|
||||
obb1.half_size = y;
|
||||
obb1.position = x;
|
||||
obb1.position = first_trans.as_transform().transform_point(first_center);
|
||||
|
||||
let a = second_trans.as_transform().transform_point(first_pos);
|
||||
let b = second_trans.half_size * second_size as f32;
|
||||
let mut obb2 = second_trans.clone();
|
||||
obb2.half_size = a;
|
||||
obb2.position = b;
|
||||
obb2.position = second_trans.as_transform().transform_point(second_center);
|
||||
|
||||
let res = obb_obb_overlap(&obb1, &obb2);
|
||||
if res {
|
||||
println!("adding collision");
|
||||
// well,
|
||||
let half1 = OctTreeCollisionPoint {
|
||||
pos_in_oct: first_pos,
|
||||
pos_in_oct: first_center,
|
||||
pos_in_global: obb1.position,
|
||||
path: Default::default(),
|
||||
};
|
||||
let half2 = OctTreeCollisionPoint {
|
||||
pos_in_oct: second_pos,
|
||||
pos_in_oct: second_center,
|
||||
pos_in_global: obb2.position,
|
||||
path: Default::default(),
|
||||
};
|
||||
|
@ -1268,6 +1266,25 @@ pub fn test_oct_x_oct_collisions() {
|
|||
&OBB::new(Vec3::ZERO, Quat::IDENTITY, Vec3::ONE / 2.),
|
||||
);
|
||||
assert!(x.is_some());
|
||||
|
||||
let mut oct1 = OctTree::new(Vec3::splat(1.), 10);
|
||||
oct1.set_voxel_at_location(Vec3::new(1., 0., 1.), 1);
|
||||
let mut oct2 = OctTree::new(Vec3::splat(0.), 10);
|
||||
oct2.set_voxel_at_location(Vec3::new(0., 1., 0.), 1);
|
||||
|
||||
let x = octtree_overlap(
|
||||
&oct1,
|
||||
&OBB::new(Vec3::ZERO, Quat::IDENTITY, Vec3::ONE / 2.),
|
||||
&oct2,
|
||||
&OBB::new(
|
||||
Vec3::ZERO,
|
||||
Quat::from_rotation_x(f32::to_radians(45.)),
|
||||
Vec3::ONE / 2.,
|
||||
),
|
||||
);
|
||||
assert!(x.is_some());
|
||||
dbg!(&x.unwrap());
|
||||
panic!();
|
||||
}
|
||||
/*
|
||||
use rand::Rng;
|
||||
|
|
Loading…
Reference in a new issue