Added primitives

This commit is contained in:
STP
2023-11-12 02:06:46 -05:00
parent eab69336a1
commit dfc5d1ad23
4 changed files with 80 additions and 16 deletions

64
Cargo.lock generated
View File

@@ -93,6 +93,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "anyhow"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]] [[package]]
name = "approx" name = "approx"
version = "0.5.1" version = "0.5.1"
@@ -222,6 +228,12 @@ dependencies = [
"syn 2.0.39", "syn 2.0.39",
] ]
[[package]]
name = "byteorder"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]] [[package]]
name = "calloop" name = "calloop"
version = "0.10.6" version = "0.10.6"
@@ -268,6 +280,12 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "color_quant"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]] [[package]]
name = "com-rs" name = "com-rs"
version = "0.2.1" version = "0.2.1"
@@ -616,6 +634,21 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "image"
version = "0.24.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f3dfdbdd72063086ff443e297b61695500514b1e41095b6fb9a5ab48a70a711"
dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"jpeg-decoder",
"num-rational",
"num-traits",
"png",
]
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.1.0" version = "2.1.0"
@@ -664,6 +697,12 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "jpeg-decoder"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
[[package]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.65" version = "0.3.65"
@@ -869,6 +908,7 @@ checksum = "307ed9b18cc2423f29e83f84fd23a8e73628727990181f18641a8b5dc2ab1caa"
dependencies = [ dependencies = [
"approx", "approx",
"matrixmultiply", "matrixmultiply",
"nalgebra-macros",
"num-complex", "num-complex",
"num-rational", "num-rational",
"num-traits", "num-traits",
@@ -877,15 +917,14 @@ dependencies = [
] ]
[[package]] [[package]]
name = "nalgebra-glm" name = "nalgebra-macros"
version = "0.18.0" version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e68879ff227a94627e63bbd518b4f82b8f0cc56bb01a498251507de6d1c412d6" checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998"
dependencies = [ dependencies = [
"approx", "proc-macro2",
"nalgebra", "quote",
"num-traits", "syn 1.0.109",
"simba",
] ]
[[package]] [[package]]
@@ -1291,16 +1330,25 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b" checksum = "216080ab382b992234dda86873c18d4c48358f5cfcb70fd693d7f6f2131b628b"
[[package]]
name = "roots"
version = "0.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "082f11ffa03bbef6c2c6ea6bea1acafaade2fd9050ae0234ab44a2153742b058"
[[package]] [[package]]
name = "rust-opengl" name = "rust-opengl"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"bytemuck", "bytemuck",
"cfg-if", "cfg-if",
"env_logger", "env_logger",
"image",
"log", "log",
"nalgebra-glm", "nalgebra",
"pollster", "pollster",
"roots",
"wgpu", "wgpu",
"winit", "winit",
] ]

View File

@@ -4,6 +4,10 @@ version = "0.1.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies.image]
version = "0.24"
default-features = false
features = ["png", "jpeg"]
[dependencies] [dependencies]
cfg-if = "1" cfg-if = "1"
@@ -13,4 +17,6 @@ log = "0.4"
wgpu = "0.18" wgpu = "0.18"
pollster = "0.3" pollster = "0.3"
bytemuck = { version = "1.12", features = [ "derive" ] } bytemuck = { version = "1.12", features = [ "derive" ] }
nalgebra-glm = "0.18.0" anyhow = "1.0"
nalgebra = "0.32.3"
roots = "0.0.8"

View File

@@ -2,10 +2,18 @@
#![allow(unused_imports)] #![allow(unused_imports)]
#![allow(unused_variables)] #![allow(unused_variables)]
//Use linear algebra module //Use linear algebra module
pub mod state;
use state::run; use state::run;
//Cameras
mod camera;
mod primitive;
mod ray;
mod state;
mod texture;
mod vertex;
const EPSILON: f32 = 1e-7;
fn main() { fn main() {
pollster::block_on(run()); pollster::block_on(run());
} }

View File

@@ -1,15 +1,17 @@
use nalgebra::Vector4; use crate::EPSILON;
use nalgebra::{Matrix4, Point3, Vector3};
pub struct Ray { pub struct Ray {
a: Vector4<f32>, pub a: Point3<f32>,
b: Vector4<f32>, pub b: Vector3<f32>,
} }
impl Ray { impl Ray {
fn new(_a: Vector4<f32>, _b: Vector4<f32>) -> Ray { pub fn new(_a: Point3<f32>, _b: Vector3<f32>) -> Ray {
Ray { a: _a, b: _b } Ray { a: _a, b: _b }
} }
fn at_t(self, t: f32) -> Vector4<f32> { pub fn at_t(self, t: f32) -> Point3<f32> {
self.a + self.b * t self.a + self.b * t
} }
} }