Erstes Treffen der Grafik-AG!!!11elf
This commit is contained in:
commit
adb0d8c4c3
6 changed files with 65654 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "renderer"
|
||||||
|
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "renderer"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
22
src/main.rs
Normal file
22
src/main.rs
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
fn main() {
|
||||||
|
let image_width = 256;
|
||||||
|
let image_height = 256;
|
||||||
|
|
||||||
|
println!("P3\n{image_width} {image_height}\n255\n");
|
||||||
|
|
||||||
|
for i in (0..image_height).rev() {
|
||||||
|
eprint!("\rScanlines remaining: {i:5}");
|
||||||
|
for j in 0..image_width {
|
||||||
|
let r = j as f32 / (image_width - 1) as f32;
|
||||||
|
let g = i as f32 / (image_height - 1) as f32;
|
||||||
|
let b = 0.25;
|
||||||
|
|
||||||
|
let ir = (255.999 * r) as u32;
|
||||||
|
let ig = (255.999 * g) as u32;
|
||||||
|
let ib = (255.999 * b) as u32;
|
||||||
|
|
||||||
|
println!("{ir} {ig} {ib}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
eprintln!("\nDone!");
|
||||||
|
}
|
76
src/vec3.rs
Normal file
76
src/vec3.rs
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
struct Vec3 {
|
||||||
|
pub e: [f64: 3],
|
||||||
|
}
|
||||||
|
|
||||||
|
type Color = Vec3;
|
||||||
|
type Point3 = Vec3;
|
||||||
|
|
||||||
|
impl Vec3 {
|
||||||
|
|
||||||
|
pub fn new(x: f64, y: f64, z: f64) -> Self {
|
||||||
|
Vec3 { e: [x, y, z] }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn length() -> f64 {
|
||||||
|
self.length_squared().sqrt()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn length_squared(&self) -> f64 {
|
||||||
|
self.e[0]*self.e[0]
|
||||||
|
+ self.e[1]*self.e[1]
|
||||||
|
+ self.e[2]*self.e[2]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn x(&self) -> f64 { self.e[0] }
|
||||||
|
pub fn y(&self) -> f64 { self.e[1] }
|
||||||
|
pub fn z(&self) -> f64 { self.e[2] }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Add for Vec3 {
|
||||||
|
type Output = Vec3;
|
||||||
|
|
||||||
|
fn add(self, rhs: Self) -> Vec3 {
|
||||||
|
Vec3::new(self.x()+rhs.x(), self.y()+rhs.y(), self.z()+rhs.z());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl AddAssign for Vec3 {
|
||||||
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
|
self.e[0] += rhs.x();
|
||||||
|
self.e[1] += rhs.y();
|
||||||
|
self.e[2] += rhs.z();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Sub for Vec3 {
|
||||||
|
type Output = Vec3;
|
||||||
|
|
||||||
|
fn sub(self, rhs: Self) -> Vec3 {
|
||||||
|
Vec3::new(self.x()-rhs.x(), self.y()-rhs.y(), self.z()-rhs.z())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Mul<Vec3> for f64 {
|
||||||
|
type Output = Vec3;
|
||||||
|
|
||||||
|
fn mul(self, rhs: Vec3) -> Vec3 {
|
||||||
|
Vec3::new(self*rhs.x(), self*rhs.y(), self*rhs.z());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MulAssign<f64> for Vec3 {
|
||||||
|
fn mul_assign(&mut self, rhs: f64) {
|
||||||
|
self.e[0] *= rhs;
|
||||||
|
self.e[1] *= rhs;
|
||||||
|
self.e[2] *= rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DivAssign<f64> for Vec3 {
|
||||||
|
fn div_assign(&mul self, rhs: f64) {
|
||||||
|
self.e[0] /= rhs;
|
||||||
|
self.e[1] /= rhs;
|
||||||
|
self.e[2] /= rhs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue