Implemented Bound for Sphere
This commit is contained in:
parent
e71887a848
commit
2722815d84
1 changed files with 14 additions and 0 deletions
14
src/bound.rs
14
src/bound.rs
|
@ -19,6 +19,7 @@ use aabb::{Aabb, Aabb3};
|
||||||
use num::BaseNum;
|
use num::BaseNum;
|
||||||
use plane::Plane;
|
use plane::Plane;
|
||||||
use point::{Point, Point3};
|
use point::{Point, Point3};
|
||||||
|
use sphere::Sphere;
|
||||||
|
|
||||||
/// Spatial relation between two objects.
|
/// Spatial relation between two objects.
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
|
@ -58,3 +59,16 @@ impl<S: BaseNum> Bound<S> for Aabb3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S: BaseNum> Bound<S> for Sphere<S> {
|
||||||
|
fn relate(&self, plane: &Plane<S>) -> Relation {
|
||||||
|
let dist = self.center.dot(&plane.n) - plane.d;
|
||||||
|
if dist > self.radius {
|
||||||
|
Relation::In
|
||||||
|
}else if dist < - self.radius {
|
||||||
|
Relation::Out
|
||||||
|
}else {
|
||||||
|
Relation::Cross
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue