Compare commits
3 Commits
01943072a1
...
714b209a44
Author | SHA1 | Date | |
---|---|---|---|
|
714b209a44 | ||
|
7d689629f4 | ||
|
7df30bb043 |
@ -1,5 +1,5 @@
|
||||
project("Simple Raytracer" C)
|
||||
cmake_minimum_required(VERSION 3.18)
|
||||
project("Simple Raytracer" C)
|
||||
|
||||
OPTION(BUILD_BENCHMARKS "Build and run benchmarks" OFF)
|
||||
|
||||
@ -96,7 +96,7 @@ add_subdirectory(module_shapes)
|
||||
add_subdirectory(module_patterns)
|
||||
add_subdirectory(module_utilities)
|
||||
|
||||
find_package(SWIG 4.1 OPTIONAL_COMPONENTS python perl5)
|
||||
find_package(SWIG 4.0 OPTIONAL_COMPONENTS python perl5)
|
||||
if (SWIG_FOUND)
|
||||
message("SWIG found: ${SWIG_EXECUTABLE}")
|
||||
include (UseSWIG)
|
||||
@ -109,6 +109,8 @@ if (SWIG_FOUND)
|
||||
endif()
|
||||
if (SWIG_perl5_FOUND)
|
||||
message("SWIG perl bindings will be generated")
|
||||
FIND_PACKAGE(PerlLibs)
|
||||
INCLUDE_DIRECTORIES(${PERL_INCLUDE_PATH})
|
||||
else()
|
||||
message(WARNING "SWIG perl bindings cannot be generated")
|
||||
endif()
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
CEXCEPTION_T global_exception;
|
||||
static void build_world(WORLD_World* world) {
|
||||
UNUSED(world);
|
||||
TUPLES_Color red, green, blue;
|
||||
TUPLES_init_color(&red, 1, 0, 0);
|
||||
TUPLES_init_color(&green, 0, 1, 0);
|
||||
@ -48,7 +49,7 @@ int main(int argc, char *argv[]) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
char* input_file = argv[1];
|
||||
double obj_scale = 1.0;
|
||||
double obj_scale = 3.0;
|
||||
if (argc == 3) {
|
||||
char* scale_string = argv[2];
|
||||
char* err = NULL;
|
||||
@ -90,7 +91,7 @@ int main(int argc, char *argv[]) {
|
||||
MATRIX_delete_all(obj_group_scale, new_transform);
|
||||
MATERIAL_Material* obj_group_material = MATERIAL_new();
|
||||
obj_group_material->refractive_index = 1.5;
|
||||
obj_group_material->ambient = 0;
|
||||
obj_group_material->ambient = 0.1;
|
||||
obj_group_material->diffuse = 0;
|
||||
obj_group_material->reflective = 1.0;
|
||||
obj_group_material->transparency = 1.0;
|
||||
@ -99,7 +100,7 @@ int main(int argc, char *argv[]) {
|
||||
MATERIAL_delete(obj_group_material);
|
||||
LOGGER_log(LOGGER_INFO, "Computing bounds...\n");
|
||||
UTILITIES_Timer* divide_timer = UTILITIES_Timer_start();
|
||||
SHAPE_divide((SHAPE_Shape*)obj_group, 1000);
|
||||
SHAPE_divide((SHAPE_Shape*)obj_group, 10);
|
||||
UTILITIES_Timer_Results divide_results = UTILITIES_Timer_stop(divide_timer);
|
||||
log_perf(divide_results, "Divide time: ");
|
||||
WORLD_add_object(world, obj_group);
|
||||
|
@ -12,7 +12,7 @@ if (SWIG_python_FOUND)
|
||||
)
|
||||
target_include_directories(pyRaytracer PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
module_math
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/module_math
|
||||
module_raytracer
|
||||
module_utilities
|
||||
external/CException/lib
|
||||
@ -22,6 +22,25 @@ if (SWIG_python_FOUND)
|
||||
)
|
||||
endif()
|
||||
|
||||
if (SWIG_perl_FOUND)
|
||||
if (SWIG_perl5_FOUND)
|
||||
set_property(SOURCE raytracer.i PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON)
|
||||
swig_add_library(plRaytracer LANGUAGE perl5 SOURCES raytracer.i )
|
||||
target_link_libraries(plRaytracer
|
||||
${PERL_LIBRARY}
|
||||
module_math
|
||||
module_raytracer
|
||||
module_utilities
|
||||
CException
|
||||
m
|
||||
)
|
||||
target_include_directories(plRaytracer PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
module_math
|
||||
module_raytracer
|
||||
module_utilities
|
||||
external/CException/lib
|
||||
)
|
||||
target_compile_options(plRaytracer PRIVATE
|
||||
-Wno-unused-parameter ${PERL_EXTRA_C_FLAGS}
|
||||
)
|
||||
endif()
|
||||
|
@ -8,6 +8,10 @@
|
||||
#include "material.h"
|
||||
#include "shape.h"
|
||||
#include "sphere.h"
|
||||
#include "plane.h"
|
||||
#include "cube.h"
|
||||
#include "cylinder.h"
|
||||
#include "cone.h"
|
||||
%}
|
||||
|
||||
%nodefaultctor;
|
||||
@ -31,6 +35,9 @@ WORLD_World *WORLD_new(LIGHTS_Light *light);
|
||||
void add_object(SHAPE_Shape* shape) {
|
||||
WORLD_add_object($self, shape);
|
||||
}
|
||||
void add_object(CYLINDER_Cylinder* shape) {
|
||||
WORLD_add_object($self, shape);
|
||||
}
|
||||
};
|
||||
|
||||
struct CAMERA_Camera { };
|
||||
@ -54,23 +61,100 @@ struct CANVAS_Canvas { };
|
||||
}
|
||||
|
||||
struct MATERIAL_Material {
|
||||
TUPLES_Color color;
|
||||
double ambient, diffuse, specular, shininess, reflective, transparency, refractive_index;
|
||||
/* PATTERN_Pattern *pattern; */
|
||||
bool shadow_calc;
|
||||
};
|
||||
%extend MATERIAL_Material {
|
||||
MATERIAL_Material *ambient(double val) {
|
||||
$self->ambient = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *diffuse(double val) {
|
||||
$self->diffuse = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *specular(double val) {
|
||||
$self->specular = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *shininess(double val) {
|
||||
$self->shininess = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *reflective(double val) {
|
||||
$self->reflective = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *transparency(double val) {
|
||||
$self->transparency = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *refractive_index(double val) {
|
||||
$self->refractive_index = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *shadow_calc(bool val) {
|
||||
$self->shadow_calc = val;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *color(const TUPLES_Color *color) {
|
||||
$self->color = *color;
|
||||
return $self;
|
||||
}
|
||||
MATERIAL_Material *color(double r, double g, double b) {
|
||||
TUPLES_init_color(&($self->color), r, g, b);
|
||||
return $self;
|
||||
}
|
||||
}
|
||||
%rename(material) MATERIAL_new;
|
||||
MATERIAL_Material *MATERIAL_new();
|
||||
|
||||
struct SHAPE_Shape { };
|
||||
struct CYLINDER_Cylinder { };
|
||||
%rename(sphere) SPHERE_new;
|
||||
SHAPE_Shape* SPHERE_new();
|
||||
%rename(plane) PLANE_new;
|
||||
SHAPE_Shape* PLANE_new();
|
||||
%rename(cube) CUBE_new;
|
||||
SHAPE_Shape* CUBE_new();
|
||||
%rename(cylinder) CYLINDER_new;
|
||||
CYLINDER_Cylinder* CYLINDER_new();
|
||||
%rename(cone) CONE_new;
|
||||
CYLINDER_Cylinder* CONE_new();
|
||||
%extend SHAPE_Shape {
|
||||
void set_transform(const MATRIX_Matrix *transformation) {
|
||||
SHAPE_Shape *set_transform(const MATRIX_Matrix *transformation) {
|
||||
SHAPE_set_transform($self, transformation);
|
||||
return $self;
|
||||
}
|
||||
void set_material(const MATERIAL_Material *material) {
|
||||
SHAPE_Shape *set_material(const MATERIAL_Material *material) {
|
||||
SHAPE_set_material($self, material);
|
||||
return $self;
|
||||
}
|
||||
};
|
||||
|
||||
%extend CYLINDER_Cylinder {
|
||||
CYLINDER_Cylinder *set_transform(const MATRIX_Matrix *transformation) {
|
||||
CYLINDER_set_transform($self, transformation);
|
||||
return $self;
|
||||
}
|
||||
|
||||
CYLINDER_Cylinder *set_material(const MATERIAL_Material *material) {
|
||||
CYLINDER_set_material($self, material);
|
||||
return $self;
|
||||
}
|
||||
|
||||
CYLINDER_Cylinder *minimum(double minimum) {
|
||||
$self->minimum = minimum;
|
||||
return $self;
|
||||
}
|
||||
|
||||
CYLINDER_Cylinder *maximum(double maximum) {
|
||||
$self->maximum = maximum;
|
||||
return $self;
|
||||
}
|
||||
|
||||
CYLINDER_Cylinder *closed(bool closed) {
|
||||
$self->closed = closed;
|
||||
return $self;
|
||||
}
|
||||
};
|
||||
|
||||
|
35
test.py
35
test.py
@ -1,7 +1,5 @@
|
||||
#!/opt/homebrew/bin/python3.11
|
||||
|
||||
import math
|
||||
import raytracer
|
||||
from raytracer import *
|
||||
|
||||
c = color(1, 1, 1)
|
||||
@ -11,34 +9,19 @@ light = pointlight(p, c)
|
||||
|
||||
w = world(light)
|
||||
|
||||
middle = sphere()
|
||||
m = material()
|
||||
m.diffuse = 0.7
|
||||
m.specular = 0.3
|
||||
m.color = color(.1, 1, .5)
|
||||
middle.set_material(m)
|
||||
s_matrix = matrix.translation(-.5, 1, .5)
|
||||
middle.set_transform(s_matrix)
|
||||
middle = sphere() \
|
||||
.set_material(material().diffuse(.7).specular(.3).color(color(.1, 1, .5))) \
|
||||
.set_transform(matrix.translation(-.5, 1, .5))
|
||||
w.add_object(middle)
|
||||
|
||||
right = sphere()
|
||||
m = material()
|
||||
m.diffuse = 0.7
|
||||
m.specular = 0.3
|
||||
m.color = color(.5, 1, .1)
|
||||
right.set_material(m)
|
||||
s_matrix = matrix.translation(1.5, .5, -.5).multiply(matrix.scaling(.5, .5, .5))
|
||||
right.set_transform(s_matrix)
|
||||
right = sphere() \
|
||||
.set_material(material().diffuse(.7).specular(.3).color(color(.5, 1, .1))) \
|
||||
.set_transform(matrix.translation(1.5, .5, -.5).multiply(matrix.scaling(.5, .5, .5)))
|
||||
w.add_object(right)
|
||||
|
||||
left = sphere()
|
||||
m = material()
|
||||
m.diffuse = 0.7
|
||||
m.specular = 0.3
|
||||
m.color = color(1, .8, .1)
|
||||
left.set_material(m)
|
||||
s_matrix = matrix.translation(-1.5, .33, -.75).multiply(matrix.scaling(.33, .33, .33))
|
||||
left.set_transform(s_matrix)
|
||||
left = sphere() \
|
||||
.set_material(material().diffuse(.7).specular(.3).color(color(1, .8, .1))) \
|
||||
.set_transform(matrix.translation(-1.5, .33, -.75).multiply(matrix.scaling(.33, .33, .33)))
|
||||
w.add_object(left)
|
||||
|
||||
c = camera(640, 480, math.pi/3)
|
||||
|
Loading…
Reference in New Issue
Block a user