Struct Plane

Source
#[repr(C)]
pub struct Plane { pub normal: Vec3, pub d: f32, }
Expand description

Planes are really useful for collisions, intersections, and visibility testing!

This plane is stored using the ax + by + cz + d = 0 formula, where the normal is a,b,c, and the d is, well, d. https://stereokit.net/Pages/StereoKit/Plane.html

§Examples

use stereokit_rust::{maths::{Vec3, Matrix, Plane},
                     mesh::Mesh, material::Material, util::named_colors};

let plane_mesh = Mesh::generate_plane_up([1.0,1.0], None, true);
let mut material_plane = Material::pbr();

let transform_wall = Matrix::t_r([-0.5, 0.0, 0.0],
                                 [0.0, 0.0, 90.0]);
let transform_floor = Matrix::t([0.0, -0.5, 0.0]);

let wall =   Plane::new (Vec3::X, 0.5);
let wall_b = Plane::from_point( [-0.5, -1.1, -1.1].into(), Vec3::X);
let wall_c = Plane::from_points([-0.5, -2.2, -2.2],
                                [-0.5, -3.3, -3.3],
                                [-0.5, -4.4, -14.4]);

assert_eq!(wall.closest(Vec3::Y), Vec3 {x:-0.5, y:1.0, z:0.0});
assert_eq!(wall_b.closest(Vec3::Y), Vec3 {x:-0.5, y:1.0, z:0.0});
assert_eq!(wall_c.closest(Vec3::Y), Vec3 {x:-0.5, y:1.0, z:0.0});
assert_eq!(wall, wall_b);
//assert_eq!(wall, wall_c); // differents but the same

filename_scr = "screenshots/plane.jpeg";
test_screenshot!( // !!!! Get a proper main loop !!!!
    plane_mesh.draw(token, &material_plane, transform_wall, Some(named_colors::CYAN.into()), None);
    plane_mesh.draw(token, &material_plane, transform_floor, Some(named_colors::BLACK.into()), None);
);
screenshot

Fields§

§normal: Vec3

The direction the plane is facing.

§d: f32

The distance/travel along the plane’s normal from the origin to the surface of the plane.

Implementations§

Source§

impl Plane

Source

pub fn new<V: Into<Vec3>>(normal: V, d: f32) -> Plane

Creates a Plane directly from the ax + by + cz + d = 0 formula! https://stereokit.net/Pages/StereoKit/Plane/Plane.html

Source

pub fn from_point<V: Into<Vec3>>(point_on_plane: V, plane_normal: V) -> Plane

Creates a plane from a normal, and any point on the plane! https://stereokit.net/Pages/StereoKit/Plane/Plane.html

§Examples
use stereokit_rust::maths::{Plane,Vec3};
let wall_x = Plane::from_point(Vec3::X*4.0,  Vec3::X);
assert_eq!(wall_x.d , -4.0);
Source

pub fn from_points<V: Into<Vec3>>( point_on_plane1: V, point_on_plane2: V, point_on_plane3: V, ) -> Plane

👎Deprecated since 0.4.0: Unstable! use Plane::from_point or Plane::new instead

Creates a plane from 3 points that are directly on that plane. Unstable as some normal with NaN values may be created if the points are aligned.

https://stereokit.net/Pages/StereoKit/Plane/Plane.html

§Examples
use stereokit_rust::maths::{Plane,Vec3};
let ground = Plane::from_points([1.0, 1.5, 0.0],
                                [0.0, 1.5, 1.0],
                                [1.0, 1.5, 1.0]);
assert_eq!(ground.d , 1.5);
assert!(ground.normal.y + 1.0 < 0.0001);

let wall_c = Plane::from_points([-0.5, -0.4, -1.0],
                                [-0.5, 0.0, 3.0],
                                [-0.5, 0.3, -4.0]);
println! ("{:?}", wall_c);
assert_eq!(wall_c.d , 0.5);
assert!(wall_c.normal.x - 1.0 < 0.0001);
Source

pub fn closest<V: Into<Vec3>>(&self, to: V) -> Vec3

Finds the closest point on this plane to the given point! https://stereokit.net/Pages/StereoKit/Plane/Closest.html

see also plane_point_closest

§Examples
use stereokit_rust::maths::{Plane,Vec3};
let plane = Plane{normal : Vec3::X , d: -4.0};
let closest = plane.closest(Vec3::ZERO);
assert_eq!(closest , (Vec3::X * 4.0));
let plane = Plane::from_points(Vec3::X , Vec3::Z, Vec3::Y );
assert_eq!(plane, Plane{normal : Vec3::ONE / (3.0_f32.sqrt()), d:-1.0/3.0_f32.sqrt()} );
let closest = plane.closest(Vec3::ZERO);
assert_eq!(closest , Vec3::new(0.3333333,0.3333333,0.3333333));
Source

pub fn intersect(&self, ray: Ray) -> Option<Vec3>

Checks the intersection of a ray with this plane! https://stereokit.net/Pages/StereoKit/Plane/Intersect.html

  • ray - The ray we’re checking with.

Returns the intersection point or None if there isn’t an instersection see also plane_ray_intersect same as Ray::intersect_plane

Source

pub fn intersect_line<V: Into<Vec3>>( &self, line_start: V, line_end: V, ) -> Option<Vec3>

Checks the intersection of a line with this plane! https://stereokit.net/Pages/StereoKit/Plane/Intersect.html

  • line_start - Start of the line.
  • line_end - End of the line.

Returns the intersection point or None if there isn’t an instersection see also plane_line_intersect

Trait Implementations§

Source§

impl AsRef<Plane> for Plane

AsRef

Source§

fn as_ref(&self) -> &Plane

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Plane

Source§

fn clone(&self) -> Plane

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Plane

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Plane

Source§

fn default() -> Plane

Returns the “default value” for a type. Read more
Source§

impl Display for Plane

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Creates a text description of the Plane, in the format of “[normal:X distance:X]”

§Examples
use stereokit_rust::maths::{Vec3, Plane};

let plane = Plane::new([1.1, 2.0, 3.0], 4.0);
assert_eq!(format!("{}", plane),
           "[normal:[x:1.1, y:2, z:3] distance:4]");
Source§

impl PartialEq for Plane

Warning: Equality with a precision of 0.1 millimeter

Source§

fn eq(&self, other: &Self) -> bool

Warning: Equality with a precision of 0.1 millimeter

1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Plane

Auto Trait Implementations§

§

impl Freeze for Plane

§

impl RefUnwindSafe for Plane

§

impl Send for Plane

§

impl Sync for Plane

§

impl Unpin for Plane

§

impl UnwindSafe for Plane

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more