/* calculates the torque and twist between two DNA segments, given their tangent vectors. Returns * the vector with the torque, and also assigns the Tw value with the current value of the twist. * INHOMOGENEOUS LINEAR MODEL. (Derived from a bending energy which is ~gb theta^2. */ void body_twist_and_torque_harmonic_inhom (t_real *torque, const t_real *R1, const t_real *R2, t_real *Tw, void *p) { t_vector bn, t1_plus_t2; t_real one_plus_t1_dot_t2, theta; inhom_par *par = (inhom_par *) p; /* calculate 1 + t1.t2 */ one_plus_t1_dot_t2 = 1. + T1_T2 (R1, R2); /* calculate the binormal to t2 and t1 */ T1_x_T2 (bn, R1, R2); vector_unit (bn); /* angle between the tangent vectors */ theta = theta_angle (R1, R2); /* calculate twist */ twist_12 (R1, R2, one_plus_t1_dot_t2, Tw); t1_plus_t2_vec (t1_plus_t2, R1, R2); /* get the segment identity */ unsigned int count = par->count; unsigned int njoints = par->njoints; t_real gb = par->gb [count]; t_real gt = par->gt [count]; /* calculate torque */ vector_lincomb (torque, bn, t1_plus_t2, gb * theta, gt * (*Tw) / one_plus_t1_dot_t2); /* increment counter */ par->count++; if (par->count==njoints) par->count = 0; }
t_vector3 normal_sphere(t_ray ray, t_vector3 inter, t_sphere *obj) { t_vector3 v_normal; (void)ray; v_normal = vector_substract(obj->pos, inter); return (vector_unit(v_normal)); }
/* calculates the torque and twist between two DNA segments, given their tangent vectors. Returns * the vector with the torque, and also assigns the Tw value with the current value of the twist */ void body_twist_and_torque_nicked_harmonic4 (t_real *torque, const t_real *R1, const t_real *R2, t_real *Tw, void *p) { t_real theta; t_real *par = (t_real *) p; /* calculate the binormal to t2 and t1 */ T1_x_T2 (torque, R1, R2); vector_unit (torque); /* angle between the tangent vectors */ theta = theta_angle (R1, R2); /* this is the torque: no component along the twist */ dScaleVector3 (torque, par [0] * theta + par [1] * theta*theta*theta); /* assign zero twist */ *Tw = 0.; }
/* calculates the torque and twist between two DNA segments, given their tangent vectors. Returns * the vector with the torque, and also assigns the Tw value with the current value of the twist */ void body_twist_and_torque_nicked_harmonic (t_real *torque, const t_real *R1, const t_real *R2, t_real *Tw, void *p) { t_vector bn; t_real theta; t_real *gb = (t_real *) p; /* calculate the binormal to t2 and t1 */ T1_x_T2 (bn, R1, R2); vector_unit (bn); /* angle between the tangent vectors */ theta = theta_angle (R1, R2); /* this is the torque: no component along the twist */ vector_scale (torque, bn, (*gb) * theta); /* assign zero twist */ *Tw = 0.; }
static t_color3 getfinalcolor(t_object *arr, t_intersect inter, t_env env) { t_color3 color; t_color3 color_tmp; float dist[2]; t_ray newray; float shade; t_vector3 l; int i; int k; int a; color_tmp = color_new(0, 0, 0); a = 0; if (inter.obj) { i = -1; while(arr[i].type != DEFAULT) { shade = 1.0; if (arr[i].light == TRUE) { l = vector_substract(arr[i].pos, inter.pos); dist[0] = vector_magnitude(l); newray.pos = vector_substract(inter.pos, vector_mul(inter.v_normal, 1e-4f)); newray.dir = vector_unit(l); k = -1; while (++k < 16 && arr[k].type != DEFAULT) if (env.fctinter[arr[k].type](newray, arr + k, &dist[1])) { if (arr[k].light != TRUE && dist[1] <= dist[0]) shade -= 0.3; } color_tmp = vector_sum(color_tmp, iter_light(inter, &arr[i], shade)); ++a; } ++i; } return (vector_div(color_tmp, a)); } return (color_new(17, 25, 37)); }
/* calculates the torque and twist between two DNA segments, given their tangent vectors. Returns * the vector with the torque, and also assigns the Tw value with the current value of the twist. * LINEAR MODEL. (Derived from a bending energy which is ~gb theta^2. */ void body_twist_and_torque_harmonic (t_real *torque, const t_real *R1, const t_real *R2, t_real *Tw, void *p) { t_vector bn, t1_plus_t2; t_real one_plus_t1_dot_t2, theta; t_real *par = (t_real *) p; /* calculate 1 + t1.t2 */ one_plus_t1_dot_t2 = 1. + T1_T2 (R1, R2); /* calculate the binormal to t2 and t1 */ T1_x_T2 (bn, R1, R2); vector_unit (bn); /* angle between the tangent vectors */ theta = theta_angle (R1, R2); /* calculate twist */ twist_12 (R1, R2, one_plus_t1_dot_t2, Tw); t1_plus_t2_vec (t1_plus_t2, R1, R2); vector_lincomb (torque, bn, t1_plus_t2, par [0] * theta, par [1] * (*Tw) / one_plus_t1_dot_t2); }
void ft_render2(t_env env) { t_color3 rgba; t_ray ray; float y; float x; t_object arr[16]; t_object light[16]; float invW = 1 / (float)env.resolution.width; float invH = 1 / (float)env.resolution.height; float ratio = env.resolution.width / (float)env.resolution.height; float angle = tanf(M_PI * 0.5f * env.fov / 180.); ft_bzero(arr, sizeof(t_object) * 16); ft_bzero(light, sizeof(t_object) * 16); create_scene(parser(env.file), arr, light); y = 0; while (y < env.resolution.height) { x = 0; while (x < env.resolution.width) { ray.pos = env.pos_absolute_camera; ray.dir.x = (2. *(x * invW) - 1.) * angle * ratio; ray.dir.y = (1. - 2. * (y * invH)) * angle; ray.dir.z = 1; ray.dir = vector_unit(ray.dir); rgba = ft_trace_ray(arr, light, ray, 0, NULL, env); ft_put_pixel_to_image(env.img, x, y, rgba); x++; } y++; } dprintf(2, "The end\n"); mlx_put_image_to_window(env.mlx, env.win, env.img.ptr, 0, 0); }
static void fill_arr(t_value val, int idx, t_object *data) { if (ft_strequ(json_get(val.data.obj, "type").data.s, "SPHERE")) { ft_memcpy(data + idx, &(t_sphere){ SPHERE, color_new(json_get(val.data.obj, "color.red").data.number, json_get(val.data.obj, "color.green").data.number, json_get(val.data.obj, "color.blue").data.number), json_get(val.data.obj, "reflection_index").data.number, json_get(val.data.obj, "diffuse").data.number, vector_new(json_get(val.data.obj, "pos.x").data.number, json_get(val.data.obj, "pos.y").data.number, json_get(val.data.obj, "pos.z").data.number), json_get(val.data.obj, "radius").data.number }, sizeof(t_sphere)); } if (ft_strequ(json_get(val.data.obj, "type").data.s, "PLANE")) { ft_memcpy(data + idx, &(t_plan){ PLANE, color_new(json_get(val.data.obj, "color.red").data.number, json_get(val.data.obj, "color.green").data.number, json_get(val.data.obj, "color.blue").data.number), json_get(val.data.obj, "reflection_index").data.number, json_get(val.data.obj, "diffuse").data.number, vector_new(json_get(val.data.obj, "pos.x").data.number, json_get(val.data.obj, "pos.y").data.number, json_get(val.data.obj, "pos.z").data.number), vector_unit(vector_new(json_get(val.data.obj, "normal.x").data.number, json_get(val.data.obj, "normal.y").data.number, json_get(val.data.obj, "normal.z").data.number)) }, sizeof(t_plan)); } if (ft_strequ(json_get(val.data.obj, "type").data.s, "CYLINDER")) { ft_memcpy(data + idx, &(t_cylinder){ CYLINDER, color_new(json_get(val.data.obj, "color.red").data.number, json_get(val.data.obj, "color.green").data.number, json_get(val.data.obj, "color.blue").data.number), json_get(val.data.obj, "reflection_index").data.number, json_get(val.data.obj, "diffuse").data.number, vector_new(json_get(val.data.obj, "pos.x").data.number, json_get(val.data.obj, "pos.y").data.number, json_get(val.data.obj, "pos.z").data.number), vector_unit(vector_new(json_get(val.data.obj, "normal.x").data.number, json_get(val.data.obj, "normal.y").data.number, json_get(val.data.obj, "normal.z").data.number)), json_get(val.data.obj, "radius").data.number }, sizeof(t_cylinder)); } if (ft_strequ(json_get(val.data.obj, "type").data.s, "CONE")) { ft_memcpy(data + idx, &(t_cone){ CONE, color_new(json_get(val.data.obj, "color.red").data.number, json_get(val.data.obj, "color.green").data.number, json_get(val.data.obj, "color.blue").data.number), json_get(val.data.obj, "reflection_index").data.number, json_get(val.data.obj, "diffuse").data.number, vector_new(json_get(val.data.obj, "pos.x").data.number, json_get(val.data.obj, "pos.y").data.number, json_get(val.data.obj, "pos.z").data.number), vector_unit(vector_new(json_get(val.data.obj, "normal.x").data.number, json_get(val.data.obj, "normal.y").data.number, json_get(val.data.obj, "normal.z").data.number)), json_get(val.data.obj, "radius").data.number, 0 }, sizeof(t_cone)); } if (ft_strequ(json_get(val.data.obj, "type").data.s, "SPOTLIGHT")) { ft_memcpy(data + idx, &(t_spotlight){ SPOTLIGHT, color_new(json_get(val.data.obj, "color.red").data.number, json_get(val.data.obj, "color.green").data.number, json_get(val.data.obj, "color.blue").data.number), json_get(val.data.obj, "reflection_index").data.number, json_get(val.data.obj, "diffuse").data.number, vector_new(json_get(val.data.obj, "pos.x").data.number, json_get(val.data.obj, "pos.y").data.number, json_get(val.data.obj, "pos.z").data.number), vector_new(json_get(val.data.obj, "dir.x").data.number, json_get(val.data.obj, "dir.y").data.number, json_get(val.data.obj, "dir.z").data.number), json_get(val.data.obj, "intensity").data.number }, sizeof(t_spotlight)); } }