diff options
| -rw-r--r-- | Makefile | 18 | ||||
| -rw-r--r-- | inc/scop.h | 8 | ||||
| -rw-r--r-- | res/basic_cube.obj | 1 | ||||
| -rw-r--r-- | res/pyramid.obj | 15 | ||||
| -rw-r--r-- | shader/vertex.glsl | 6 | ||||
| -rw-r--r-- | src/gl.c | 27 | ||||
| -rw-r--r-- | src/glfw.c | 5 | ||||
| -rw-r--r-- | src/main.c | 142 | ||||
| -rw-r--r-- | src/parse.c | 15 | ||||
| m--------- | vendor/libft | 0 | ||||
| -rw-r--r-- | vendor/libftm/Makefile | 21 | ||||
| -rw-r--r-- | vendor/libftm/inc/libftm_mat4.h | 27 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_frustum.c | 27 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c | 26 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_perspective.c | 25 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4init_proj.c | 0 | ||||
| -rw-r--r-- | vendor/libftm/src/mat4/ftm_mat4rotate.c | 6 |
17 files changed, 285 insertions, 84 deletions
@@ -6,12 +6,12 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/05/09 10:24:52 by charles #+# #+# # -# Updated: 2020/05/12 14:04:16 by charles ### ########.fr # +# Updated: 2020/05/12 16:07:23 by charles ### ########.fr # # # # **************************************************************************** # -MAKE = make RM = rm -f +MAKE = make --no-print-directory VENDOR_DIR = vendor LIBFT_DIR = $(VENDOR_DIR)/libft @@ -38,19 +38,23 @@ INC = $(shell find $(INC_DIR) -type f -name '*.h') all: prebuild $(NAME) prebuild: - mkdir -p $(OBJ_DIR) + @mkdir -p $(OBJ_DIR) $(NAME): $(OBJ) libft_all libftm_all - $(CC) -o $@ $(OBJ) $(LDFLAGS) + @echo "Linking $@" + @$(CC) -o $@ $(OBJ) $(LDFLAGS) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC) - $(CC) $(CCFLAGS) -c -o $@ $< + @echo "Compiling $@" + @$(CC) $(CCFLAGS) -c -o $@ $< cleanloc: - $(RM) $(OBJ) + @echo "Compiling objects" + @$(RM) $(OBJ) fcleanloc: cleanloc - $(RM) $(NAME) + @echo "Removing $(NAME)" + @$(RM) $(NAME) reloc: fcleanloc all @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 10:41:44 by charles #+# #+# */ -/* Updated: 2020/05/12 13:39:34 by charles ### ########.fr */ +/* Updated: 2020/05/12 16:28:57 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,7 +40,9 @@ typedef struct unsigned int index_buf; unsigned int vertex_array; unsigned int shader; - int mvp_location; + int model_location; + int view_location; + int proj_location; } t_gl_state; /* @@ -55,7 +57,7 @@ int parse(char *filepath, t_object *object); int gl_state_init(t_gl_state *state, t_object *object); void gl_state_quit(t_gl_state *state, t_object *object); -void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *mvp); +void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *model, t_ftmmat4 *view, t_ftmmat4 *proj); /* ** error.c diff --git a/res/basic_cube.obj b/res/basic_cube.obj index 9884f37..23620cb 100644 --- a/res/basic_cube.obj +++ b/res/basic_cube.obj @@ -6,6 +6,7 @@ v -1.000000 1.000000 -1.000000 v -1.000000 -1.000000 -1.000000 v -1.000000 1.000000 1.000000 v -1.000000 -1.000000 1.000000 + f 1 5 7 3 f 4 3 7 8 f 8 7 5 6 diff --git a/res/pyramid.obj b/res/pyramid.obj new file mode 100644 index 0000000..16073df --- /dev/null +++ b/res/pyramid.obj @@ -0,0 +1,15 @@ +# top +v 0.0 1.0 0.0 +# base +v 0.0 0.0 -1.0 +v -1.0 0.0 1.0 +v 1.0 0.0 1.0 + +# base +f 2 3 4 + +# front +f 1 3 4 + +f 1 2 3 +f 1 3 4 diff --git a/shader/vertex.glsl b/shader/vertex.glsl index 0e7b04d..02a1954 100644 --- a/shader/vertex.glsl +++ b/shader/vertex.glsl @@ -2,9 +2,11 @@ layout (location = 0) in vec3 v_position; -uniform mat4 u_mvp; +uniform mat4 u_model; +uniform mat4 u_view; +uniform mat4 u_proj; void main() { - gl_Position = u_mvp * vec4(v_position, 1.0); + gl_Position = u_proj * u_view * u_model * vec4(v_position, 1.0); } @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/11 01:31:10 by charles #+# #+# */ -/* Updated: 2020/05/12 14:07:04 by charles ### ########.fr */ +/* Updated: 2020/05/12 18:46:49 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,8 +16,14 @@ int gl_state_init(t_gl_state *state, t_object *object) { if ((state->shader = shader_new()) == 0) return (-1); - GL_CALL(state->mvp_location = glGetUniformLocation(state->shader, "u_mvp")); - if (state->mvp_location == -1) + GL_CALL(state->view_location = glGetUniformLocation(state->shader, "u_view")); + if (state->view_location == -1) + return (-1); + GL_CALL(state->model_location = glGetUniformLocation(state->shader, "u_model")); + if (state->model_location == -1) + return (-1); + GL_CALL(state->proj_location = glGetUniformLocation(state->shader, "u_proj")); + if (state->proj_location == -1) return (-1); GL_CALL(glGenVertexArrays(1, &state->vertex_array)); @@ -49,7 +55,18 @@ void gl_state_quit(t_gl_state *state, t_object *object) free(object->indices); } -void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *mvp) +void gl_state_set_mvp(t_gl_state *state, t_ftmmat4 *model, t_ftmmat4 *view, t_ftmmat4 *proj) { - GL_CALL(glUniformMatrix4fv(state->mvp_location, 1, GL_TRUE, mvp->m)); + if (model != NULL) + { + GL_CALL(glUniformMatrix4fv(state->model_location, 1, GL_TRUE, model->m)); + } + if (view != NULL) + { + GL_CALL(glUniformMatrix4fv(state->view_location, 1, GL_TRUE, view->m)); + } + if (proj != NULL) + { + GL_CALL(glUniformMatrix4fv(state->proj_location, 1, GL_TRUE, proj->m)); + } } @@ -6,15 +6,18 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/11 01:58:00 by charles #+# #+# */ -/* Updated: 2020/05/12 13:58:51 by charles ### ########.fr */ +/* Updated: 2020/05/12 19:05:43 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "scop.h" +bool g_window_resized = false; + void st_resize_callback(GLFWwindow *window, int width, int height) { (void)window; + g_window_resized = true; glViewport(0, 0, width, height); } @@ -6,73 +6,97 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 10:20:09 by charles #+# #+# */ -/* Updated: 2020/05/12 14:10:09 by charles ### ########.fr */ +/* Updated: 2020/05/12 19:08:00 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "scop.h" +void debugmat(t_ftmmat4 *mat) +{ + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + printf("%f, ", mat->m[i * 4 + j]); + } + printf("\n"); + } + printf("\n"); +} + +extern bool g_window_resized; + int main(int argc, char **argv) { GLFWwindow *window; t_object object; t_gl_state state; - /* if (argc != 2) */ - /* { */ - /* ft_putstr("Usage: "); */ - /* ft_putstr(argv[0]); */ - /* ft_putendl(" [obj file]"); */ - /* return (1); */ - /* } */ - /* if (parse(argv[1], &object) == -1) */ - /* { */ - /* ft_putstr("Error: couldn't parse "); */ - /* ft_putendl(argv[1]); */ - /* return (1); */ - /* } */ - - float positions[] = { - 0.5f, 0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - -0.5f, -0.5f, 0.0f, - -0.5f, 0.5f, 0.0f - }; - unsigned int index[] = { - 0, 1, 3, - 1, 2, 3 - }; - - object.vertices = malloc(sizeof(positions)); - ft_memcpy(object.vertices, positions, sizeof(positions)); - object.indices = malloc(sizeof(index)); - ft_memcpy(object.indices, index, sizeof(index)); - object.vertices_len = 12; - object.indices_len = 6; - /* for (size_t i = 0; i < object.indices_len; i++) */ - /* printf("%u\n", object.indices[i]); */ - /* for (size_t i = 0; i < object.vertices_len; i++) */ - /* printf("%f\n", object.vertices[i]); */ - /* printf("%lu\n", object.indices_len); */ - - t_ftmmat4 trans; + if (argc != 2) + { + ft_putstr("Usage: "); + ft_putstr(argv[0]); + ft_putendl(" [obj file]"); + return (1); + } + if (parse(argv[1], &object) == -1) + { + ft_putstr("Error: couldn't parse "); + ft_putendl(argv[1]); + return (1); + } + + /* float positions[] = { */ + /* 0.5f, 0.5f, 0.0f, */ + /* 0.5f, -0.5f, 0.0f, */ + /* -0.5f, -0.5f, 0.0f, */ + /* -0.5f, 0.5f, 0.0f */ + /* }; */ + /* unsigned int index[] = { */ + /* 0, 1, 3, */ + /* 1, 2, 3 */ + /* }; */ + /* object.vertices = malloc(sizeof(positions)); */ + /* ft_memcpy(object.vertices, positions, sizeof(positions)); */ + /* object.indices = malloc(sizeof(index)); */ + /* ft_memcpy(object.indices, index, sizeof(index)); */ + /* object.vertices_len = 12; */ + /* object.indices_len = 6; */ + + for (size_t i = 0; i < object.indices_len; i++) + { + printf("%u, ", object.indices[i++]); + printf("%u, ", object.indices[i++]); + printf("%u\n", object.indices[i]); + } + printf("yo %lu\n", object.indices_len); + for (size_t i = 0; i < object.vertices_len; i++) + { + printf("%f, ", object.vertices[i++]); + printf("%f, ", object.vertices[i++]); + printf("%f\n", object.vertices[i]); + } + printf("yo %lu\n", object.vertices_len); + + t_ftmmat4 model; + t_ftmmat4 view; + t_ftmmat4 proj; t_ftmvec3 vec; - ftm_mat4init_eye(&trans, 1.0); - /* ftm_mat4translate(&trans, 0.5, 0.5, 0.0); */ + ftm_mat4init_eye(&model, 1.0); + ftm_mat4translate(&model, 0.0, 0.0, -5.0); + /* ftm_mat4rotate(&model, ftm_radian(45.0), ftm_vec3init(&vec, 0.0, 1.0, 0.0)); */ + /* ftm_mat4scale(&model, 1.1, 1.1, 1.1); */ - ftm_mat4rotate(&trans, ftm_radian(45.0), ftm_vec3init(&vec, 0.0, 0.0, 1.0)); + ftm_mat4init_eye(&view, 1.0); - /* ftm_mat4scale(&trans, 0.5, 0.5, 0.5); */ + ftm_mat4init_perspective(&proj, M_PI_2 / 2.0, 1.0, 0.1, 100.0); + + /* debugmat(&model); */ + /* debugmat(&view); */ + debugmat(&proj); - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++) - { - printf("%f, ", trans.m[i * 4 + j]); - } - printf("\n"); - } if ((window = glfw_init(400, 400)) == NULL || gl_state_init(&state, &object) == -1) @@ -84,7 +108,7 @@ int main(int argc, char **argv) GL_CALL(glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)); GL_CALL(glUseProgram(state.shader)); - gl_state_set_mvp(&state, &trans); + gl_state_set_mvp(&state, &model, &view, &proj); while (!glfwWindowShouldClose(window)) { @@ -92,8 +116,18 @@ int main(int argc, char **argv) GL_CALL(glClear(GL_COLOR_BUFFER_BIT)); GL_CALL(glUseProgram(state.shader)); - ftm_mat4rotate(&trans, ftm_radian(1.0), ftm_vec3init(&vec, 0.0, 0.0, 1.0)); - gl_state_set_mvp(&state, &trans); + ftm_mat4rotate(&model, ftm_radian(0.5), ftm_vec3init(&vec, 1.0, 0.0, 0.0)); + + if (g_window_resized) + { + int w, h; + glfwGetFramebufferSize(window, &w, &h); + printf("%d %d\n", w, h); + ftm_mat4init_perspective(&proj, M_PI_2 / 2.0, (float)w / (float)h, 0.1, 100.0); + g_window_resized = false; + } + + gl_state_set_mvp(&state, &model, &view, &proj); GL_CALL(glBindVertexArray(state.vertex_array)); GL_CALL(glDrawElements(GL_TRIANGLES, object.indices_len, GL_UNSIGNED_INT, (void*)0)); diff --git a/src/parse.c b/src/parse.c index 6290b1a..6f632d6 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/09 11:02:00 by charles #+# #+# */ -/* Updated: 2020/05/11 15:55:44 by charles ### ########.fr */ +/* Updated: 2020/05/12 18:38:56 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,15 @@ #define SCOP_VEC_DEFAULT_SIZE 64 +static void *st_iter_func_decrement_uint(void *void_uint) +{ + unsigned int uint; + + uint = *(unsigned int*)&void_uint; + uint--; + return (*(void**)&uint); +} + static int st_parse_face(char **indexes_strs, t_ftvec *indices) { size_t i; @@ -79,11 +88,14 @@ static int st_parse_file(int fd, t_ftvec *vertices, t_ftvec *indices) while ((ret = ft_getline(fd, &line)) == FT_LINE) { + printf("[%s]\n", line); ret = st_parse_line(line, vertices, indices); free(line); if (ret == -1) break ; } + printf(">>%d\n", ret); + printf("[%s]\n", line); if (ret == FT_ERROR) return (-1); if (*line != '\0') @@ -109,6 +121,7 @@ int parse(char *filepath, t_object *object) if ((indices = ft_vecnew(SCOP_VEC_DEFAULT_SIZE)) == NULL) return (-1); st_parse_file(fd, vertices, indices); + ft_veciter_ret(indices, st_iter_func_decrement_uint); object->vertices = (float*)ft_vectobuf32(vertices); object->indices = (unsigned int*)ft_vectobuf32(indices); object->vertices_len = vertices->size; diff --git a/vendor/libft b/vendor/libft -Subproject b9f000a80cbba38b8f21c9737a42f07573ec7b9 +Subproject 966eb29634a84496e0851ef2b5a7d64f413d33e diff --git a/vendor/libftm/Makefile b/vendor/libftm/Makefile index 10b2bbd..c33bd78 100644 --- a/vendor/libftm/Makefile +++ b/vendor/libftm/Makefile @@ -6,12 +6,14 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/05/09 20:44:53 by charles #+# #+# # -# Updated: 2020/05/12 11:43:06 by charles ### ########.fr # +# Updated: 2020/05/12 16:03:51 by charles ### ########.fr # # # # **************************************************************************** # LIB = ar rcs RM = rm -f +MAKE = make --no-print-directory +JOBS = 4 SRC_DIR = src INC_DIR = inc @@ -29,21 +31,26 @@ OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) OBJ_SUB_DIR = $(shell find $(SRC_DIR) -type d | sed 's/$(SRC_DIR)/$(OBJ_DIR)/') -all: prebuild $(NAME) +all: prebuild + @$(MAKE) -j$(JOBS) $(NAME) prebuild: - mkdir -p $(OBJ_DIR) $(OBJ_SUB_DIR) + @mkdir -p $(OBJ_DIR) $(OBJ_SUB_DIR) $(NAME): $(OBJ) $(INC) - $(LIB) $@ $(OBJ) + @echo "Linking: $@" + @$(LIB) $@ $(OBJ) $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c - $(CC) $(CCFLAGS) -c -o $@ $< + @echo "Compiling: $@" + @$(CC) $(CCFLAGS) -c -o $@ $< clean: - $(RM) $(OBJ) + @echo "Removing objects" + @$(RM) $(OBJ) fclean: clean - $(RM) $(NAME) + @echo "Removing $(NAME)" + @$(RM) $(NAME) re: fclean all diff --git a/vendor/libftm/inc/libftm_mat4.h b/vendor/libftm/inc/libftm_mat4.h index f69d7e6..5fc183b 100644 --- a/vendor/libftm/inc/libftm_mat4.h +++ b/vendor/libftm/inc/libftm_mat4.h @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/12 11:04:59 by charles #+# #+# */ -/* Updated: 2020/05/12 13:53:40 by charles ### ########.fr */ +/* Updated: 2020/05/12 17:21:34 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,33 @@ typedef struct float m[4 * 4]; } t_ftmmat4; +/* +** http://www.songho.ca/opengl/gl_projectionmatrix.html +*/ + +typedef struct +{ + float near; + float far; + float left; + float right; + float top; + float bottom; +} t_ftmfrustum; + +typedef struct +{ + float near; + float far; + float width; + float height; +} t_ftmfrustum_sym; + t_ftmmat4 *ftm_mat4init_eye(t_ftmmat4 *mat4, float x); t_ftmmat4 *ftm_mat4init_fill(t_ftmmat4 *mat4, float x); +t_ftmmat4 *ftm_mat4init_frustum(t_ftmmat4 *mat4, t_ftmfrustum *frustum); +t_ftmmat4 *ftm_mat4init_frustum_sym(t_ftmmat4 *mat4, t_ftmfrustum_sym *frustum); +t_ftmmat4 *ftm_mat4init_perspective(t_ftmmat4 *mat4, float fov, float aspect_ratio, float near, float far); t_ftmmat4 *ftm_mat4translate(t_ftmmat4 *mat4, float x, float y, float z); t_ftmmat4 *ftm_mat4rotate(t_ftmmat4 *mat4, float radian, t_ftmvec3 *axis); t_ftmmat4 *ftm_mat4scale(t_ftmmat4 *mat4, float x, float y, float z); diff --git a/vendor/libftm/src/mat4/ftm_mat4init_frustum.c b/vendor/libftm/src/mat4/ftm_mat4init_frustum.c new file mode 100644 index 0000000..1ba30b2 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_frustum.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4init_frustum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 15:37:26 by charles #+# #+# */ +/* Updated: 2020/05/12 17:29:53 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4init_frustum(t_ftmmat4 *mat4, t_ftmfrustum *frustum) +{ + ftm_mat4init_fill(mat4, 0.0); + + ftm_mat4set(mat4, 0, 0, (2.0 * frustum->near) / (frustum->right - frustum->left)); + ftm_mat4set(mat4, 1, 1, (2.0 * frustum->near) / (frustum->top - frustum->bottom)); + ftm_mat4set(mat4, 2, 2, (-(frustum->far + frustum->near)) / (frustum->far - frustum->near)); + ftm_mat4set(mat4, 0, 2, (frustum->right + frustum->left) / (frustum->right - frustum->left)); + ftm_mat4set(mat4, 1, 2, (frustum->top + frustum->bottom) / (frustum->top - frustum->bottom)); + ftm_mat4set(mat4, 2, 3, (-2.0 * frustum->far * frustum->near) / (frustum->far - frustum->near)); + ftm_mat4set(mat4, 3, 2, -1.0); + return (mat4); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c b/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c new file mode 100644 index 0000000..2763765 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_frustum_sym.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4init_frustum_sym.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 15:47:45 by charles #+# #+# */ +/* Updated: 2020/05/12 17:21:06 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4init_frustum_sym(t_ftmmat4 *mat4, t_ftmfrustum_sym *frustum) +{ + t_ftmfrustum f; + + f.right = frustum->width / 2; + f.left = -f.right; + f.top = frustum->height / 2; + f.bottom = -f.top; + f.near = frustum->near; + f.far = frustum->far; + return (ftm_mat4init_frustum(mat4, &f)); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4init_perspective.c b/vendor/libftm/src/mat4/ftm_mat4init_perspective.c new file mode 100644 index 0000000..f04b39e --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_perspective.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ftm_mat4init_perspective.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 16:54:49 by charles #+# #+# */ +/* Updated: 2020/05/12 19:07:45 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftm_mat4.h" + +t_ftmmat4 *ftm_mat4init_perspective(t_ftmmat4 *mat4, float fov, float aspect_ratio, + float near, float far) +{ + t_ftmfrustum_sym frustum; + + frustum.near = near; + frustum.far = far; + frustum.width = 2.0 * (near / tanf(M_PI_2 - (fov / 2.0))); + frustum.height = frustum.width / aspect_ratio; + return (ftm_mat4init_frustum_sym(mat4, &frustum)); +} diff --git a/vendor/libftm/src/mat4/ftm_mat4init_proj.c b/vendor/libftm/src/mat4/ftm_mat4init_proj.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/vendor/libftm/src/mat4/ftm_mat4init_proj.c diff --git a/vendor/libftm/src/mat4/ftm_mat4rotate.c b/vendor/libftm/src/mat4/ftm_mat4rotate.c index 0a39c16..6d0432e 100644 --- a/vendor/libftm/src/mat4/ftm_mat4rotate.c +++ b/vendor/libftm/src/mat4/ftm_mat4rotate.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/05/12 11:44:18 by charles #+# #+# */ -/* Updated: 2020/05/12 14:05:18 by charles ### ########.fr */ +/* Updated: 2020/05/12 17:07:23 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,8 +46,8 @@ t_ftmmat4 *ftm_mat4rotate(t_ftmmat4 *mat4, float theta, t_ftmvec3 *axis) x = axis->v[0]; y = axis->v[1]; z = axis->v[2]; - sin_t = sin(theta); - cos_t = cos(theta); + sin_t = sinf(theta); + cos_t = cosf(theta); ftm_mat4init_fill(&rot, 0.0); ftm_mat4set(&rot, 0, 0, cos_t + x * x * (1 - cos_t)); ftm_mat4set(&rot, 1, 0, y * x * (1 - cos_t) + z * sin_t); |
