shapes: create generic Shape object with Sphere implementation.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -4,7 +4,7 @@ use rtchallenge::{
|
||||
canvas::Canvas,
|
||||
matrices::Matrix4x4,
|
||||
rays::Ray,
|
||||
spheres::{intersect, Sphere},
|
||||
shapes::{intersect, Shape},
|
||||
tuples::{Color, Tuple},
|
||||
Float,
|
||||
};
|
||||
@@ -20,7 +20,7 @@ fn main() -> Result<()> {
|
||||
let pixel_size = wall_size / w as Float;
|
||||
let half = wall_size / 2.;
|
||||
let color = Color::new(1., 0., 0.);
|
||||
let mut shape = Sphere::default();
|
||||
let mut shape = Shape::sphere();
|
||||
shape.set_transform(
|
||||
Matrix4x4::shearing(1., 0., 0., 0., 0., 0.) * Matrix4x4::scaling(0.5, 1., 1.0),
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ use rtchallenge::{
|
||||
lights::PointLight,
|
||||
materials::{lighting, Material},
|
||||
rays::Ray,
|
||||
spheres::{intersect, Sphere},
|
||||
shapes::{intersect, Shape},
|
||||
tuples::{Color, Tuple},
|
||||
Float, WHITE,
|
||||
};
|
||||
@@ -20,7 +20,7 @@ fn main() -> Result<()> {
|
||||
let wall_size = 7.;
|
||||
let pixel_size = wall_size / w as Float;
|
||||
let half = wall_size / 2.;
|
||||
let mut shape = Sphere::default();
|
||||
let mut shape = Shape::sphere();
|
||||
shape.material = Material {
|
||||
color: Color::new(1., 0.2, 1.),
|
||||
specular: 0.5,
|
||||
|
||||
@@ -9,7 +9,7 @@ use rtchallenge::{
|
||||
lights::PointLight,
|
||||
materials::Material,
|
||||
matrices::Matrix4x4,
|
||||
spheres::Sphere,
|
||||
shapes::Shape,
|
||||
transformations::view_transform,
|
||||
tuples::{Color, Tuple},
|
||||
world::World,
|
||||
@@ -39,7 +39,7 @@ fn main() -> Result<()> {
|
||||
camera.set_transform(view_transform(from, to, up));
|
||||
camera.render_strategy = opt.render_strategy;
|
||||
|
||||
let mut floor = Sphere::default();
|
||||
let mut floor = Shape::sphere();
|
||||
floor.set_transform(Matrix4x4::scaling(10., 0.01, 10.));
|
||||
floor.material = Material {
|
||||
color: Color::new(1., 0.9, 0.9),
|
||||
@@ -47,7 +47,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut left_wall = Sphere::default();
|
||||
let mut left_wall = Shape::sphere();
|
||||
left_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(-PI / 4.)
|
||||
@@ -56,7 +56,7 @@ fn main() -> Result<()> {
|
||||
);
|
||||
left_wall.material = floor.material.clone();
|
||||
|
||||
let mut right_wall = Sphere::default();
|
||||
let mut right_wall = Shape::sphere();
|
||||
right_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(PI / 4.)
|
||||
@@ -65,7 +65,7 @@ fn main() -> Result<()> {
|
||||
);
|
||||
right_wall.material = floor.material.clone();
|
||||
|
||||
let mut middle = Sphere::default();
|
||||
let mut middle = Shape::sphere();
|
||||
middle.set_transform(Matrix4x4::translation(-0.5, 1., 0.5));
|
||||
middle.material = Material {
|
||||
color: Color::new(0.1, 1., 0.5),
|
||||
@@ -74,7 +74,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut right = Sphere::default();
|
||||
let mut right = Shape::sphere();
|
||||
right.set_transform(Matrix4x4::translation(1.5, 0.5, -0.5) * Matrix4x4::scaling(0.5, 0.5, 0.5));
|
||||
right.material = Material {
|
||||
color: Color::new(0.5, 1., 0.1),
|
||||
@@ -83,7 +83,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut left = Sphere::default();
|
||||
let mut left = Shape::sphere();
|
||||
left.set_transform(
|
||||
Matrix4x4::translation(-1.5, 0.33, -0.75) * Matrix4x4::scaling(0.33, 0.33, 0.33),
|
||||
);
|
||||
|
||||
@@ -9,7 +9,7 @@ use rtchallenge::{
|
||||
lights::PointLight,
|
||||
materials::Material,
|
||||
matrices::Matrix4x4,
|
||||
spheres::Sphere,
|
||||
shapes::Shape,
|
||||
transformations::view_transform,
|
||||
tuples::{Color, Tuple},
|
||||
world::World,
|
||||
@@ -51,7 +51,7 @@ fn main() -> Result<()> {
|
||||
camera.render_strategy = opt.render_strategy;
|
||||
camera.samples_per_pixel = opt.samples;
|
||||
|
||||
let mut floor = Sphere::default();
|
||||
let mut floor = Shape::sphere();
|
||||
floor.set_transform(Matrix4x4::scaling(10., 0.01, 10.));
|
||||
floor.material = Material {
|
||||
color: Color::new(1., 0.9, 0.9),
|
||||
@@ -59,7 +59,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut left_wall = Sphere::default();
|
||||
let mut left_wall = Shape::sphere();
|
||||
left_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(-PI / 4.)
|
||||
@@ -68,7 +68,7 @@ fn main() -> Result<()> {
|
||||
);
|
||||
left_wall.material = floor.material.clone();
|
||||
|
||||
let mut right_wall = Sphere::default();
|
||||
let mut right_wall = Shape::sphere();
|
||||
right_wall.set_transform(
|
||||
Matrix4x4::translation(0., 0., 5.)
|
||||
* Matrix4x4::rotation_y(PI / 4.)
|
||||
@@ -77,7 +77,7 @@ fn main() -> Result<()> {
|
||||
);
|
||||
right_wall.material = floor.material.clone();
|
||||
|
||||
let mut middle = Sphere::default();
|
||||
let mut middle = Shape::sphere();
|
||||
middle.set_transform(Matrix4x4::translation(-0.5, 1., 0.5));
|
||||
middle.material = Material {
|
||||
color: Color::new(0.1, 1., 0.5),
|
||||
@@ -86,7 +86,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut right = Sphere::default();
|
||||
let mut right = Shape::sphere();
|
||||
right.set_transform(Matrix4x4::translation(1.5, 0.5, -0.5) * Matrix4x4::scaling(0.5, 0.5, 0.5));
|
||||
right.material = Material {
|
||||
color: Color::new(1., 1., 1.),
|
||||
@@ -95,7 +95,7 @@ fn main() -> Result<()> {
|
||||
..Material::default()
|
||||
};
|
||||
|
||||
let mut left = Sphere::default();
|
||||
let mut left = Shape::sphere();
|
||||
left.set_transform(
|
||||
Matrix4x4::translation(-1.5, 0.33, -0.75) * Matrix4x4::scaling(0.33, 0.33, 0.33),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user