mat4_multiply
This commit is contained in:
parent
430092bb1d
commit
c2b5bb8de0
3
Makefile
3
Makefile
|
@ -6,7 +6,7 @@
|
|||
# By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2020/12/17 19:47:03 by gbrochar #+# #+# #
|
||||
# Updated: 2020/12/22 20:49:38 by gbrochar ### ########.fr #
|
||||
# Updated: 2020/12/23 10:49:53 by gbrochar ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -17,6 +17,7 @@ SRC_FILE = main.c \
|
|||
parse_line.c \
|
||||
env.c \
|
||||
mat4_transpose.c \
|
||||
mat4_multiply.c \
|
||||
|
||||
OBJ_FILE = $(SRC_FILE:.c=.o)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 20:35:00 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/22 20:48:29 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/23 10:50:09 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -20,4 +20,8 @@ struct s_mat4
|
|||
double data[16];
|
||||
};
|
||||
|
||||
t_mat4 mat4_transpose(t_mat4 m);
|
||||
t_mat4 mat4_multiply(t_mat4 m, t_mat4 rhs);
|
||||
t_mat4 mat4_multiply_tmp(t_mat4 m, t_mat4 rhs);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* mat4_mul.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/23 10:39:09 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/23 10:49:28 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "mat4.h"
|
||||
|
||||
t_mat4 mat4_multiply_tmp(t_mat4 m, t_mat4 rhs)
|
||||
{
|
||||
t_mat4 out;
|
||||
|
||||
out.data[0] = rhs.data[0] * m.data[0] + rhs.data[1] * m.data[4]
|
||||
+ rhs.data[2] * m.data[8] + rhs.data[3] * m.data[12];
|
||||
out.data[1] = rhs.data[0] * m.data[1] + rhs.data[1] * m.data[5]
|
||||
+ rhs.data[2] * m.data[9] + rhs.data[3] * m.data[13];
|
||||
out.data[2] = rhs.data[0] * m.data[2] + rhs.data[1] * m.data[6]
|
||||
+ rhs.data[2] * m.data[10] + rhs.data[3] * m.data[14];
|
||||
out.data[3] = rhs.data[0] * m.data[3] + rhs.data[1] * m.data[7]
|
||||
+ rhs.data[2] * m.data[11] + rhs.data[3] * m.data[15];
|
||||
out.data[4] = rhs.data[4] * m.data[0] + rhs.data[5] * m.data[4]
|
||||
+ rhs.data[6] * m.data[8] + rhs.data[7] * m.data[12];
|
||||
out.data[5] = rhs.data[4] * m.data[1] + rhs.data[5] * m.data[5]
|
||||
+ rhs.data[6] * m.data[9] + rhs.data[7] * m.data[13];
|
||||
out.data[6] = rhs.data[4] * m.data[2] + rhs.data[5] * m.data[6]
|
||||
+ rhs.data[6] * m.data[10] + rhs.data[7] * m.data[14];
|
||||
out.data[7] = rhs.data[4] * m.data[3] + rhs.data[5] * m.data[7]
|
||||
+ rhs.data[6] * m.data[11] + rhs.data[7] * m.data[15];
|
||||
out.data[8] = rhs.data[8] * m.data[0] + rhs.data[9] * m.data[4]
|
||||
+ rhs.data[10] * m.data[8] + rhs.data[11] * m.data[12];
|
||||
return (out);
|
||||
}
|
||||
|
||||
t_mat4 mat4_multiply(t_mat4 m, t_mat4 rhs)
|
||||
{
|
||||
t_mat4 out;
|
||||
|
||||
out = mat4_multiply_tmp(m, rhs);
|
||||
out.data[9] = rhs.data[8] * m.data[1] + rhs.data[9] * m.data[5]
|
||||
+ rhs.data[10] * m.data[9] + rhs.data[11] * m.data[13];
|
||||
out.data[10] = rhs.data[8] * m.data[2] + rhs.data[9] * m.data[6]
|
||||
+ rhs.data[10] * m.data[10] + rhs.data[11] * m.data[14];
|
||||
out.data[11] = rhs.data[8] * m.data[3] + rhs.data[9] * m.data[7]
|
||||
+ rhs.data[10] * m.data[11] + rhs.data[11] * m.data[15];
|
||||
out.data[12] = rhs.data[12] * m.data[0] + rhs.data[13] * m.data[4]
|
||||
+ rhs.data[14] * m.data[8] + rhs.data[15] * m.data[12];
|
||||
out.data[13] = rhs.data[12] * m.data[1] + rhs.data[13] * m.data[5]
|
||||
+ rhs.data[14] * m.data[9] + rhs.data[15] * m.data[13];
|
||||
out.data[14] = rhs.data[12] * m.data[2] + rhs.data[13] * m.data[6]
|
||||
+ rhs.data[14] * m.data[10] + rhs.data[15] * m.data[14];
|
||||
out.data[15] = rhs.data[12] * m.data[3] + rhs.data[13] * m.data[7]
|
||||
+ rhs.data[14] * m.data[11] + rhs.data[15] * m.data[15];
|
||||
return (out);
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gbrochar <gbrochar@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2020/12/22 20:34:52 by gbrochar #+# #+# */
|
||||
/* Updated: 2020/12/22 20:48:21 by gbrochar ### ########.fr */
|
||||
/* Updated: 2020/12/23 10:50:15 by gbrochar ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
Loading…
Reference in New Issue