Add plane texture mapping

This commit is contained in:
maddiebaka
2023-06-17 01:36:49 -04:00
parent 04b166ac72
commit a9f503fdf4
4 changed files with 30 additions and 6 deletions

View File

@@ -28,16 +28,24 @@ use std::io::{Write,stdout};
use crossterm::{QueueableCommand,cursor,terminal,ExecutableCommand};
fn initialize_scene(camera: &mut PerspectiveCamera) {
camera.lights.push(LightSrc::new(Vec3::new(180000.0, 900.0, 300.0), 2.0));
camera.lights.push(LightSrc::new(Vec3::new(1800.0, 900.0, 300.0), 2.0));
camera.lights.push(LightSrc::new(Vec3::new(1100.0, 800.0, 300.0), 2.0));
let color = Color { red: 30.0, green: 30.0, blue: 30.0 };
//let color = Color { red: 30.0, green: 30.0, blue: 30.0 };
let back_texture_path = Path::new("texture/tiles_base.png");
let back_height_path = Path::new("texture/tiles_height.png");
let back_texture_image = image::open(&back_texture_path).unwrap();
let back_height_image = image::open(&back_height_path).unwrap();
let back_texture = Texture { texture: back_texture_image.clone(), heightmap: back_height_image.clone() };
let back_plane = Plane {
//pos: Vec3::new(0.0, 0.0, 100.0),
pos: Vec3::new(0.0, 0.0, 1500.0),
//color: Color::new(20.0, 20.0, 255.0),
material: Material::new(Coloration::Color(color), 2.0, SurfaceType::Diffuse),
material: Material::new(Coloration::Texture(back_texture), 2.0, SurfaceType::Diffuse),
normal: Vec3::new(0.0, 0.0, 1.0),
};
camera.elements.push(Element::Plane(back_plane));
@@ -66,10 +74,11 @@ fn initialize_scene(camera: &mut PerspectiveCamera) {
};
camera.elements.push(Element::Sphere(right_sphere));
let sphere_color = Color { red: 60.0, green: 60.0, blue: 60.0 };
let center_sphere = Sphere {
pos: Vec3::new(1280.0, 690.0, 1100.0),
radius: 300.0,
material: Material::new(Coloration::Texture(base_texture.clone()), 2.0, SurfaceType::Reflective { reflectivity: 0.2 }),
material: Material::new(Coloration::Color(sphere_color), 2.0, SurfaceType::Reflective { reflectivity: 0.2 }),
};
camera.elements.push(Element::Sphere(center_sphere));
}