pub fn draw_scanline(&mut self, a:f32, b:f32, aZ:f32, bZ:f32, y:i32, c1:Vec3f, c2:Vec3f) {
        let (mut min, mut max): (i32, i32);
        if a > b { min = (b-EPS).round() as i32; max = (a+EPS).round() as i32; }
        else { min = (a-EPS).round() as i32; max = (b+EPS).round() as i32; }
        min = min.max(0);
        max = max.min(WIDTH as i32);
        for x in min..max {
            let inter = (x as f32 - a) / (b - a);
            let c = Vec3f::lerp(c1, c2, inter);
            let z = lerp(aZ, bZ, inter);

            // Z-buffering
            if z < self.depth_buffer[(y * WIDTH as i32 + x) as usize] { continue; }

            self.d[(y * WIDTH as i32 + x) as usize].0 = (z / 2. *255.0) as u8;
            self.d[(y * WIDTH as i32 + x) as usize].1 = (z / 2. *255.0) as u8;
            self.d[(y * WIDTH as i32 + x) as usize].2 = (z / 2. *255.0) as u8;
            self.depth_buffer[(y * WIDTH as i32 + x) as usize] = z;
        }
    }
/// Draw a horizontal line at row y between points a and b
Draw a horizontal line at row y between points a and b
Draw a horizontal line at row y between points a and b
pub fn draw_scanline(&mut self, a:f32, b:f32, aZ:f32, bZ:f32, y:i32, c1:Vec3f, c2:Vec3f) {
        let (mut min, mut max): (i32, i32);
        if a > b { min = (b-EPS).round() as i32; max = (a+EPS).round() as i32; }
        else { min = (a-EPS).round() as i32; max = (b+EPS).round() as i32; }
        min = min.max(0);
        max = max.min(WIDTH as i32);
        for x in min..max {
            let inter = (x as f32 - a) / (b - a);
            let c = Vec3f::lerp(c1, c2, inter);
            let z = lerp(aZ, bZ, inter);
            // Z-buffering
            if z < self.depth_buffer[(y * WIDTH as i32 + x) as usize] { continue; }
            self.d[(y * WIDTH as i32 + x) as usize].0 = (z / 2. *255.0) as u8;
            self.d[(y * WIDTH as i32 + x) as usize].1 = (z / 2. *255.0) as u8;
            self.d[(y * WIDTH as i32 + x) as usize].2 = (z / 2. *255.0) as u8;
            self.depth_buffer[(y * WIDTH as i32 + x) as usize] = z;
        }
    }
pub fn draw_scanline ( & mut self , a : f32 , b : f32 , aZ : f32 , bZ : f32 , y : i32 , c1 : Vec3f , c2 : Vec3f ) { let ( mut min , mut max ) : ( i32 , i32 ) ; if a > b { min = ( b - EPS ) . round ( ) as i32 ; max = ( a + EPS ) . round ( ) as i32 ; } else { min = ( a - EPS ) . round ( ) as i32 ; max = ( b + EPS ) . round ( ) as i32 ; } min = min . max ( 0 ) ; max = max . min ( WIDTH as i32 ) ; for x in min .. max { let inter = ( x as f32 - a ) / ( b - a ) ; let c = Vec3f :: lerp ( c1 , c2 , inter ) ; let z = lerp ( aZ , bZ , inter ) ; // Z-buffering if z < self . depth_buffer [ ( y * WIDTH as i32 + x ) as usize ] { continue ; } self . d [ ( y * WIDTH as i32 + x ) as usize ] . 0 = ( z / 2. * 255.0 ) as u8 ; self . d [ ( y * WIDTH as i32 + x ) as usize ] . 1 = ( z / 2. * 255.0 ) as u8 ; self . d [ ( y * WIDTH as i32 + x ) as usize ] . 2 = ( z / 2. * 255.0 ) as u8 ; self . depth_buffer [ ( y * WIDTH as i32 + x ) as usize ] = z ; } }
Draw a horizontal line at row y between points a and b
Draw a horizontal line at row y between points a and b
&mut self
a
f32
b
f32
aZ
f32
bZ
f32
y
i32
c1
Vec3f
c2
Vec3f
&mut self
a
f32
b
f32
aZ
f32
bZ
f32
y
i32
c1
Vec3f
c2
Vec3f