void load_scene5_objects(t_scene *scene) { add_object(scene, new_object(CONE, new_cone(new_vector(0, 1, -0.5), new_vector(8, 4, -5), 30), new_color(LIGHT_BLUE), 100)); add_object(scene, new_object(CYLINDER, new_cylinder(new_vector(0, 1, -0.3), new_vector(-10, 0, -5), 2), new_color(PASTEL_BLUE), 100)); add_object(scene, new_object(SPHERE, new_sphere(-1, 3, 2, 2), new_color(BLUE), 100)); add_object(scene, new_object(PLANE, new_plane(0, -1, 0, 0), new_color(DARK_GREY), 100)); }
int main() { init_geometry(); shape_t *planet = new_sphere(50, 20, 20); shape_t *sp1 = new_sphere(10, 16, 16); shape_t *sp2 = new_sphere(10, 16, 16); shape_t *t1 = new_taurus(30, 4, 50, 10); shape_t *t2 = new_taurus(30, 4, 40, 10); shape_translate(sp1, 80, 70, 40); shape_translate(sp2, -90, 10, -60); shape_scale(t1, 5, 1.2, 5); shape_scale(t2, 3.5, 1.2, 3.5); shape_rotate(t1, -20, 0, 0, 1); shape_rotate(t2, 20, 0, 0, 1); flushOBJ(stdout); free_shape(planet); free_shape(t1); free_shape(t2); finalize_geometry(); return 0; }
void generate_random_spheres(Scene * scene, int count) { srand(time(NULL)); int i; for(i = 0; i < count; i++) { int x = (rand() % 200) - (rand() % 200); int y = (rand() % 200) - (rand() % 200); int z = (rand() % 200) - (rand() % 200); int r = (rand() % 40); add_object(scene, new_sphere(point3d(x, y, z), r, rgb(255, 0, 0), material(1, 5, 0, 0, 0, 0))); } }
int handle_input(t_env* env, char* line) { char** input; int nb_args; input = id_strwordtab(line, " \t", &nb_args); if (input == NULL) return (-1); if (id_strcmp(input[0], "c") == 0) return (fill_camera(env, input, nb_args)); else if (id_strcmp(input[0], "S") == 0) return (new_sphere(env, input, nb_args)); else if (id_strcmp(input[0], "P") == 0) return (new_plane(env, input, nb_args)); else if (id_strcmp(input[0], "C") == 0) return (new_cylinder(env, input, nb_args)); else if (id_strcmp(input[0], "Li") == 0) return (new_light(env, input, nb_args)); id_wordtabfree(input); return (0); }
int main(void) { // Allocating scene Scene * scene = new_scene(MAX_OBJECTS_NUMBER, MAX_LIGHT_SOURCES_NUMBER, BACKGROUND_COLOR); // Allocating new sphere Float radius = 100; Point3d center = point3d(0, 0, 0); Color sphere_color = rgb(250, 30, 30); Material sphere_material = material(1, 5, 5, 10, 0, 10); Object3d * sphere = new_sphere(center, radius, sphere_color, sphere_material); // Adding sphere to the scene add_object(scene, sphere); // Allocating new triangle Object3d * triangle = new_triangle(point3d(-700, -700, -130), // vertex 1 point3d( 700, -700, -130), // vertex 2 point3d( 0, 400, -130), // vertex 3 rgb(100, 255, 30), // color material(1, 6, 0, 2, 0, 0) // surface params ); // Adding triangle to the scene add_object(scene, triangle); // Loading 3D model of cow from *.obj file // defining transformations and parameters of 3D model // TODO: must be refactored... SceneFaceHandlerParams load_params = new_scene_face_handler_params(scene, // scale: 40, // move dx, dy, dz: -150, -100, 30, // rotate around axises x, y, z: 0, 0, 0, // color rgb(200, 200, 50), // surface params material(2, 3, 0, 0, 0, 0) ); load_obj("./demo/models/cow.obj", // default handler which adding polygons of 3D model to scene: scene_face_handler, &load_params); // This function is requried (bulding k-d tree of entire scene) prepare_scene(scene); printf("\nNumber of polygons: %i\n", scene->last_object_index + 1); // Allocating new light source Color light_source_color = rgb(255, 255, 255); Point3d light_source_location = point3d(-300, 300, 300); LightSource3d * light_source = new_light_source(light_source_location, light_source_color); // Adding light source to the scene add_light_source(scene, light_source); // Adding fog Float density = 0.002; set_exponential_fog(scene, density); // Allocating camera // TODO: It's a pity, but quaternions are not implemented yet :( Point3d camera_location = point3d(0, 500, 0); Float focus = 320; Float x_angle = -1.57; Float y_angle = 0; Float z_angle = 3.14; Camera * camera = new_camera(camera_location, x_angle, y_angle, z_angle, focus); // Rotate camera if needed // rotate_camera(camera, d_x_angle, d_y_angle, d_z_angle); // Move camera if needed // move_camera(camera, vector3df(d_x, d_y, d_z)); // Alocate new canvas, to render scene on it Canvas * canvas = new_canvas(CANVAS_W, CANVAS_H); render_scene(scene, camera, canvas, THREADS_NUM); // Saving rendered image in PNG format write_png("example.png", canvas); release_canvas(canvas); release_scene(scene); release_camera(camera); return 0; }