예제 #1
0
파일: scene5.c 프로젝트: vchaillo/rtv1
void			load_scene5(t_env *e)
{
	if (e->scene)
		delete_scene(e->scene);
	e->scene_type = SCENE_5;
	e->scene = new_scene(new_color(BLACK), new_camera(0, 4, 20));
	load_scene5_objects(e->scene);
	load_scene5_lights(e->scene);
}
예제 #2
0
CameraID CameraManager::new_camera_for_viewport(const Viewport& vp) {
    float x, y, width, height;
    calculate_ratios_from_viewport(vp.type(), x, y, width, height);

    CameraID cid = new_camera();
    camera(cid)->set_perspective_projection(45.0, width / height);

    return cid;
}
예제 #3
0
void initialize_cameras(void){
  int i;
  for(i = 0; i < 9; i ++){
    cam[i] = new_camera((i < 3)?(-800.0):((i < 6)?(0.0):(800.0)),
			(i%3 == 0)?(-800.0):((i%3 == 2)?(0.0):(800.0)),
			800.0, 800.0);
    limit_camera(cam[i], window_width / 2 - 400, window_height / 2 - 400,
		 800, 800);
  }
}
예제 #4
0
파일: game.c 프로젝트: thiagoharry/spacewar
void intro(void){
  int i, sound = 0;
  time_t begin, now;
  float speed[6];
  circle *planet[6], *moon1;
  camera *cam = new_camera(0.0, 0.0, 800.0, 800.0);
  surface *dark_weaver = new_image("dark_weaver.png");
  surface *credits = new_image("credits.png");
  for(i = 0; i < 6; i ++){
    speed[i] = ((rand() % 20) + 10) / 1000.0;
    planet[i] = new_circle(450.0 + i*50, 450.0 + i*50, (rand() % 20) + 10.0);
  }
  moon1 = new_circle(planet[2] -> x + 40.0, planet[2] -> y + 40.0, 10.0);
  limit_camera(cam, window_width / 2 - 400, window_height / 2 - 400,
	       800, 800);
  begin = time(NULL);
  initialize_star();
  for(;;){
    now = time(NULL);
    if(now - begin > 3){
      draw_surface(dark_weaver, window, 
		   (window_width - dark_weaver -> width) / 2, 
		   (window_height - dark_weaver -> height) / 2);
      draw_surface(credits, window, (window_width - credits -> width) / 2, 0);
      if(sound == 0){
	sound = 1;
	play_sound("weaver.ogg");
      }
      if(now - begin > 5)
	break;
    }
    for(i = 0; i < 6; i ++)
      erase_fullcircle(cam, planet[i]);
    erase_fullcircle(cam, moon1);
    for(i = 0; i < 6; i ++)
      rotate_circle(planet[i], 400.0, 400.0, speed[i]);
    rotate_circle(moon1, planet[2] -> x, planet[2] -> y, speed[2]*10.0);
    film_fullcircle(cam, planet[0], 0x220000);
    film_fullcircle(cam, planet[1], 0x002200);
    film_fullcircle(cam, planet[2], 0x000022);
    film_fullcircle(cam, planet[3], 0x002222);
    film_fullcircle(cam, planet[4], 0x220022);
    film_fullcircle(cam, planet[5], 0x222222);
    film_fullcircle(cam, moon1, 0x444400);
    update_star();
    weaver_rest(10000000);
  }
  destroy_surface(dark_weaver);
  destroy_surface(credits);
  destroy_star();
}
예제 #5
0
Camera *
create_camera(void) {
    Point3d camera_location = point3d(-70, 200, 50);
    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);
    return camera;
}
예제 #6
0
파일: camera.c 프로젝트: johnh530/electro
void recv_create_camera(void)
{
    int i = new_camera();
    int t = recv_index();

    struct camera *c = get_camera(i);

    c->count = 1;
    c->type  = t;
    c->n     = recv_float();
    c->f     = recv_float();

    c->frame = 0;
    c->depth = 0;
    c->image = 0;

    recv_create_entity();
}
예제 #7
0
CameraID CameraManager::new_camera_with_orthographic_projection(double left, double right, double bottom, double top, double near, double far) {
    /*
     *  Instantiates a camera with an orthographic projection. If both left and right are zero then they default to 0 and window.width()
     *  respectively. If bottom and top are zero, then they default to window.height() and 0 respectively. So top left is 0,0
     */
    CameraID new_camera_id = new_camera();

    if(!left && !right) {
        right = window_->width();
    }

    if(!bottom && !top) {
        bottom = window_->height();
    }

    camera(new_camera_id)->set_orthographic_projection(left, right, bottom, top, near, far);

    return new_camera_id;
}
예제 #8
0
파일: camera.c 프로젝트: johnh530/electro
int send_create_camera(int t)
{
    int i;

    if ((i = new_camera()) >= 0)
    {
        struct camera *c = get_camera(i);

        c->count = 1;
        c->type  = t;
        c->n     = (t == CAMERA_ORTHO) ? -1000.0f :    0.1f;
        c->f     = (t == CAMERA_ORTHO) ?  1000.0f : 1000.0f;

        c->frame = 0;
        c->depth = 0;
        c->image = 0;

        c->view_basis[0][0] = 1.0f;
        c->view_basis[0][1] = 0.0f;
        c->view_basis[0][2] = 0.0f;
        c->view_basis[1][0] = 0.0f;
        c->view_basis[1][1] = 1.0f;
        c->view_basis[1][2] = 0.0f;
        c->view_basis[2][0] = 0.0f;
        c->view_basis[2][1] = 0.0f;
        c->view_basis[2][2] = 1.0f;

        send_event(EVENT_CREATE_CAMERA);
        send_index(t);
        send_float(c->n);
        send_float(c->f);

        return send_create_entity(TYPE_CAMERA, i);
    }
    return -1;
}
예제 #9
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;
}