I have the following parallel projection (Row major):
Before I apply the projection I use the following matrix to apply a transformation on the original points:
When in reality it should be giving me this (image not centered):
n is 0.1 and f is 100 The origin is in the middle of the wireframe and the 42 wireframe height is in the z direction.
My matrix multiplication:
typedef struct s_point
{
float x;
float y;
float z;
int c; //color
} t_point;
void multiply_matrix_vector(t_point *i, t_point *o, t_pmatrix *m)
{
float w;
o->x = i->x * m->m[0][0] i->y * m->m[1][0] i->z * m->m[2][0] m->m[3][0];
o->y = i->x * m->m[0][1] i->y * m->m[1][1] i->z * m->m[2][1] m->m[3][1];
o->z = i->x * m->m[0][2] i->y * m->m[1][2] i->z * m->m[2][2] m->m[3][2];
w = i->x * m->m[0][3] i->y * m->m[1][3] i->z * m->m[2][3] m->m[3][3];
if (w != 0.0f)
{
o->x /= w;
o->y /= w;
o->z /= w;
}
o->c = i->c;
}
What am I doing wrong?
CodePudding user response:
I remembered that I was having a hard time with matrix multiplication before and that probably I might had screwed a sign or a trigonometric function. I double checked everything and but all was ok. Still the result was flipped on the y axis so what I did was this:
On the first matrix at [1][1]
I just changed the 1
for -1
Matrices are tricky because the multiplication order matters more than one would think