new scene from inside a spherical mirror
This commit is contained in:
@@ -46,6 +46,10 @@ pub fn obj<'lua>(ctx: Context<'lua>, _env: Table<'lua>) -> rlua::Result<Table<'l
|
||||
|ctx, (a, b): (LuaObject, LuaObject)| LuaObject::new(Intersection::new(a.get(), b.get()))
|
||||
)?)?;
|
||||
|
||||
module.set("negation", ctx.create_function(
|
||||
|ctx, obj: LuaObject| LuaObject::new(Negation::new(obj.get()))
|
||||
)?)?;
|
||||
|
||||
module.set("plane", ctx.create_function(
|
||||
|ctx, (normal, offset): (Vec3, f64)| LuaObject::new(Plane::new(normal, offset))
|
||||
)?)?;
|
||||
|
||||
+2
-2
@@ -85,8 +85,8 @@ fn default_scene3() -> Scene {
|
||||
|
||||
fn main() {
|
||||
// get scene and camera
|
||||
//let scene = scene_from_file("scenes/randomspheres.lua".to_owned()).unwrap();
|
||||
let scene = default_scene3();
|
||||
let scene = scene_from_file("scenes/insidemirror.lua".to_owned()).unwrap();
|
||||
//let scene = default_scene3();
|
||||
let cam = default_cam();
|
||||
|
||||
// get stats on the scene we're about to render
|
||||
|
||||
@@ -10,6 +10,7 @@ mod plane;
|
||||
mod union;
|
||||
mod intersection;
|
||||
mod exclusion;
|
||||
mod negation;
|
||||
mod cuboid;
|
||||
mod cylinder;
|
||||
mod torus;
|
||||
@@ -65,6 +66,7 @@ pub use plane::Plane;
|
||||
pub use union::Union;
|
||||
pub use intersection::Intersection;
|
||||
pub use exclusion::Exclusion;
|
||||
pub use negation::Negation;
|
||||
pub use cuboid::Cuboid;
|
||||
pub use cylinder::Cylinder;
|
||||
pub use torus::Torus;
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
use crate::object::Obj;
|
||||
use crate::structs::Vec3;
|
||||
use crate::material::Material;
|
||||
use crate::light::Light;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Negation<T: Obj> {
|
||||
obj: T
|
||||
}
|
||||
|
||||
impl<T: Obj> Negation<T> {
|
||||
pub fn new(obj: T) -> Negation<T> {
|
||||
Negation { obj }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Obj> Obj for Negation<T> {
|
||||
fn distance_to(&self, point: Vec3) -> f64 {
|
||||
-self.obj.distance_to(point)
|
||||
}
|
||||
fn normal_at(&self, point: Vec3) -> Vec3 {
|
||||
-self.obj.normal_at(point)
|
||||
}
|
||||
fn material_at(&self, point: Vec3) -> Material {
|
||||
self.obj.material_at(point)
|
||||
}
|
||||
fn get_lights(&self) -> Vec<Light> {
|
||||
self.obj.get_lights()
|
||||
}
|
||||
fn node_count(&self) -> u32 {
|
||||
self.obj.node_count() + 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user