chore: remove norm from headers
This commit is contained in:
parent
7bc350942d
commit
dadd6998cb
36
inc/mat4.h
36
inc/mat4.h
|
@ -1,15 +1,3 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* mat4.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/12/22 20:35:00 by gbrochar #+# #+# */
|
|
||||||
/* Updated: 2020/12/26 09:16:18 by gbrochar ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef MAT4_H
|
#ifndef MAT4_H
|
||||||
# define MAT4_H
|
# define MAT4_H
|
||||||
|
|
||||||
|
@ -20,13 +8,11 @@
|
||||||
typedef struct s_mat4 t_mat4;
|
typedef struct s_mat4 t_mat4;
|
||||||
typedef struct s_persp_tool t_persp_tool;
|
typedef struct s_persp_tool t_persp_tool;
|
||||||
|
|
||||||
struct s_mat4
|
struct s_mat4 {
|
||||||
{
|
|
||||||
float data[16];
|
float data[16];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_persp_tool
|
struct s_persp_tool {
|
||||||
{
|
|
||||||
double xmin;
|
double xmin;
|
||||||
double xmax;
|
double xmax;
|
||||||
double ymin;
|
double ymin;
|
||||||
|
@ -34,33 +20,21 @@ struct s_persp_tool
|
||||||
};
|
};
|
||||||
|
|
||||||
t_mat4 mat4_transpose(t_mat4 m);
|
t_mat4 mat4_transpose(t_mat4 m);
|
||||||
|
|
||||||
t_mat4 mat4_multiply(t_mat4 m, t_mat4 rhs);
|
t_mat4 mat4_multiply(t_mat4 m, t_mat4 rhs);
|
||||||
|
t_mat4 mat4_perspective(double fov, double aspect, double near, double far);
|
||||||
t_mat4 mat4_perspective(
|
t_mat4 mat4_frustrum(t_persp_tool tool, double near, double far);
|
||||||
double fov, double aspect, double near, double far);
|
|
||||||
t_mat4 mat4_frustrum(
|
|
||||||
t_persp_tool tool, double near, double far);
|
|
||||||
t_mat4 mat4_frustrum_tmp(double x, double y, t_vec4 tool);
|
|
||||||
|
|
||||||
t_mat4 mat4_lookat(t_vec3 eye, t_vec3 up, t_vec3 target);
|
t_mat4 mat4_lookat(t_vec3 eye, t_vec3 up, t_vec3 target);
|
||||||
t_mat4 mat4_lookat_make_mat(
|
t_mat4 mat4_lookat_make_mat(t_vec3 x, t_vec3 y, t_vec3 z, t_vec3 eye);
|
||||||
t_vec3 x, t_vec3 y, t_vec3 z, t_vec3 eye);
|
|
||||||
t_vec3 mat4_lookat_make_y(t_vec3 x, t_vec3 z);
|
t_vec3 mat4_lookat_make_y(t_vec3 x, t_vec3 z);
|
||||||
t_vec3 mat4_lookat_make_x(t_vec3 z, t_vec3 up);
|
t_vec3 mat4_lookat_make_x(t_vec3 z, t_vec3 up);
|
||||||
t_vec3 mat4_lookat_make_z(t_vec3 eye, t_vec3 target);
|
t_vec3 mat4_lookat_make_z(t_vec3 eye, t_vec3 target);
|
||||||
|
|
||||||
t_mat4 mat4_identity(void);
|
t_mat4 mat4_identity(void);
|
||||||
|
|
||||||
t_mat4 mat4_inverse(t_mat4 m);
|
t_mat4 mat4_inverse(t_mat4 m);
|
||||||
|
|
||||||
t_mat4 mat4_rotatex(t_mat4 m, double theta);
|
t_mat4 mat4_rotatex(t_mat4 m, double theta);
|
||||||
t_mat4 mat4_rotatey(t_mat4 m, double theta);
|
t_mat4 mat4_rotatey(t_mat4 m, double theta);
|
||||||
t_mat4 mat4_rotatez(t_mat4 m, double theta);
|
t_mat4 mat4_rotatez(t_mat4 m, double theta);
|
||||||
t_mat4 mat4_rotatexyz(t_mat4 m, t_vec3 theta);
|
t_mat4 mat4_rotatexyz(t_mat4 m, t_vec3 theta);
|
||||||
|
|
||||||
t_mat4 mat4_translate(t_mat4 m, t_vec3 t);
|
t_mat4 mat4_translate(t_mat4 m, t_vec3 t);
|
||||||
|
|
||||||
t_mat4 mat4_scale(t_mat4 m, t_vec3 s);
|
t_mat4 mat4_scale(t_mat4 m, t_vec3 s);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
43
inc/scop.h
43
inc/scop.h
|
@ -1,15 +1,3 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* scop.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */
|
|
||||||
/* Updated: 2020/12/26 09:16:30 by gbrochar ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef SCOP_H
|
#ifndef SCOP_H
|
||||||
# define SCOP_H
|
# define SCOP_H
|
||||||
|
|
||||||
|
@ -36,8 +24,7 @@
|
||||||
|
|
||||||
typedef enum e_gl_buf_type t_gl_buf_type;
|
typedef enum e_gl_buf_type t_gl_buf_type;
|
||||||
|
|
||||||
enum e_gl_buf_type
|
enum e_gl_buf_type {
|
||||||
{
|
|
||||||
VERTEX,
|
VERTEX,
|
||||||
UV,
|
UV,
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
@ -53,36 +40,31 @@ typedef struct s_buf_s t_buf_s;
|
||||||
typedef struct s_obj t_obj;
|
typedef struct s_obj t_obj;
|
||||||
typedef struct s_env t_env;
|
typedef struct s_env t_env;
|
||||||
|
|
||||||
struct s_cam
|
struct s_cam {
|
||||||
{
|
|
||||||
double fov;
|
double fov;
|
||||||
double aspect;
|
double aspect;
|
||||||
double near;
|
double near;
|
||||||
double far;
|
double far;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_window
|
struct s_window {
|
||||||
{
|
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_buf_d
|
struct s_buf_d {
|
||||||
{
|
|
||||||
double *data;
|
double *data;
|
||||||
size_t ptr;
|
size_t ptr;
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_buf_ui
|
struct s_buf_ui {
|
||||||
{
|
|
||||||
unsigned int *data;
|
unsigned int *data;
|
||||||
size_t ptr;
|
size_t ptr;
|
||||||
size_t len;
|
size_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_obj
|
struct s_obj {
|
||||||
{
|
|
||||||
t_buf_d vertices;
|
t_buf_d vertices;
|
||||||
t_buf_d uvs;
|
t_buf_d uvs;
|
||||||
t_buf_d normals;
|
t_buf_d normals;
|
||||||
|
@ -91,8 +73,7 @@ struct s_obj
|
||||||
t_buf_ui normals_indices;
|
t_buf_ui normals_indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct s_env
|
struct s_env {
|
||||||
{
|
|
||||||
char *file_name;
|
char *file_name;
|
||||||
t_cam camera;
|
t_cam camera;
|
||||||
t_window window;
|
t_window window;
|
||||||
|
@ -111,19 +92,15 @@ int parse_file(t_env *e);
|
||||||
|
|
||||||
int parse_line(t_env *e, char *line);
|
int parse_line(t_env *e, char *line);
|
||||||
t_gl_buf_type parse_gl_buf_type(char *token);
|
t_gl_buf_type parse_gl_buf_type(char *token);
|
||||||
void parse_triangulate(
|
void parse_triangulate(t_buf_ui *indices, int token_count);
|
||||||
t_buf_ui *indices, int token_count);
|
void parse_append_data_tmp(t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
|
||||||
void parse_append_data_tmp(
|
|
||||||
t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
|
|
||||||
|
|
||||||
int parse_token(
|
int parse_token(t_env *e, char *token, t_gl_buf_type gl_buf_type);
|
||||||
t_env *e, char *token, t_gl_buf_type gl_buf_type);
|
|
||||||
int parse_append_data_d(t_buf_d *buffer, char *token);
|
int parse_append_data_d(t_buf_d *buffer, char *token);
|
||||||
int parse_append_data_ui(t_buf_ui *buffer, char *token);
|
int parse_append_data_ui(t_buf_ui *buffer, char *token);
|
||||||
|
|
||||||
void center_vertices(t_buf_d *vertices);
|
void center_vertices(t_buf_d *vertices);
|
||||||
|
|
||||||
|
|
||||||
void free_env(t_env *e);
|
void free_env(t_env *e);
|
||||||
void init_window(t_env *e);
|
void init_window(t_env *e);
|
||||||
void init_camera(t_env *e);
|
void init_camera(t_env *e);
|
||||||
|
|
16
inc/vec3.h
16
inc/vec3.h
|
@ -1,25 +1,13 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* vec3.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/12/23 16:14:13 by gbrochar #+# #+# */
|
|
||||||
/* Updated: 2020/12/23 16:14:28 by gbrochar ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef VEC3_H
|
#ifndef VEC3_H
|
||||||
# define VEC3_H
|
# define VEC3_H
|
||||||
|
|
||||||
typedef struct s_vec3 t_vec3;
|
typedef struct s_vec3 t_vec3;
|
||||||
|
|
||||||
struct s_vec3
|
struct s_vec3 {
|
||||||
{
|
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
double z;
|
double z;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
13
inc/vec4.h
13
inc/vec4.h
|
@ -1,15 +1,3 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* vec4.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2020/12/23 15:57:23 by gbrochar #+# #+# */
|
|
||||||
/* Updated: 2020/12/23 16:00:12 by gbrochar ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef VEC4_H
|
#ifndef VEC4_H
|
||||||
# define VEC4_H
|
# define VEC4_H
|
||||||
|
|
||||||
|
@ -24,3 +12,4 @@ struct s_vec4
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -13,34 +13,12 @@
|
||||||
#include "mat4.h"
|
#include "mat4.h"
|
||||||
#include "vec4.h"
|
#include "vec4.h"
|
||||||
|
|
||||||
t_mat4 mat4_frustrum_tmp(double x, double y, t_vec4 tool)
|
|
||||||
{
|
|
||||||
t_mat4 ret;
|
|
||||||
|
|
||||||
ret.data[0] = x;
|
|
||||||
ret.data[4] = 0;
|
|
||||||
ret.data[8] = tool.x;
|
|
||||||
ret.data[12] = 0;
|
|
||||||
ret.data[1] = 0;
|
|
||||||
ret.data[5] = y;
|
|
||||||
ret.data[9] = tool.y;
|
|
||||||
ret.data[13] = 0;
|
|
||||||
ret.data[2] = 0;
|
|
||||||
ret.data[6] = 0;
|
|
||||||
ret.data[10] = tool.z;
|
|
||||||
ret.data[14] = tool.w;
|
|
||||||
ret.data[3] = 0;
|
|
||||||
ret.data[7] = 0;
|
|
||||||
ret.data[11] = -1;
|
|
||||||
ret.data[15] = 0;
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_mat4 mat4_frustrum(t_persp_tool tool, double near, double far)
|
t_mat4 mat4_frustrum(t_persp_tool tool, double near, double far)
|
||||||
{
|
{
|
||||||
double x;
|
double x;
|
||||||
double y;
|
double y;
|
||||||
t_vec4 tool2;
|
t_vec4 tool2;
|
||||||
|
t_mat4 frustrum;
|
||||||
|
|
||||||
x = (2.0 * near) / (tool.xmax - tool.xmin);
|
x = (2.0 * near) / (tool.xmax - tool.xmin);
|
||||||
y = (2.0 * near) / (tool.ymax - tool.ymin);
|
y = (2.0 * near) / (tool.ymax - tool.ymin);
|
||||||
|
@ -48,7 +26,23 @@ t_mat4 mat4_frustrum(t_persp_tool tool, double near, double far)
|
||||||
tool2.y = (tool.ymax + tool.ymin) / (tool.ymax - tool.ymin);
|
tool2.y = (tool.ymax + tool.ymin) / (tool.ymax - tool.ymin);
|
||||||
tool2.z = -(far + near) / (far - near);
|
tool2.z = -(far + near) / (far - near);
|
||||||
tool2.w = (-2.0 * far * near) / (far - near);
|
tool2.w = (-2.0 * far * near) / (far - near);
|
||||||
return (mat4_frustrum_tmp(x, y, tool2));
|
frustrum.data[0] = x;
|
||||||
|
frustrum.data[4] = 0;
|
||||||
|
frustrum.data[8] = tool2.x;
|
||||||
|
frustrum.data[12] = 0;
|
||||||
|
frustrum.data[1] = 0;
|
||||||
|
frustrum.data[5] = y;
|
||||||
|
frustrum.data[9] = tool2.y;
|
||||||
|
frustrum.data[13] = 0;
|
||||||
|
frustrum.data[2] = 0;
|
||||||
|
frustrum.data[6] = 0;
|
||||||
|
frustrum.data[10] = tool2.z;
|
||||||
|
frustrum.data[14] = tool2.w;
|
||||||
|
frustrum.data[3] = 0;
|
||||||
|
frustrum.data[7] = 0;
|
||||||
|
frustrum.data[11] = -1;
|
||||||
|
frustrum.data[15] = 0;
|
||||||
|
return frustrum;
|
||||||
}
|
}
|
||||||
|
|
||||||
t_mat4 mat4_perspective(
|
t_mat4 mat4_perspective(
|
||||||
|
@ -60,5 +54,6 @@ t_mat4 mat4_perspective(
|
||||||
tool.ymin = -tool.ymax;
|
tool.ymin = -tool.ymax;
|
||||||
tool.xmin = tool.ymin * aspect;
|
tool.xmin = tool.ymin * aspect;
|
||||||
tool.xmax = tool.ymax * aspect;
|
tool.xmax = tool.ymax * aspect;
|
||||||
return (mat4_frustrum(tool, near, far));
|
return mat4_frustrum(tool, near, far);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ float rand(float n)
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
|
vec3 color = vec3(rand(float(vID + int(time))), rand(float(vID + int(time))), rand(float(vID + int(time))));
|
||||||
FragColor = vec4(color * 0.001 + texture(ourTexture, gl_FragCoord.xy / vec2(480., 360.)).rgb, 1.0);
|
FragColor = vec4(color, 1.);
|
||||||
|
//FragColor = vec4(color * 0.001 + texture(ourTexture, gl_FragCoord.xy / vec2(480., 360.)).rgb, 1.0);
|
||||||
//FragColor = vec4(color * 0.1 + texture(ourTexture, gl_FragCoord.xy).rgb, 1.0);
|
//FragColor = vec4(color * 0.1 + texture(ourTexture, gl_FragCoord.xy).rgb, 1.0);
|
||||||
//FragColor = vec4(color * 0.01 + texture2D(ourTexture, gl_FragCoord.xy / vec2(480., 360.)).rgb, 1.0);
|
//FragColor = vec4(color * 0.01 + texture2D(ourTexture, gl_FragCoord.xy / vec2(480., 360.)).rgb, 1.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue