Ejemplo n.º 1
0
void setup_scene_0() {
	theCamera = init_camera(vector_init(2, 1, 3), vector_init(0, 0.3, 0), vector_init(0, 1, 0), 60, (float) WIDTH / (float) HEIGHT);

	lights[0].position = vector_init(-200, 170, 300);
	lights[0].col = vector_init(2, 2, 2);
	num_lights = 1;

	object_count = 0;
	material mat;

	mat.kd = vector_init(.5, .5, .5);
	mat.ks = vector_init(.5, .5, .5);
	mat.shininess = 200;
	mat.reflect_coef = 0.8;
	scene[object_count++] = init_sphere(0, 0, 0, .3, mat);

	mat.kd = vector_init(.9, 0, 0);
	mat.ks = vector_init(.1, .1, .1);
	mat.shininess = 500;
	mat.reflect_coef = 0.5;
	scene[object_count++] = init_sphere(1, -.05, 0, .15, mat);

	mat.kd = vector_init(0, 1, 0);
	mat.ks = vector_init(.0, .0, .0);
	mat.shininess = 0.01;
	scene[object_count++] = init_sphere(0, 1, 0, .25, mat);

	mat.kd = vector_init(0, 0, 0.6);
	mat.ks = vector_init(.4, .4, .4);
	mat.shininess = 20;
	mat.reflect_coef = 0.04;
	scene[object_count++] = init_sphere(0, -.05, 1, .20, mat);
}
Ejemplo n.º 2
0
void setup_scene_4() {
	theCamera = init_camera(vector_init(2, 1, 3), vector_init(0, 0.3, 0), vector_init(0, 1, 0), 60, (float) WIDTH / (float) HEIGHT);
	lights[0].position = vector_init(0, 1.7, 1);
	lights[0].col = vector_init(1, 1, 1);
	lights[1].position = vector_init(3, 2, 3);
	lights[1].col = vector_init(0.4, 0.4, 0.4);
	lights[2].position = vector_init(4, 3, -1);
	lights[2].col = vector_init(0.5, 0.5, 0.5);

	num_lights = 3;

	object_count = 0;
	material mat;

	mat.kd = vector_init(.5, .5, .5);
	mat.ks = vector_init(.5, .5, .5);
	mat.shininess = 200;
	mat.reflect_coef = 0.4;
	scene[object_count++] = init_sphere(0, 0, 0, .3, mat);

	mat.kd = vector_init(.9, 0, 0);
	mat.ks = vector_init(.1, .1, .1);
	mat.shininess = 500;
	scene[object_count++] = init_sphere(1, -.05, 0, .15, mat);

	mat.kd = vector_init(0, 1, 0);
	mat.ks = vector_init(.0, .0, .0);
	mat.shininess = 0.01;
	mat.reflect_coef = 0.04;
	scene[object_count++] = init_sphere(0, 1, 0, .25, mat);

	mat.kd = vector_init(0, 0, 0.6);
	mat.ks = vector_init(.4, .4, .4);
	mat.shininess = 20;
	scene[object_count++] = init_sphere(0, -.05, 1, .20, mat);

	mat.kd = vector_init(.5, 0.9, .7);
	mat.ks = vector_init(.01, .01, .01);
	mat.shininess = 100;
	mat.reflect_coef = 0.04;
	scene[object_count++] = init_plane(0, 1, 0, 0.2, mat);

	mat.kd = vector_init(.8, 0.09, .07);
	mat.ks = vector_init(.2, .2, .1);
	mat.shininess = 10;
	mat.reflect_coef = 0.5;
	scene[object_count++] = init_plane(1, 0.0, -1.0, 2, mat);

	mat.kd = vector_init(0.1, 0.3, .05);
	mat.ks = vector_init(.5, .5, .5);
	mat.shininess = 20;
	scene[object_count++] = init_plane(0.3, -0.2, 1, 3, mat);
}
Ejemplo n.º 3
0
void setup_scene_2() {
	theCamera = init_camera(vector_init(2, 1, 3), vector_init(0, 0.3, 0), vector_init(0, 1, 0), 60, (float) WIDTH / (float) HEIGHT);

	lights[0].position = vector_init(-2, 1.7, 3);
	lights[0].col = vector_init(1, 1, 1);
	lights[1].position = vector_init(3, 2, 3);
	lights[1].col = vector_init(0.4, 0.4, 0.4);
	lights[2].position = vector_init(4, 3, -10);
	lights[2].col = vector_init(0.5, 0.5, 0.5);

	num_lights = 3;

	object_count = 0;
	material mat;
	mat.shininess = 20;
	mat.kd = vector_init(1, 1, 1);
	mat.ks = vector_init(.5, .5, .5);
	mat.reflect_coef = 0.8;
	scene[object_count++] = init_sphere(0, 0, 0, .3, mat);

	mat.reflect_coef = 0.5;
	mat.shininess = 20;
	mat.kd = vector_init(0, 0, 1);
	scene[object_count++] = init_sphere(0, -.05, 1, .20, mat);

	mat.reflect_coef = 0.04;
	mat.ks = vector_init(.1, .1, .1);
	mat.kd = vector_init(0, 1, 0);
	scene[object_count++] = init_sphere(0, 1, 0, .15, mat);

	mat.kd = vector_init(1, 0, 0);
	mat.shininess = 500;
	scene[object_count++] = init_sphere(1, -.05, 0, .15, mat);

	mat.kd = vector_init(.5, 1, .7);
	scene[object_count++] = init_plane(0, 1, 0, 0.2, mat);

	mat.reflect_coef = 0.0;
	mat.ks = vector_init(.1, .1, .1);
	mat.kd = vector_init(1, 1, 0);
	scene[object_count++] = init_cylinder(vector_init(.0, .0, .0), vector_init(1, 0, 0), 1, .05, mat);
	scene[object_count++] = init_cylinder(vector_init(.0, .0, .0), vector_init(0, 1, 0), 1, .05, mat);
	scene[object_count++] = init_cylinder(vector_init(.0, .0, .0), vector_init(0, 0, 1), 1, .05, mat);

}
Ejemplo n.º 4
0
void Sphere::render() const
{
    // create geometry if we haven't already
    init_sphere();

    if ( material )
        material->set_gl_state();

    // just scale by radius and draw unit sphere
    glPushMatrix();
    glScaled( radius, radius, radius );
    glInterleavedArrays( GL_T2F_N3F_V3F, VERTEX_SIZE * sizeof Vertices[0], Vertices );
    glDrawElements( GL_TRIANGLES, SPHERE_NUM_INDICES, GL_UNSIGNED_INT, Indices );
    glPopMatrix();

    if ( material )
        material->reset_gl_state();
}
Ejemplo n.º 5
0
int main()
{
    unsigned long i;
    struct _sphere_context ctx;
    init_sphere(&ctx);
    
    srand(time(NULL));
    for (i = 0; i < 10000; ++i)
    {
        if (insert_vertex(&ctx, rand() % 10000, 1, 1, 1) < 0)
            break;
    }
    
    for (i = 0; i < ctx.v_count; ++i)
    {
        printf("%f %f %f\n", ctx.vertices[i].x, 
                             ctx.vertices[i].y, 
                             ctx.vertices[i].z);
    }
    printf ("Total vertices: %d\n", ctx.v_count);
    return 0;
}
Ejemplo n.º 6
0
void setup_scene_3() {
	theCamera = init_camera(vector_init(2, 1, 3), vector_init(0, 0.3, 0), vector_init(0, 1, 0), 60, (float) WIDTH / (float) HEIGHT);

	lights[0].position = vector_init(-2, 1.7, 3);
	lights[0].col = vector_init(1, 1, 1);
	lights[1].position = vector_init(3, 2, 3);
	lights[1].col = vector_init(0.4, 0.4, 0.4);
	lights[2].position = vector_init(4, 3, -10);
	lights[2].col = vector_init(0.5, 0.5, 0.5);

	num_lights = 3;

	object_count = 0;
	material mat;
	mat.shininess = 20;
	mat.kd = vector_init(1, 0, 0);
	mat.ks = vector_init(.5, .5, .5);
	mat.reflect_coef = 0.8;
	for (int i = 0; i < SCENE_SIZE; i++) {
		mat.kd = vector_init(((float) (rand() % 255)) / 255.f, ((float) (rand() % 255)) / 255.f, ((float) (rand() % 255)) / 255.f);
		scene[object_count++] = init_sphere(((float) (rand() % 8)) / 4.f, ((float) (rand() % 8)) / 4.f, ((float) (rand() % 8)) / 4.f, .1, mat);
	}
}
Ejemplo n.º 7
0
int main(int argc, char *argv[])
{
    SDL_Event event;
    int continuer = 1;

    SDL_Init(SDL_INIT_VIDEO);
    FSOUND_Init(44100, 32, FSOUND_NORMAL);
    atexit(SDL_Quit);
    SDL_WM_SetCaption("Sphere Quantique", NULL);
    SDL_SetVideoMode(1280/*glutGet(GLUT_SCREEN_WIDTH)*/,720/*glutGet(GLUT_SCREEN_HEIGHT)*/, 32, SDL_OPENGL | SDL_NOFRAME/*| SDL_FULLSCREEN*/);

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective(70,(double)glutGet(GLUT_SCREEN_WIDTH)/glutGet(GLUT_SCREEN_HEIGHT),1,1000);
    glEnable(GL_DEPTH_TEST);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glFlush();
    SDL_GL_SwapBuffers();

    srand(time(NULL));
    for(int i=0;i<MAX_BALL;i++){

        int r_x = rand()%(50-1)+10;

        int r_y = rand()%(50-1)+10;

        int r_z = rand()%(50-1)+10;


        int ax_1 = rand()%2;

        int ax_2 = rand()%2;


        int angl = rand()%360;

        int R = rand()%256;
        int G = rand()%256;
        int B = rand()%256;

        sphere[i] = init_sphere(sphere[i],0,0,0,r_x,r_y,r_z,ax_1,ax_2,angl,R,G,B);

    }




//SDL_Delay(10000);

    while(continuer)
    {
        SDL_PollEvent(&event);
        switch(event.type)
        {   case SDL_QUIT:
                continuer = 0;
                break;
            case SDL_KEYDOWN:
                 switch(event.key.keysym.sym)
                 {   case SDLK_ESCAPE:
                          continuer = 0;
                          break;
                    case SDLK_w:
                        cam_x += 1;
                        cam_px += 1;
                        break;
                    case SDLK_a:

                        break;
                    case SDLK_d:

                        break;
                    case SDLK_s:
                        cam_x -= 1;
                        cam_px -= 1;
                        break;
                     default:break;
                 }
                 break;
        }
        Dessiner();

        SDL_Delay(10);

    }

    FSOUND_Close();

    return 0;
}
Ejemplo n.º 8
0
void Application::load(SceneInfo* sceneInfo) {

  vector<Collada::Node>& nodes = sceneInfo->nodes;
  vector<DynamicScene::SceneLight *> lights;
  vector<DynamicScene::SceneObject *> objects;

  // save camera position to update camera control later
  CameraInfo *c;
  Vector3D c_pos = Vector3D();
  Vector3D c_dir = Vector3D();

  int len = nodes.size();
  for (int i = 0; i < len; i++) {
    Collada::Node& node = nodes[i];
    Collada::Instance *instance = node.instance;
    const Matrix4x4& transform = node.transform;

    switch(instance->type) {
      case Collada::Instance::CAMERA:
        c = static_cast<CameraInfo*>(instance);
        c_pos = (transform * Vector4D(c_pos,1)).to3D();
        c_dir = (transform * Vector4D(c->view_dir,1)).to3D().unit();
        init_camera(*c, transform);
        break;
      case Collada::Instance::LIGHT:
      {
        lights.push_back(
          init_light(static_cast<LightInfo&>(*instance), transform));
        break;
      }
      case Collada::Instance::SPHERE:
        objects.push_back(
          init_sphere(static_cast<SphereInfo&>(*instance), transform));
        break;
      case Collada::Instance::POLYMESH:
        objects.push_back(
          init_polymesh(static_cast<PolymeshInfo&>(*instance), transform));
        break;
      case Collada::Instance::MATERIAL:
        init_material(static_cast<MaterialInfo&>(*instance));
        break;
     }
  }

  scene = new DynamicScene::Scene(objects, lights);

  const BBox& bbox = scene->get_bbox();
  if (!bbox.empty()) {

    Vector3D target = bbox.centroid();
    canonical_view_distance = bbox.extent.norm() / 2 * 1.5;

    double view_distance = canonical_view_distance * 2;
    double min_view_distance = canonical_view_distance / 10.0;
    double max_view_distance = canonical_view_distance * 20.0;

    canonicalCamera.place(target,
                          acos(c_dir.y),
                          atan2(c_dir.x, c_dir.z),
                          view_distance,
                          min_view_distance,
                          max_view_distance);

    camera.place(target,
                acos(c_dir.y),
                atan2(c_dir.x, c_dir.z),
                view_distance,
                min_view_distance,
                max_view_distance);

    set_scroll_rate();
  }

  // set default draw styles for meshEdit -
  scene->set_draw_styles(&defaultStyle, &hoverStyle, &selectStyle);

}
Ejemplo n.º 9
0
int main(void) {
    GlutCLWindow window(512, 512);

    Sphere sphere;
    init_sphere(&sphere);
    sphere.center.y = -4.0f;
    sphere.center.x = -2.0f;
    sphere.center.z = -2.0f;
    sphere.mat.kd = 1.0f;
    sphere.mat.diffuse.x = 0.0f;
    sphere.mat.diffuse.y = 0.7f;
    sphere.mat.diffuse.z = 0.7f;
    window.rayTracer.addSphere(sphere);

    init_sphere(&sphere);
    sphere.center.y = -3.0f;
    sphere.center.x = 2.0f;
    sphere.center.z = 2.0f;
    sphere.mat.ks = 0.2f;
    sphere.mat.kt = 0.8f;
    sphere.mat.extinction.x = 0.99f;
    sphere.mat.extinction.y = 0.95f;
    sphere.mat.extinction.z = 0.95f;
    sphere.mat.ior = 1.1f;
    window.rayTracer.addSphere(sphere);

    init_sphere(&sphere);
    sphere.center.y = -4.0f;
    sphere.center.x = 0.0f;
    sphere.center.z = 0.0f;
    sphere.mat.ks = 1.0f;
    window.rayTracer.addSphere(sphere);

    init_sphere(&sphere);
    sphere.center.y = -4.0f;
    sphere.center.x = 2.0f;
    sphere.center.z = -2.0f;
    sphere.mat.kd = 0.2f;
    sphere.mat.ks = 0.8f;
    sphere.mat.diffuse.x = 0.7f;
    sphere.mat.diffuse.y = 0.7f;
    sphere.mat.diffuse.z = 0.0f;
    sphere.mat.specExp = 100.0f;
    window.rayTracer.addSphere(sphere);

    init_sphere(&sphere);
    sphere.center.y = -4.0f;
    sphere.center.x = -2.0f;
    sphere.center.z = 2.0f;
    sphere.mat.kd = 0.6f;
    sphere.mat.ks = 0.4f;
    sphere.mat.diffuse.x = 0.7f;
    sphere.mat.diffuse.y = 0.0f;
    sphere.mat.diffuse.z = 0.8f;
    sphere.mat.specExp = 1000.0f;
    window.rayTracer.addSphere(sphere);

    init_sphere(&sphere);
    sphere.center.x = 2.2f;
    sphere.center.y = 1.0f;
    sphere.center.z = 2.0f;
    sphere.radius = 0.5f;
    sphere.mat.emission_power = 1.0;
    sphere.mat.emission.x = 1.8f;
    sphere.mat.emission.y = 1.8f;
    sphere.mat.emission.z = 1.8f;
    window.rayTracer.addSphere(sphere);

//    init_sphere(&sphere);
//    sphere.center.x = 1.0f;
//    sphere.center.y = 3.0f;
//    sphere.center.z = -2.0f;
//    sphere.radius = 0.5f;
//    sphere.mat.emission_power = 1.0;
//    sphere.mat.emission.x = 0.4f;
//    sphere.mat.emission.y = 0.1f;
//    sphere.mat.emission.z = 0.6f;
//    window.rayTracer.addSphere(sphere);

    window.rayTracer.setSampleRate(1);
    window.rayTracer.setMaxPathDepth(6);
    window.rayTracer.setCameraSpherical(gmtl::Point3f(0, -4, -0), 14.0f,
            118.0f, 5);
    window.setProgressive(20000);

    glutMainLoop();

}