#[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);
);

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
impl Plane
Sourcepub fn new<V: Into<Vec3>>(normal: V, d: f32) -> Plane
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
Sourcepub fn from_point<V: Into<Vec3>>(point_on_plane: V, plane_normal: V) -> Plane
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);
Sourcepub 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
pub fn from_points<V: Into<Vec3>>( point_on_plane1: V, point_on_plane2: V, point_on_plane3: V, ) -> Plane
Plane::from_point
or Plane::new
insteadCreates 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);
Sourcepub fn closest<V: Into<Vec3>>(&self, to: V) -> Vec3
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));
Sourcepub fn intersect(&self, ray: Ray) -> Option<Vec3>
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
Sourcepub fn intersect_line<V: Into<Vec3>>(
&self,
line_start: V,
line_end: V,
) -> Option<Vec3>
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 Display for Plane
impl Display for Plane
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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]");