Skip to content

Commit

Permalink
feat: some more init and multi threading start.
Browse files Browse the repository at this point in the history
  • Loading branch information
emiflake committed Nov 13, 2019
1 parent ee1320c commit 950919a
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 36 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: pacovali <[email protected]> +#+ #
# +#+ #
# Created: 2019/11/05 19:50:44 by pacovali #+# #+# #
# Updated: 2019/11/12 18:19:28 by nmartins ######## odam.nl #
# Updated: 2019/11/13 01:03:26 by nmartins ######## odam.nl #
# #
# **************************************************************************** #

Expand Down Expand Up @@ -88,6 +88,9 @@ STNAMES= \
algebra/shapes/init \
algebra/shapes/sphere_init \
algebra/shapes/plane_init \
algebra/shapes/square_init \
algebra/shapes/cube_init \
algebra/shapes/disk_init \
algebra/shapes/move \
algebra/shapes/cone_move \
algebra/shapes/cube_move \
Expand Down Expand Up @@ -193,4 +196,4 @@ re:
dev:
@$(MAKE) -j10 -s
@echo "$(TIME) $(CNORM) $(CRED)Running $(CCYAN)$(NAME)$(CDEF)"
@./$(NAME)
@./$(NAME) $(SCENE)
46 changes: 46 additions & 0 deletions scenes/cornell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"camera": {
"fov": 50,
"origin": [0, 18, -75]
},
"objects": [
{
"type": "square",
"origin": [-15, 40, -20],
"normal": [0, -1, 0],
"side_a": [0, 0, 30],
"side_b": [30, 0, 0],
"emission": [255, 255, 255]
},
{
"type": "plane",
"origin": [0, 0, 20],
"normal": [0, 0, -1],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [20, 0, 0],
"normal": [-1, 0, 0],
"color": [100, 255, 100]
},
{
"type": "plane",
"origin": [-20, 0, 0],
"normal": [1, 0, 0],
"color": [255, 100, 100]
},
{
"type": "plane",
"origin": [0, 0, 0],
"normal": [0, 1, 0],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [0, 40, 0],
"normal": [0, -1, 0],
"color": [255, 255, 255]
}
]
}
58 changes: 58 additions & 0 deletions scenes/room.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"camera": {
"fov": 50,
"origin": [0, 18, -50]
},
"objects": [
{
"type": "square",
"origin": [-15, 40, -20],
"normal": [0, -1, 0],
"side_a": [0, 0, 30],
"side_b": [30, 0, 0],
"emission": [255, 255, 255]
},
{
"type": "sphere",
"origin": [-10, 10, 10],
"radius": 10,
"color": [255, 255, 255]
},
{
"type": "sphere",
"origin": [5, 8, 10],
"radius": 8,
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [0, 0, 20],
"normal": [0, 0, -1],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [20, 0, 0],
"normal": [-1, 0, 0],
"color": [100, 255, 100]
},
{
"type": "plane",
"origin": [-20, 0, 0],
"normal": [1, 0, 0],
"color": [255, 100, 100]
},
{
"type": "plane",
"origin": [0, 0, 0],
"normal": [0, 1, 0],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [0, 40, 0],
"normal": [0, -1, 0],
"color": [255, 255, 255]
}
]
}
53 changes: 53 additions & 0 deletions scenes/shapes_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"camera": {
"fov": 50,
"origin": [0, 18, -75]
},
"objects": [
{
"type": "disk",
"origin": [0, 40, -20],
"normal": [0, -1, 0],
"outer_radius": 10,
"emission": [5000, 5000, 5000]
},
{
"type": "square",
"origin": [-5, 10, -20],
"normal": [0, -1, 0],
"side_a": [0, 0, 10],
"side_b": [10, 0, 0],
"color": [50, 50, 50]
},
{
"type": "plane",
"origin": [0, 0, 20],
"normal": [0, 0, -1],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [20, 0, 0],
"normal": [-1, 0, 0],
"color": [100, 255, 100]
},
{
"type": "plane",
"origin": [-20, 0, 0],
"normal": [1, 0, 0],
"color": [255, 100, 100]
},
{
"type": "plane",
"origin": [0, 0, 0],
"normal": [0, 1, 0],
"color": [255, 255, 255]
},
{
"type": "plane",
"origin": [0, 40, 0],
"normal": [0, -1, 0],
"color": [255, 255, 255]
}
]
}
35 changes: 35 additions & 0 deletions src/algebra/shapes/cube_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* cube_init.c :+: :+: */
/* +:+ */
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/13 00:05:41 by nmartins #+# #+# */
/* Updated: 2019/11/13 01:00:56 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

#include "shape.h"

// typedef struct s_cube
// {
// t_vec origin;
// t_vec size;
// t_vec up_axis;
// t_vec front_axis;
// t_vec right_axis;
// t_square side[6];
// } t_cube;

bool cube_init(
t_shape *shape_out, const t_json_value *value)
{
t_cube *cube;

(void)value;
shape_out->type = SHAPE_CUBE;
cube = &shape_out->val.as_cube;
/* TODO */
return (true);
}
27 changes: 27 additions & 0 deletions src/algebra/shapes/disk_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* disk_init.c :+: :+: */
/* +:+ */
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/13 01:00:23 by nmartins #+# #+# */
/* Updated: 2019/11/13 01:04:02 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

#include "shape.h"

bool disk_init(
t_shape *shape_out, const t_json_value *value)
{
t_disk *disk;

shape_out->type = SHAPE_DISK;
disk = &shape_out->val.as_disk;
dict_def_vec(value, "origin", (t_vec){0, 0, 0}, &disk->plane.origin);
dict_def_vec(value, "normal", (t_vec){0, 0, 0}, &disk->plane.normal);
disk->inner_radius = dict_def_double(value, "inner_radius", 0.0);
disk->outer_radius = dict_def_double(value, "outer_radius", 0.0);
return (true);
}
5 changes: 4 additions & 1 deletion src/algebra/shapes/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/12 18:03:38 by nmartins #+# #+# */
/* Updated: 2019/11/12 20:09:52 by nmartins ######## odam.nl */
/* Updated: 2019/11/13 01:02:45 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -20,6 +20,9 @@
const static t_shape_init_kvp g_shape_init_map[] = {
{ "sphere", sphere_init },
{ "plane", plane_init },
{ "square", square_init },
{ "cube", cube_init },
{ "disk", disk_init },
};

static char *get_type(const t_json_value *value)
Expand Down
14 changes: 13 additions & 1 deletion src/algebra/shapes/shape.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: pacovali <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/01/12 18:56:23 by pacovali #+# #+# */
/* Updated: 2019/11/12 18:05:52 by nmartins ######## odam.nl */
/* Updated: 2019/11/13 01:10:44 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -133,6 +133,18 @@ bool sphere_init(
bool plane_init(
t_shape *shape_out, const t_json_value *value);

bool square_init(
t_shape *shape_out, const t_json_value *value);

bool cube_init(
t_shape *shape_out, const t_json_value *value);

bool disk_init(
t_shape *shape_out, const t_json_value *value);

bool triangle_init(
t_shape *shape_out, const t_json_value *value);

/*
** Moving objects
*/
Expand Down
6 changes: 4 additions & 2 deletions src/algebra/shapes/shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/* +:+ */
/* By: pacovali <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/01/12 18:56:23 by pacovali #+# #+# */
/* Updated: 2019/01/23 17:53:36 by pacovali ######## odam.nl */
/* Created: 2019/01/12 18:56:23 by pacovali #+# #+# */
/* Updated: 2019/11/13 01:12:30 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -44,6 +44,8 @@ typedef struct s_square
REAL dot_b;
} t_square;

// TODO: defo reimplement this using just 3 `t_vec`s

typedef struct s_triangle
{
t_plane plane;
Expand Down
29 changes: 29 additions & 0 deletions src/algebra/shapes/square_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* square_init.c :+: :+: */
/* +:+ */
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/12 23:16:16 by nmartins #+# #+# */
/* Updated: 2019/11/12 23:21:13 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

#include "shape.h"

bool square_init(
t_shape *shape_out, const t_json_value *value)
{
t_square *square;

shape_out->type = SHAPE_SQUARE;
square = &shape_out->val.as_square;
dict_def_vec(value, "origin", (t_vec){0, 0, 0}, &square->plane.origin);
dict_def_vec(value, "normal", (t_vec){0, 0, 0}, &square->plane.normal);
dict_def_vec(value, "side_a", (t_vec){0, 0, 0}, &square->side_a);
dict_def_vec(value, "side_b", (t_vec){0, 0, 0}, &square->side_b);
square->dot_a = vec_dot(&square->side_a, &square->side_a);
square->dot_b = vec_dot(&square->side_b, &square->side_b);
return (true);
}
25 changes: 25 additions & 0 deletions src/algebra/shapes/triangle_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* :::::::: */
/* triangle_init.c :+: :+: */
/* +:+ */
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/11/13 01:10:30 by nmartins #+# #+# */
/* Updated: 2019/11/13 01:13:12 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

#include "shape.h"

bool triangle_init(
t_shape *shape_out, const t_json_value *value)
{
t_triangle *tri;

shape_out->type = SHAPE_TRIANGLE;
tri = &shape_out->val.as_triangle;
(void)shape_out;
(void)value;
return (true);
}
5 changes: 2 additions & 3 deletions src/compdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: nmartins <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/10/26 13:20:57 by nmartins #+# #+# */
/* Updated: 2019/11/12 20:36:35 by nmartins ######## odam.nl */
/* Updated: 2019/11/13 01:38:24 by nmartins ######## odam.nl */
/* */
/* ************************************************************************** */

Expand All @@ -23,8 +23,7 @@
** By doing it this way, we are able to
** switch from floats to doubles.
*/
# define SUPERSAMPLE 256
# define SQRT_SUPERS 16
# define SUPERSAMPLE 1

# define SUCCESS 0
# define FAILURE 1
Expand Down
Loading

0 comments on commit 950919a

Please sign in to comment.