[][src]Struct obscura::Sphere

pub struct Sphere { /* fields omitted */ }

A sphere primitive.


impl Sphere[src]

pub fn new(origin: &Vec3, radius: f32) -> Sphere[src]

Create a new Sphere.


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


use obscura::{Sphere, Vec3, Ray, RayIntersection, Intersect};
let origin = Vec3::zero();
let target: Sphere = Sphere::new(
    &Vec3::new(2.0, 0.0, 0.0),
// A ray that intersects the sphere twice.
let ray1: Ray = Ray::new(
    &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(
    &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>, 

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Any for T where
    T: 'static + ?Sized