chore: remove norm from headers

This commit is contained in:
gbrochar 2024-04-24 20:40:56 +02:00
parent 7bc350942d
commit dadd6998cb
6 changed files with 121 additions and 197 deletions

View File

@ -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
# define MAT4_H
@ -17,51 +5,37 @@
# include "vec3.h"
# include <math.h>
typedef struct s_mat4 t_mat4;
typedef struct s_persp_tool t_persp_tool;
typedef struct s_mat4 t_mat4;
typedef struct s_persp_tool t_persp_tool;
struct s_mat4
{
float data[16];
struct s_mat4 {
float data[16];
};
struct s_persp_tool
{
double xmin;
double xmax;
double ymin;
double ymax;
struct s_persp_tool {
double xmin;
double xmax;
double ymin;
double ymax;
};
t_mat4 mat4_transpose(t_mat4 m);
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_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_make_mat(
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_x(t_vec3 z, t_vec3 up);
t_vec3 mat4_lookat_make_z(t_vec3 eye, t_vec3 target);
t_mat4 mat4_identity(void);
t_mat4 mat4_inverse(t_mat4 m);
t_mat4 mat4_rotatex(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_rotatexyz(t_mat4 m, t_vec3 theta);
t_mat4 mat4_translate(t_mat4 m, t_vec3 t);
t_mat4 mat4_scale(t_mat4 m, t_vec3 s);
t_mat4 mat4_transpose(t_mat4 m);
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_frustrum(t_persp_tool tool, double near, double far);
t_mat4 mat4_lookat(t_vec3 eye, t_vec3 up, t_vec3 target);
t_mat4 mat4_lookat_make_mat(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_x(t_vec3 z, t_vec3 up);
t_vec3 mat4_lookat_make_z(t_vec3 eye, t_vec3 target);
t_mat4 mat4_identity(void);
t_mat4 mat4_inverse(t_mat4 m);
t_mat4 mat4_rotatex(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_rotatexyz(t_mat4 m, t_vec3 theta);
t_mat4 mat4_translate(t_mat4 m, t_vec3 t);
t_mat4 mat4_scale(t_mat4 m, t_vec3 s);
#endif

View File

@ -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
# define SCOP_H
@ -34,10 +22,9 @@
# define EPSILON 0.000001
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,
UV,
NORMAL,
@ -45,92 +32,82 @@ enum e_gl_buf_type
OTHER
};
typedef struct s_cam t_cam;
typedef struct s_window t_window;
typedef struct s_buf_d t_buf_d;
typedef struct s_buf_ui t_buf_ui;
typedef struct s_buf_s t_buf_s;
typedef struct s_obj t_obj;
typedef struct s_env t_env;
typedef struct s_cam t_cam;
typedef struct s_window t_window;
typedef struct s_buf_d t_buf_d;
typedef struct s_buf_ui t_buf_ui;
typedef struct s_buf_s t_buf_s;
typedef struct s_obj t_obj;
typedef struct s_env t_env;
struct s_cam
{
double fov;
double aspect;
double near;
double far;
struct s_cam {
double fov;
double aspect;
double near;
double far;
};
struct s_window
{
int width;
int height;
struct s_window {
int width;
int height;
};
struct s_buf_d
{
double *data;
size_t ptr;
size_t len;
struct s_buf_d {
double *data;
size_t ptr;
size_t len;
};
struct s_buf_ui
{
unsigned int *data;
size_t ptr;
size_t len;
struct s_buf_ui {
unsigned int *data;
size_t ptr;
size_t len;
};
struct s_obj
{
t_buf_d vertices;
t_buf_d uvs;
t_buf_d normals;
t_buf_ui vertices_indices;
t_buf_ui uvs_indices;
t_buf_ui normals_indices;
struct s_obj {
t_buf_d vertices;
t_buf_d uvs;
t_buf_d normals;
t_buf_ui vertices_indices;
t_buf_ui uvs_indices;
t_buf_ui normals_indices;
};
struct s_env
{
char *file_name;
t_cam camera;
t_window window;
t_obj object;
GLuint shader_program;
GLuint vertex_shader;
GLuint fragment_shader;
t_vec3 translate;
t_vec3 rotate;
t_vec3 scale;
struct s_env {
char *file_name;
t_cam camera;
t_window window;
t_obj object;
GLuint shader_program;
GLuint vertex_shader;
GLuint fragment_shader;
t_vec3 translate;
t_vec3 rotate;
t_vec3 scale;
};
int parse(t_env *e, int argc, char **argv);
void set_params(t_env *e, int argc, char **argv);
int parse_file(t_env *e);
int parse(t_env *e, int argc, char **argv);
void set_params(t_env *e, int argc, char **argv);
int parse_file(t_env *e);
int parse_line(t_env *e, char *line);
t_gl_buf_type parse_gl_buf_type(char *token);
void parse_triangulate(
t_buf_ui *indices, int token_count);
void parse_append_data_tmp(
t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
int parse_line(t_env *e, char *line);
t_gl_buf_type parse_gl_buf_type(char *token);
void parse_triangulate(t_buf_ui *indices, int token_count);
void parse_append_data_tmp(t_buf_ui *indices, int vertex_count, unsigned int *data_tmp);
int parse_token(
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_ui(t_buf_ui *buffer, char *token);
int parse_token(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_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 init_window(t_env *e);
void init_camera(t_env *e);
void init_object(t_env *e);
void init_env(t_env *e);
void free_env(t_env *e);
void init_window(t_env *e);
void init_camera(t_env *e);
void init_object(t_env *e);
void init_env(t_env *e);
int run(t_env *e);
int run(t_env *e);
#endif

View File

@ -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
# define VEC3_H
typedef struct s_vec3 t_vec3;
typedef struct s_vec3 t_vec3;
struct s_vec3
{
double x;
double y;
double z;
struct s_vec3 {
double x;
double y;
double z;
};
#endif

View File

@ -1,26 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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
# define VEC4_H
typedef struct s_vec4 t_vec4;
typedef struct s_vec4 t_vec4;
struct s_vec4
struct s_vec4
{
double x;
double y;
double z;
double w;
double x;
double y;
double z;
double w;
};
#endif

View File

@ -13,34 +13,12 @@
#include "mat4.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)
{
double x;
double y;
t_vec4 tool2;
t_mat4 frustrum;
x = (2.0 * near) / (tool.xmax - tool.xmin);
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.z = -(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(
@ -60,5 +54,6 @@ t_mat4 mat4_perspective(
tool.ymin = -tool.ymax;
tool.xmin = tool.ymin * aspect;
tool.xmax = tool.ymax * aspect;
return (mat4_frustrum(tool, near, far));
return mat4_frustrum(tool, near, far);
}

View File

@ -15,7 +15,8 @@ float rand(float n)
void main()
{
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.01 + texture2D(ourTexture, gl_FragCoord.xy / vec2(480., 360.)).rgb, 1.0);
}