pub fn convert(map: Vec<Vec<f32>>, scale: f32) -> Vec<Vec<(f32, f32, f32)>> {
    let mut normals: Vec<Vec<(f32, f32, f32)>> =
        vec![vec![(0.0, 0.0, 0.0); map[0].len() as usize]; map.len() as usize];
    let mut n: Vector3f = Vector3f::new(0.0, 0.0, 0.0);
    let mut arr;

    for i in 0..map.len() {
        for j in 0..map[0].len() {
            arr = neighbours(&map, (i as i32, j as i32));
            n.x = scale
                * -(arr[8 as usize] - arr[6 as usize]
                    + 2.0 * (arr[5 as usize] - arr[3 as usize])
                    + arr[2 as usize]
                    - arr[0 as usize]);
            n.y = scale
                * -(arr[0 as usize] - arr[6 as usize]
                    + 2.0 * (arr[1 as usize] - arr[7 as usize])
                    + arr[2 as usize]
                    - arr[8 as usize]);
            n.z = 1.0;
            n = n.normalize();
            normals[i as usize][j as usize] = (n.x, n.y, n.z);
        }
    }
    normals
}
/// Converts a height map into a normal map
Converts a height map into a normal map
Converts a height map into a normal map
pub fn convert(map: Vec<Vec<f32>>, scale: f32) -> Vec<Vec<(f32, f32, f32)>> {
    let mut normals: Vec<Vec<(f32, f32, f32)>> =
        vec![vec![(0.0, 0.0, 0.0); map[0].len() as usize]; map.len() as usize];
    let mut n: Vector3f = Vector3f::new(0.0, 0.0, 0.0);
    let mut arr;
    for i in 0..map.len() {
        for j in 0..map[0].len() {
            arr = neighbours(&map, (i as i32, j as i32));
            n.x = scale
                * -(arr[8 as usize] - arr[6 as usize]
                    + 2.0 * (arr[5 as usize] - arr[3 as usize])
                    + arr[2 as usize]
                    - arr[0 as usize]);
            n.y = scale
                * -(arr[0 as usize] - arr[6 as usize]
                    + 2.0 * (arr[1 as usize] - arr[7 as usize])
                    + arr[2 as usize]
                    - arr[8 as usize]);
            n.z = 1.0;
            n = n.normalize();
            normals[i as usize][j as usize] = (n.x, n.y, n.z);
        }
    }
    normals
}
pub fn convert ( map : Vec < Vec < f32 > > , scale : f32 ) -> Vec < Vec < ( f32 , f32 , f32 ) > > { let mut normals : Vec < Vec < ( f32 , f32 , f32 ) > > = vec ! [ vec [ ( 0.0 0.0 0.0 ) map [ 0 ] len ( ) as usize ] map len ( ) as usize ] ; let mut n : Vector3f = Vector3f :: new ( 0.0 , 0.0 , 0.0 ) ; let mut arr ; for i in 0 .. map . len ( ) { for j in 0 .. map [ 0 ] . len ( ) { arr = neighbours ( & map , ( i as i32 , j as i32 ) ) ; n . x = scale * - ( arr [ 8 as usize ] - arr [ 6 as usize ] + 2.0 * ( arr [ 5 as usize ] - arr [ 3 as usize ] ) + arr [ 2 as usize ] - arr [ 0 as usize ] ) ; n . y = scale * - ( arr [ 0 as usize ] - arr [ 6 as usize ] + 2.0 * ( arr [ 1 as usize ] - arr [ 7 as usize ] ) + arr [ 2 as usize ] - arr [ 8 as usize ] ) ; n . z = 1.0 ; n = n . normalize ( ) ; normals [ i as usize ] [ j as usize ] = ( n . x , n . y , n . z ) ; } } normals }
Converts a height map into a normal map
Converts a height map into a normal map
map
Vec<Vec<f32>>
scale
f32