pub struct Shape {
position: Vec3,
geometry: Geometry,
material: Option<Material>,
}
impl Shape {
pub fn new(geometry: Geometry) -> Shape {
Shape {
position: Vec3::default(),
geometry,
material: None,
}
}
pub fn with_position(mut self, position: Vec3) -> Shape {
self.position = position;
self
}
pub fn with_material(mut self, material: Material) -> Shape {
self.material = Some(material);
self
}
}
// Call site
let shape = Shape::new(Geometry::Sphere::with_radius(1))
.with_position(Vec3(0, 9, 2))
.with_material(Material::SolidColor(Color::Red));
|