void make_cylinder_rotation(t_vector* dir, t_transformation* t, t_vector* origin) { t_vector y_axis; t_vector o; t_vector ret; id_memset(&y_axis, 0, sizeof(y_axis)); id_memset(&o, 0, sizeof(o)); y_axis.y = 1; get_rotation_all_matrix(t, dir, &y_axis); get_translation_matrix(t, origin, &o); get_translation_vect(t, dir, &ret); }
int init(int argc, char** argv, t_env* env) { id_memset(env, 0, sizeof(*env)); if (argc != 4) return (id_error("id_rt width height fileToLoad")); env->width = id_atoi(argv[1]); env->height = id_atoi(argv[2]); if (env->height <= 0 || env->width <= 0) return (id_error("width and height should be over 0")); if (init_input(env, argv[3])) return (-1); env->screen = idx_init("Raytracing", env->width, env->height); if (env->screen == NULL) return (-1); env->pixels = malloc(sizeof(*env->pixels) * (env->width * env->height)); if (!env->pixels) return (-1); if (build_thread(env)) return (-1); env->global_work = 0; env->scale = (((env->width * env->height) / 10) * (ANTIALIASING / 2)) * 2; env->current_work = 0; return (0); }
void get_translation_matrix(t_transformation* t, t_vector* o, t_vector* w) { id_memset(&t->move, 0, sizeof(t->move)); t->move[0] = 1; t->move[5] = 1; t->move[10] = 1; t->move[15] = 1; t->move[3] = -(o->x - w->x); t->move[7] = -(o->y - w->y); t->move[11] = -(o->z - w->z); t->is_move = 1; }
void make_avg(t_thread_pixel* cut_pixel, t_thread_pixel* pixel) { int i; double avg[3]; i = 0; id_memset(avg, 0, sizeof(avg)); while (i < ANTIALIASING * ANTIALIASING) { avg[0] = avg[0] + cut_pixel[i].r; avg[1] = avg[1] + cut_pixel[i].g; avg[2] = avg[2] + cut_pixel[i].b; i = i + 1; } pixel->r = avg[0] / (ANTIALIASING * ANTIALIASING); pixel->g = avg[1] / (ANTIALIASING * ANTIALIASING); pixel->b = avg[2] / (ANTIALIASING * ANTIALIASING); }
bool Client::Init(const char* ip, const char* port) { addrinfo hints; if (this->__init == true) return 0; id_memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if (getaddrinfo(ip, port, &hints, &this->__res) != 0) return 1; this->__sockfd = socket(this->__res->ai_family, this->__res->ai_socktype, this->__res->ai_protocol); if (this->__sockfd == -1) return 1; if (connect(this->__sockfd, this->__res->ai_addr, this->__res->ai_addrlen) == -1) return 1; this->__init = true; return 0; }
bool server::Init(char* port) { struct addrinfo hints; if (this->__init == true) return 0; id_memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if (getaddrinfo(0, port, &hints, &this->__res) != 0) return 1; this->__sockfd = socket(this->__res->ai_family, this->__res->ai_socktype, this->__res->ai_protocol); if (this->__sockfd == -1) return 1; if (bind(this->__sockfd, this->__res->ai_addr, this->__res->ai_addrlen) == -1) return 1; if (listen(this->__sockfd, 10) == -1) return 1; this->__init = true; return 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; }