Compare commits
5 Commits
c4a794c4f2
...
50eabecfe9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50eabecfe9 | ||
|
|
585af00665 | ||
|
|
5065596f96 | ||
|
|
8cd294c44a | ||
|
|
58a9c36d0d |
@ -1,2 +1,2 @@
|
|||||||
mod geometry;
|
pub mod geometry;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
|
|||||||
83
src/main.rs
83
src/main.rs
@ -1,8 +1,83 @@
|
|||||||
use hello::math::Point3;
|
use hello::geometry::{self, Geometry, Sphere};
|
||||||
|
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 p1 = Point3::new(0.0, 0.0, 0.0);
|
let tex = Rc::new(Texture::load_texture());
|
||||||
let p2 = Point3::new(0.0, 0.0, 0.0);
|
|
||||||
|
|
||||||
let v = p1 - p2;
|
let geo1 = RenderableGeometry::new(
|
||||||
|
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,6 +90,16 @@ 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