Compare commits
No commits in common. "50eabecfe95efeced6645da8d24ebe32fd9c1af0" and "c4a794c4f25ada8c51db41aae1d7999525d3b637" have entirely different histories.
50eabecfe9
...
c4a794c4f2
@ -1,2 +1,2 @@
|
|||||||
pub mod geometry;
|
mod geometry;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
|
|||||||
83
src/main.rs
83
src/main.rs
@ -1,83 +1,8 @@
|
|||||||
use hello::geometry::{self, Geometry, Sphere};
|
use hello::math::Point3;
|
||||||
use hello::math::{Mat4x4, Point3};
|
|
||||||
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct RGB {
|
|
||||||
red: f64,
|
|
||||||
green: f64,
|
|
||||||
blue: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct Texture {
|
|
||||||
width: usize,
|
|
||||||
height: usize,
|
|
||||||
pixel: Vec<RGB>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Texture {
|
|
||||||
fn load_texture() -> Texture {
|
|
||||||
let width = 640;
|
|
||||||
let height = 480;
|
|
||||||
|
|
||||||
let mut pixel = Vec::new();
|
|
||||||
|
|
||||||
for x in 0..width {
|
|
||||||
for y in 0..height {
|
|
||||||
pixel.push(RGB {
|
|
||||||
red: 1.0,
|
|
||||||
green: 1.0,
|
|
||||||
blue: 1.0,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Texture {
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
pixel,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct RenderableGeometry {
|
|
||||||
transform: Mat4x4,
|
|
||||||
geometry: Geometry,
|
|
||||||
texture: Rc<Texture>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl RenderableGeometry {
|
|
||||||
fn new(transform: Mat4x4, geometry: Geometry, texture: Rc<Texture>) -> RenderableGeometry {
|
|
||||||
RenderableGeometry {
|
|
||||||
transform,
|
|
||||||
geometry,
|
|
||||||
texture,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let tex = Rc::new(Texture::load_texture());
|
let p1 = Point3::new(0.0, 0.0, 0.0);
|
||||||
|
let p2 = Point3::new(0.0, 0.0, 0.0);
|
||||||
|
|
||||||
let geo1 = RenderableGeometry::new(
|
let v = p1 - p2;
|
||||||
Mat4x4::ident(),
|
|
||||||
Geometry::Sphere(Sphere::new(Point3::new(0.0, 0.0, 0.0), 1.0)),
|
|
||||||
tex.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let geo2 = RenderableGeometry::new(
|
|
||||||
Mat4x4::ident(),
|
|
||||||
Geometry::Sphere(Sphere::new(Point3::new(-2.0, 0.0, 0.0), 1.0)),
|
|
||||||
tex.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
let geo3 = RenderableGeometry::new(
|
|
||||||
Mat4x4::ident(),
|
|
||||||
Geometry::Sphere(Sphere::new(Point3::new(2.0, 0.0, 0.0), 1.0)),
|
|
||||||
tex.clone(),
|
|
||||||
);
|
|
||||||
|
|
||||||
println!("Reference counter = {}", Rc::strong_count(&tex));
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/math.rs
10
src/math.rs
@ -90,16 +90,6 @@ impl Sub for Point3 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Mat4x4 {
|
|
||||||
v: f64,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Mat4x4 {
|
|
||||||
pub fn ident() -> Mat4x4 {
|
|
||||||
Mat4x4 { v: 0.0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user