Beispiel #1
0
void			set_triangle(t_triangle *tr)
{
	tr->u = (sub_vec(tr->p2, tr->p1));
	tr->v = (sub_vec(tr->p3, tr->p1));
	tr->uu = dot_prod(tr->u, tr->u);
	tr->uv = dot_prod(tr->u, tr->v);
	tr->vv = dot_prod(tr->v, tr->v);
	tr->d = tr->uv * tr->uv - tr->uu * tr->vv;
	tr->n = normalizator_ret(prod_vector(tr->u, tr->v));
}
Beispiel #2
0
void			check_triangle(t_item *item, t_pd *s, t_inter *inter, t_thr *f)
{
	t_vec		n;
	t_vec		a;
	FLOAT_SIZE	t;

	n = (prod_vector(item->tr->u, item->tr->v));
	a.x = -dot_prod(n, sub_vec(s->pos, item->tr->p1));
	a.y = dot_prod(n, s->dir);
	if (fabs(a.y) > 0 && (t = a.x / a.y) >= 0)
	{
		n = sub_vec(set_dist_pos(t, s->dir, s->pos), item->tr->p1);
		a.x = dot_prod(n, item->tr->u);
		a.y = dot_prod(n, item->tr->v);
		a.z = (a.y * item->tr->uv - item->tr->vv * a.x) / item->tr->d;
		a.y = (item->tr->uv * a.x - item->tr->uu * a.y) / item->tr->d;
		if (a.z < 0.0 || a.z > 1.0 || a.y < 0.0 || (a.y + a.z) > 1.0)
			return ;
		if (check_t(inter, t, s, item) == 1 && f->impactmod)
			inter->norm = item->tr->n;
	}
	return ;
}
Beispiel #3
0
void	get_rotation_all_matrix(t_transformation* t, t_vector* u, t_vector* v)
{
	t_vector	axis;
	double		angle;
	double		c;
	double		s;

	id_memset(&t->rotation_all, 0, sizeof(t->rotation_all));
	angle = acos(dot_vector(v, u));
	c = cos(angle);
	s = sin(angle);
	prod_vector(u, v, &axis);
	t->rotation_all[0] = id_pow(axis.x, 2) + (1 - id_pow(axis.x, 2)) * c;
	t->rotation_all[1] = axis.x * axis.y * (1 - c) - axis.z * s;
	t->rotation_all[2] = axis.x * axis.z * (1 - c) + axis.y * s;
	t->rotation_all[4] = axis.x * axis.y * (1 - c) + axis.z * s;
	t->rotation_all[5] = id_pow(axis.y, 2) + (1 - id_pow(axis.y, 2)) * c;
	t->rotation_all[6] = axis.y * axis.z * (1 - c) - axis.x * s;
	t->rotation_all[8] = axis.x * axis.z * (1 - c) - axis.y * s;
	t->rotation_all[9] = axis.y * axis.z * (1 - c) + axis.x * s;
	t->rotation_all[10] = id_pow(axis.z, 2) + (1 - id_pow(axis.z, 2)) * c;
	t->is_rotation_all = 1;
}