Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
use direct nalgebra conversions instead of mint for the collision code
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsairobo committed Dec 4, 2020
1 parent f9106fa commit 455ecd8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
3 changes: 1 addition & 2 deletions crates/building_blocks_search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ description = "Search algorithms for voxel data."
[features]
default = []

ncollide = ["mint", "nalgebra", "ncollide3d", "building_blocks_core/mint"]
ncollide = ["nalgebra", "ncollide3d", "building_blocks_core/nalgebra"]

[dependencies]
fnv = "1.0"
indexmap = "1.5"
itertools = "0.9"

# Optional, feature-gated
mint = { version = "0.5", optional = true }
nalgebra = { version = "0.23", optional = true, features = ["mint"] }
ncollide3d = { version = "0.26", optional = true }

Expand Down
11 changes: 4 additions & 7 deletions crates/building_blocks_search/src/collision.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
na_conversions::na_point3f_from_point3i,
octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor},
};
use crate::octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor};

use building_blocks_core::prelude::*;
use building_blocks_storage::octree::{Octant, VisitStatus};
Expand Down Expand Up @@ -272,7 +269,7 @@ fn impact_with_leaf_octant(
// land in the correct voxel. It should help to nudge the point along the
// intersection normal by some amount less than 1.0.
const NUDGE_AMOUNT: f32 = 0.25;
let nudged_p: mint::Point3<f32> = (contact - NUDGE_AMOUNT * octant_normal).into();
let nudged_p = contact - NUDGE_AMOUNT * octant_normal;

Point3f::from(nudged_p).in_voxel()
}
Expand All @@ -283,14 +280,14 @@ fn extent3i_cuboid(e: &Extent3i) -> Cuboid<f32> {
}

fn extent3i_cuboid_transform(e: &Extent3i) -> Isometry3<f32> {
let min = na_point3f_from_point3i(e.minimum);
let min = na::Point3::from(Point3f::from(e.minimum));
let center = min + half_extent(e.shape);

Isometry3::new(center.coords, zero())
}

fn half_extent(shape: Point3i) -> na::Vector3<f32> {
na_point3f_from_point3i(shape).coords / 2.0
na::Vector3::from(Point3f::from(shape)) / 2.0
}

// ████████╗███████╗███████╗████████╗
Expand Down
10 changes: 0 additions & 10 deletions crates/building_blocks_search/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,3 @@ pub use octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor};

#[cfg(feature = "ncollide")]
pub use ncollide3d;

#[cfg(feature = "ncollide")]
mod na_conversions {
use building_blocks_core::{Point3f, Point3i};
use nalgebra as na;

pub fn na_point3f_from_point3i(p: Point3i) -> na::Point3<f32> {
mint::Point3::from(Point3f::from(p)).into()
}
}
6 changes: 3 additions & 3 deletions crates/building_blocks_search/src/octree_dbvt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
use building_blocks_core::prelude::*;
use building_blocks_storage::octree::{Octant, OctreeSet, OctreeVisitor, VisitStatus};

use crate::na_conversions::na_point3f_from_point3i;
use core::hash::Hash;
use fnv::FnvHashMap;
use ncollide3d::{
bounding_volume::AABB,
na,
partitioning::{self as nc_part, DBVTLeaf, DBVTLeafId, BVH, DBVT},
};

Expand Down Expand Up @@ -99,8 +99,8 @@ pub trait OctreeDBVTVisitor {
}

pub fn octant_aabb(octant: &Octant) -> AABB<f32> {
let aabb_min = na_point3f_from_point3i(octant.minimum);
let aabb_max = na_point3f_from_point3i(octant.minimum + PointN([octant.edge_length; 3]));
let aabb_min = Point3f::from(octant.minimum).into();
let aabb_max = Point3f::from(octant.minimum + PointN([octant.edge_length; 3])).into();

AABB::new(aabb_min, aabb_max)
}

0 comments on commit 455ecd8

Please sign in to comment.