void init_see(void) { short c,d,e; init_ray(0,-9); init_ray(1,-7); init_ray(2,+7); init_ray(3,+9); init_ray(4,-8); init_ray(5,+1); init_ray(6,+8); init_ray(7,-1); for(c=0;c<=63;c++) { for(d=0;d<=63;d++) { directions[c][d]=-1; for(e=0;e<=7;e++) if(ISSET(ray[c][e],d)) directions[c][d]=e; } } printf("...static exchange evaluator initialization done...\n"); }
int loop_hook(t_env *e) { t_rgb c; int x; if (e->img.img != NULL) { //Changed form mlx_destroy_image to this. mlx_destroy_image(e->mlx, e->img.img); e->img.img = NULL; } e->img.img = mlx_new_image(e->mlx, WIN_WIDTH, WIN_HEIGH); x = 0; while (x < WIN_WIDTH) { init_ray(e, x); ray_dir(e); perform_dda(e); compute(e); colors(e, &c); draw_line(x, e, &c); x++; } get_time_frame(e); move(e); mlx_put_image_to_window(e->mlx, e->win, e->img.img, 0, 0); return (0); }
int expose_hook(t_env *env) { double x; t_ray ray; t_dda dda; t_draw draw; env->old_time = clock(); x = 0; while (x <= env->vec.width) { init_ray(*env, &ray, x); init_dda(*env, ray, &dda); compute_dda(*env, &dda, ray); correction(&dda, ray); get_height(&draw, *env, dda); draw_walls(*env, draw, dda, x); draw_decor(*env, draw, x); x++; } mlx_put_image_to_window(env->mlx, env->win, env->img.img, 0, 0); env->time = clock(); compute_fps(*env); move(env); return (0); }
BOOL TraverseHierarchyUniform(RAY *r, IRECORD *hit, INT pid) { INT status; INT intersectPrim; VOXEL *v; r->ri = NULL; v = init_ray(r, gm->world_level_grid); if (v == NULL) { reset_rayinfo(r); return (FALSE); } intersectPrim = FALSE; hit[0].t = HUGE_REAL; status = IN_WORLD; while (!intersectPrim && status != EXITED_WORLD) { IntersectHuniformPrimlist(&intersectPrim, hit, v, r, pid); if (!intersectPrim) v = next_nonempty_leaf(r, STEP, &status); } reset_rayinfo(r); return (intersectPrim); }
t_vec raytracer(t_rayparams *params) { t_raytracer *ray; ray = init_ray(params->over.l); first_loop(ray, params->dir, params->o); if (!ray->ret) return (ray->color); *(params->distance) = ray->ret2; if (ray->ret->light == TRUE) return (set_vec(1, 1, 1)); ray->pi = add_vec(params->o, mul_vec(params->dir, ray->ret2)); ray->tmp = params->over.l; while (ray->tmp) { if (ray->tmp->light == TRUE) { set_nray(ray, params->over.l, params->dir, params->o); shade(ray, params->dir); } ray->tmp = ray->tmp->next; } reflexion(ray, params); refraction(ray, params); return (ray->color); }
int cast_a_ray_alias(t_rt *img, int x, int y) { t_ray ray; t_color color; t_obj *tmp; int colour[3]; colour[0] = 0; colour[1] = 0; colour[2] = 0; ray.color = &color; init_ray(img, &ray, x, y); while (img && ray.x < x + 1) { ray.y = (double)y; while (ray.y < y + 1) { tmp = img->objs; calc_color_alias(img, &ray, tmp); calc_final_alias(ray.color, &colour[2], &colour[0], &colour[1]); ray.y += 0.125; } ray.x += 0.125; } return (transform_pixel(colour[0], colour[1], colour[2])); }
colour get_the_scene(t_rt_client *rt, int x, int y) { t_ray ray; t_color color; t_obj *tmp; t_obj *obj_result; tmp = rt->objs; obj_result = NULL; ray.color = &color; init_ray(rt, &ray, x, y); while (rt && tmp && tmp->color) { assign_ray(rt, &ray, tmp); obj_result = cast_ray(&ray, tmp, obj_result); tmp = tmp->next; } if (obj_result && obj_result->color) { assign_ray(rt, &ray, obj_result); obj_result->color->color = perlin_color(rt, &ray, obj_result); lighting(&ray, obj_result, rt->spot); shadows(rt, &ray, obj_result); } return (ray.color->color); }
REAL HuniformShadowIntersect(RAY *r, REAL lightlength, ELEMENT *pe, INT pid) { INT status; INT hitcode,i; REAL trans; /* Transparency factor. */ OBJECT *peParent; /* Ptr to parent object. */ ELEMENT **pptr; /* Primitive element list ptr. */ ELEMENT *pe2; /* Ptr to element. */ IRECORD newhit[ISECT_MAX]; /* Hit record. */ VOXEL *v; trans = 1.0; /* Now try uniform hierarchy. */ r->ri = NULL; v = init_ray(r, gm->world_level_grid); if (v == NULL) { reset_rayinfo(r); return(trans); } newhit[0].t = HUGE_REAL; status = IN_WORLD; while (trans > 0.0 && status != EXITED_WORLD) { /* Intersect primitives in cell. */ pptr = (ELEMENT**)v->cell; for (i = 0; (i < v->numelements) && (trans > 0.0); i++) { pe2 = pptr[i]; peParent = pe2->parent; hitcode = (*peParent->procs->pe_intersect)(r, pe2, newhit); if (hitcode && newhit[0].pelem != pe && newhit[0].t < lightlength) trans *= newhit[0].pelem->parent->surf->ktran; } if (trans > 0.0) v = next_nonempty_leaf(r, STEP, &status); } reset_rayinfo(r); return (trans); }
void draw_real_map(t_map *map, t_img *img) { int x; t_raycaster r; x = 0; while (x < img->width) { init_ray(&r, map, img, x); ray_cast(&r, map); draw_column(&r, map, img, x); x++; } }
int64_t stripe(struct stripe_data *sd, int j) { uint32_t *fb = sd->fb; int w = sd->w; v4sf dU = sd->dU; v4sf dV = sd->dV; m34sf UV = sd->UV; struct sphere sphere = sd->sphere; struct aabb aabb = sd->aabb; struct camera camera = sd->camera; float a = sd->a; int use_aabb = sd->use_aabb; v4sf jdV = v4sf_set1(j) * dV; int64_t pixels = 0; for (int i = 0; i < (w & ~1); i += 2) { v4sf idU = v4sf_set1(i) * dU; m34sf scr = m34sf_addv(UV, jdV + idU); m34sf dir = m34sf_normal(m34sf_addv(scr, camera.dir)); struct ray ray = init_ray(m34sf_splat(camera.origin), dir); i4sf l; uint32_t color[4] = { 0, 0, 0, 0 }; v4su test; if (use_aabb) test = aabb_ray(&l, aabb, ray); else test = sphere_ray(&l, sphere, ray); test &= v4sf_gt(l.max, v4sf_set1(0)); if (!v4su_all_zeros(test)) { pixels += 4; l.min = v4sf_max(l.min, v4sf_set1(0)); l.min = v4sf_and(test, l.min); l.max = v4sf_and(test, l.max); m34sf tmp = value(l, ray, a); color[0] = test[0] & argb(m34sf_get0(tmp)); color[1] = test[1] & argb(m34sf_get1(tmp)); color[2] = test[2] & argb(m34sf_get2(tmp)); color[3] = test[3] & argb(m34sf_get3(tmp)); } fb[w * (j+0) + (i+0)] = 0xff000000 | color[0]; fb[w * (j+0) + (i+1)] = 0xff000000 | color[1]; fb[w * (j+1) + (i+0)] = 0xff000000 | color[2]; fb[w * (j+1) + (i+1)] = 0xff000000 | color[3]; } return pixels; }
int main(){ int an_r[10] = {1,2,3,4,5,10,9,8,7,6}; struct ray list_of_int; init_ray(10, &list_of_int); for (int k=0; k < list_of_int.length; k++) { list_of_int.array[k] = an_r[k]; } for (int k=0; k < list_of_int.length; k++) { printf("%c\n", list_of_int.array[k]); } //test ray_of_ints_to_matrix_picture(&list_of_int); selection_sort(list_of_int.array, list_of_int.length); ray_of_ints_to_matrix_picture(&list_of_int); return 0; }
void dynamic_objects() { struct ray ray = init_ray(v3f(2, 2, 5), v3f_normal(v3f(0.1 * mouse_x, 0.1 * mouse_y, -1))); struct v3f p0 = ray.o; struct v3f p1 = v3f_mul_add(40, ray.d, ray.o); struct v3f red = { 1, 0, 0 }; struct v3f cyan = { 0, 1, 1 }; struct grid grid; if (!init_traversal(&grid, ray, big_box, cells)) { line(cyan, p0, p1); return; } struct v3f pl0 = v3f_mul_add(grid.l[0], ray.d, ray.o); struct v3f pl1 = v3f_mul_add(grid.l[1], ray.d, ray.o); line(cyan, p0, pl0); line(red, pl0, pl1); line(cyan, pl1, p1); for (first_voxel(&grid); inside_grid(&grid); next_voxel(&grid)) draw_cell(red, grid.g); }