pub struct HeightField {
pub heights: Vec<Fix128>,
pub width: u32,
pub depth: u32,
pub spacing: Fix128,
pub origin: Vec3Fix,
}Expand description
Height field terrain collider
Heights stored as a 2D grid in row-major order (Z-major):
index = x + z * width
Fields§
§heights: Vec<Fix128>Height values (Fix128)
width: u32Grid width (number of columns, X axis)
depth: u32Grid depth (number of rows, Z axis)
spacing: Fix128World-space spacing between grid points
origin: Vec3FixWorld-space origin (min corner)
Implementations§
Source§impl HeightField
impl HeightField
Sourcepub fn new(
heights: Vec<Fix128>,
width: u32,
depth: u32,
spacing: Fix128,
origin: Vec3Fix,
) -> Self
pub fn new( heights: Vec<Fix128>, width: u32, depth: u32, spacing: Fix128, origin: Vec3Fix, ) -> Self
Create a height field from a grid of heights
Sourcepub fn flat(
width: u32,
depth: u32,
spacing: Fix128,
origin: Vec3Fix,
height: Fix128,
) -> Self
pub fn flat( width: u32, depth: u32, spacing: Fix128, origin: Vec3Fix, height: Fix128, ) -> Self
Create a flat height field at a given Y level
Sourcepub fn get_height(&self, gx: u32, gz: u32) -> Fix128
pub fn get_height(&self, gx: u32, gz: u32) -> Fix128
Get height at grid coordinates (clamped to bounds)
Sourcepub fn set_height(&mut self, gx: u32, gz: u32, height: Fix128)
pub fn set_height(&mut self, gx: u32, gz: u32, height: Fix128)
Set height at grid coordinates
Sourcepub fn sample_height(&self, world_x: Fix128, world_z: Fix128) -> Fix128
pub fn sample_height(&self, world_x: Fix128, world_z: Fix128) -> Fix128
Sample height at world-space XZ with bilinear interpolation
Sourcepub fn sample_normal(&self, world_x: Fix128, world_z: Fix128) -> Vec3Fix
pub fn sample_normal(&self, world_x: Fix128, world_z: Fix128) -> Vec3Fix
Compute surface normal at world-space XZ via central difference
Sourcepub fn collide_sphere(&self, center: Vec3Fix, radius: Fix128) -> Option<Contact>
pub fn collide_sphere(&self, center: Vec3Fix, radius: Fix128) -> Option<Contact>
Sphere vs HeightField collision
The sphere is clear of the surface when its centre is at least radius
away along the surface normal — the distance to the tangent plane, which
is Δy · n_y for a centre Δy above the surface point below it. (Measuring
Δy itself, as this used to, buries a sphere on a slope by r·(1/cosθ − 1).)
A field with no grid points, or a non-positive spacing, has no surface.
Sourcepub fn signed_distance(&self, point: Vec3Fix) -> Fix128
pub fn signed_distance(&self, point: Vec3Fix) -> Fix128
Point vs HeightField: get signed distance (positive = above)
Trait Implementations§
Source§impl Clone for HeightField
impl Clone for HeightField
Source§impl Debug for HeightField
impl Debug for HeightField
impl Eq for HeightField
Source§impl PartialEq for HeightField
impl PartialEq for HeightField
impl StructuralPartialEq for HeightField
Auto Trait Implementations§
impl Freeze for HeightField
impl RefUnwindSafe for HeightField
impl Send for HeightField
impl Sync for HeightField
impl Unpin for HeightField
impl UnsafeUnpin for HeightField
impl UnwindSafe for HeightField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more