use glam::{Vec2, Vec3};
use symbios_ground::HeightMap;
pub struct TensorField<'a> {
pub(crate) heightmap: &'a HeightMap,
}
impl<'a> TensorField<'a> {
pub fn new(heightmap: &'a HeightMap) -> Self {
Self { heightmap }
}
pub fn sample(&self, world_x: f32, world_z: f32) -> (Vec2, Vec2) {
let n_arr = self.heightmap.get_normal_at(world_x, world_z);
let normal = Vec3::from_array(n_arr);
let minor = Vec2::new(normal.x, normal.z);
if minor.length_squared() < 1e-5 {
return (Vec2::new(1.0, 0.0), Vec2::new(0.0, 1.0));
}
let minor = minor.normalize();
let major = Vec2::new(-minor.y, minor.x);
(major, minor)
}
}