[−][src]Struct obscura::Sphere
A sphere primitive.
Methods
impl Sphere
[src]
pub fn new(origin: &Vec3, radius: f32) -> Sphere
[src]
Create a new Sphere.
Examples
use obscura::{Sphere, Vec3}; let origin = Vec3::zero(); let x = Sphere::new(&origin, 1.0);
Trait Implementations
impl Intersect for Sphere
[src]
fn intersect(&self, ray: &Ray) -> RayIntersection
[src]
Intersect ray with sphere. Return t or t1,t2 where intersection point p = ray.origin + t * ray.direction
Examples
use obscura::{Sphere, Vec3, Ray, RayIntersection, Intersect}; let origin = Vec3::zero(); let target: Sphere = Sphere::new( &Vec3::new(2.0, 0.0, 0.0), 1.0 ); // A ray that intersects the sphere twice. let ray1: Ray = Ray::new( &origin, &Vec3::new(1.0, 0.0, 0.0) ); if let RayIntersection::Hit(t1, t2) = Sphere::intersect(&target, &ray1) { assert_eq!(t1, 1.0); assert_eq!(t2, 3.0); } else { panic!("Oh no!"); } // A ray which never intersects the sphere. let ray2: Ray = Ray::new( &origin, &Vec3::new(0.0, 0.0, 1.0) ); let result = Sphere::intersect(&target, &ray2); assert_eq!(result, RayIntersection::Miss);
Auto Trait Implementations
impl Send for Sphere
impl Sync for Sphere
impl Unpin for Sphere
impl UnwindSafe for Sphere
impl RefUnwindSafe for Sphere
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,