Exemplo n.º 1
0
Arquivo: mat4.c Projeto: nbouteme/rtv1
t_mat4	mat4_inverse(t_mat4 m)
{
	int		i;
	float	coefs[18];
	t_vec4	lenny[6][6];
	t_mat4	inverse;
	float	det;

	mat_invcoef(m, coefs);
	make_faces(coefs, lenny[0]);
	make_vecs(m, lenny[1]);
	make_inv(lenny[2], lenny[1], lenny[0], lenny[3]);
	i = -1;
	while (++i < 4)
	{
		inverse.s.v[i] = vec4_mul(lenny[2][i], lenny[3][i % 2]).s;
		lenny[5][0].v[i] = lenny[2][i].v[0];
	}
	lenny[4][0] = vec4_mul(m.s.v[0], lenny[5][0]);
	det = lenny[4][0].s.x + lenny[4][0].s.y + lenny[4][0].s.z + lenny[4][0].s.w;
	return (mat4_muls(inverse, 1.0f / det));
}
Exemplo n.º 2
0
static int _llfunc_vec4_mul(lua_State *L) {
	vec4 *v = (vec4*)userdata_get_or_die(L, 1);
	if (lua_isuserdata(L, 2)) {
		mat4 *m = (mat4*)lua_touserdata(L, 2);
		vec4 *r = (vec4*)userdata_get_or_new(L, 3, sizeof(vec4));
		vec4_mul_mat4(v, m, r);
	}
	else {
		float k = (float)luaL_checknumber(L, 2);
		vec4 *r = (vec4*)userdata_get_or_new(L, 3, sizeof(vec4));
		vec4_mul(v, k, r);
	}
	return 1;
}
Exemplo n.º 3
0
Arquivo: mat4.c Projeto: nbouteme/rtv1
void	make_inv(t_vec4 inv[4], t_vec4 vec[4], t_vec4 faces[6], t_vec4 sign[2])
{
	inv[0] = vec4_add(vec4_sub(vec4_mul(vec[1], faces[0]),
							vec4_mul(vec[2], faces[1])),
					vec4_mul(vec[3], faces[2]));
	inv[1] = vec4_add(vec4_sub(vec4_mul(vec[0], faces[0]),
							vec4_mul(vec[2], faces[3])),
					vec4_mul(vec[3], faces[4]));
	inv[2] = vec4_add(vec4_sub(vec4_mul(vec[0], faces[1]),
							vec4_mul(vec[1], faces[3])),
					vec4_mul(vec[3], faces[5]));
	inv[3] = vec4_add(vec4_sub(vec4_mul(vec[0], faces[2]),
							vec4_mul(vec[1], faces[4])),
					vec4_mul(vec[2], faces[5]));
	sign[0].s = (t_4dvec){+1, -1, +1, -1};
	sign[1].s = (t_4dvec){-1, +1, -1, +1};
}
Exemplo n.º 4
0
void SSBoneFrame_UpdateChangeDirCommand(struct ss_bone_frame_s *bf)
{
    float q[4], r[4], t[4], tt[4];
    //vec4_copy(q, bf->transform->M4x4 + 8);
    q[0] = 0.0f; q[1] = 0.0f; q[2] = 1.0f; q[3] = 0.0f;
    vec4_copy_inv(r, q);

    vec3_copy(t, bf->animations.prev_bf.pos);
    t[3] = 0.0f;
    vec4_mul(tt, q, t);
    vec4_mul(t, tt, r);
    vec3_copy(bf->animations.prev_bf.pos, t);
    
    vec3_copy(t, bf->animations.prev_bf.centre);
    t[3] = 0.0f;
    vec4_mul(tt, q, t);
    vec4_mul(t, tt, r);
    vec3_copy(bf->animations.prev_bf.centre, t);
    
    vec3_copy(t, bf->animations.prev_bf.bb_min);
    vec4_mul(tt, q, t);
    vec4_mul(t, tt, r);
    vec3_copy(bf->animations.prev_bf.bb_min, t);
    
    vec3_copy(t, bf->animations.prev_bf.bb_max);
    vec4_mul(tt, q, t);
    vec4_mul(t, tt, r);
    vec3_copy(bf->animations.prev_bf.bb_max, t);
    
    vec3_copy(t, bf->animations.prev_bf.bone_tags->offset);
    vec4_mul(tt, q, t);
    vec4_mul(t, tt, r);
    vec3_copy(bf->animations.prev_bf.bone_tags->offset, t);
    
    vec3_copy(t, bf->animations.prev_bf.bone_tags->qrotate);
    t[3] = 0.0f;
    vec4_mul(tt, q, t);
    vec3_copy(bf->animations.prev_bf.bone_tags->qrotate, tt);
}