mirror of
https://github.com/stickynotememo/wolf_renderer.git
synced 2026-07-30 06:46:03 +10:00
its a triangle
This commit is contained in:
+6
-7
@@ -49,15 +49,14 @@ fn main() {
|
|||||||
|
|
||||||
let mut scene = vec![Object {
|
let mut scene = vec![Object {
|
||||||
vertices: vec![
|
vertices: vec![
|
||||||
// Point3D(0.0, f64::MAX / 2.0, 1.0),
|
Point3D(0.0, f64::MAX / 2.0, 0.0),
|
||||||
// Point3D(f64::MAX / 2.0, -f64::MAX / 2.0, 1.0),
|
Point3D(f64::MAX / 2.0, -f64::MAX / 2.0, 0.0),
|
||||||
// Point3D(-f64::MAX / 2.0, -f64::MAX / 2.0, 1.0),
|
Point3D(-f64::MAX / 2.0, -f64::MAX / 2.0, 0.0),
|
||||||
// Point3D(0.0, 0.0, f64::MAX / 2.0),
|
|
||||||
// Point3D(0.0, 0.0, 0.0),
|
|
||||||
Point3D(f64::MAX / 2.0, f64::MAX / 2.0, 0.0)
|
|
||||||
],
|
],
|
||||||
edges: vec![
|
edges: vec![
|
||||||
(Point3D(0.0, 0.0, 0.0), Point3D(f64::MAX / 2.0, f64::MAX / 2.0, 0.0))
|
(Point3D(0.0, f64::MAX / 2.0, 0.0), Point3D(f64::MAX / 2.0, -f64::MAX / 2.0, 0.0)),
|
||||||
|
(Point3D(f64::MAX / 2.0, -f64::MAX / 2.0, 0.0), Point3D(-f64::MAX / 2.0, -f64::MAX / 2.0, 0.0)),
|
||||||
|
(Point3D(-f64::MAX / 2.0, -f64::MAX / 2.0, 0.0), Point3D(0.0, f64::MAX / 2.0, 0.0))
|
||||||
],
|
],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
use crate::consts::*;
|
use crate::consts::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Point2D(pub f64, pub f64);
|
pub struct Point2D(pub f64, pub f64);
|
||||||
impl Point2D {
|
impl Point2D {
|
||||||
pub fn to_canvas_coordinates(&self) -> Point3D {
|
pub fn to_canvas_coordinates(&self) -> Point3D {
|
||||||
@@ -18,7 +18,7 @@ impl Point2D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct Point3D(pub f64, pub f64, pub f64);
|
pub struct Point3D(pub f64, pub f64, pub f64);
|
||||||
impl Point3D {
|
impl Point3D {
|
||||||
pub fn to_screen_coordinates(&self) -> Point2D {
|
pub fn to_screen_coordinates(&self) -> Point2D {
|
||||||
|
|||||||
+4
-5
@@ -13,7 +13,7 @@ fn to_rgb((red, green, blue): Subpixels) -> Pixel {
|
|||||||
pixel
|
pixel
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn index_buffer(buf: &mut [u32], x: f64, y: f64) -> &mut u32 {
|
fn index_buffer(buf: &mut [u32], x: f64, y: f64) -> &mut u32 {
|
||||||
let x = x.round_ties_even(); // Banker's round
|
let x = x.round_ties_even(); // Banker's round
|
||||||
let y = y.round_ties_even();
|
let y = y.round_ties_even();
|
||||||
|
|
||||||
@@ -41,13 +41,11 @@ pub fn render(t: u128, scene: &Scene, buf: &mut [u32]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for edge in &obj.edges { // Draw lines
|
for edge in &obj.edges { // Draw lines
|
||||||
dbg!(&edge.0, &edge.1);
|
|
||||||
let start = edge.0.to_screen_coordinates();
|
let start = edge.0.to_screen_coordinates();
|
||||||
let end = edge.1.to_screen_coordinates();
|
let end = edge.1.to_screen_coordinates();
|
||||||
|
|
||||||
dbg!(&start, &end);
|
|
||||||
if (end.0 - start.0).abs() == 0.0 { // Vertical line case - m is undefined
|
if (end.0 - start.0).abs() == 0.0 { // Vertical line case - m is undefined
|
||||||
for y in (start.0.min(end.0) as u32)..(end.0.max(start.0) + 1.0) as u32 {
|
for y in (start.1.min(end.1) as u32)..(end.1.max(start.1) + 1.0) as u32 {
|
||||||
*index_buffer(buf, end.0, y as f64) = to_rgb((255, 255, 255));
|
*index_buffer(buf, end.0, y as f64) = to_rgb((255, 255, 255));
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
@@ -56,7 +54,8 @@ pub fn render(t: u128, scene: &Scene, buf: &mut [u32]) {
|
|||||||
let m = (end.1 - start.1) / (end.0 - start.0); // m = rise/run
|
let m = (end.1 - start.1) / (end.0 - start.0); // m = rise/run
|
||||||
let c = start.1 as f64 - m * start.0 as f64; // c = y - mx
|
let c = start.1 as f64 - m * start.0 as f64; // c = y - mx
|
||||||
|
|
||||||
for x in (start.0 as usize)..(end.0 as usize) {
|
dbg!(start, end, "===");
|
||||||
|
for x in (start.0.min(end.0) as usize)..(end.0.max(start.0) as usize) {
|
||||||
let x = x as f64;
|
let x = x as f64;
|
||||||
let y = m * x + c; // y = mx + c
|
let y = m * x + c; // y = mx + c
|
||||||
*index_buffer(buf, x, y) = to_rgb((255, 255, 255));
|
*index_buffer(buf, x, y) = to_rgb((255, 255, 255));
|
||||||
|
|||||||
Reference in New Issue
Block a user