示例#1
0
/**
 * Wooden Monkey Scene 1
 */
void wmonkey_scene_1()
{
    printf("WOODEN MONKEY SCENE : 1 ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material for shading.
    Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2, 0.8 );
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);

    // Defines a point light source.
    double l0c = 0.5;
    PointLight * light0 = new PointLight(
        Point3D(-2, 2, 5),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* plane = rt.addObject( new UnitSquare(), &jade );

    // Apply some transformations to the unit square.
    double factor1[3] = { 1.0, 2.0, 1.0 };
    double factor2[3] = { 6.0, 6.0, 6.0 };
    rt.translate(sphere, Vector3D(0, 0, -5));
    rt.rotate(sphere, 'x', -45);
    rt.rotate(sphere, 'z', 45);
    rt.scale(sphere, Point3D(0, 0, 0), factor1);

    rt.translate(plane, Vector3D(0, 0, -7));
    rt.rotate(plane, 'z', 45);
    rt.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    rt.translate(sphere2, Vector3D(3, 0, -5));
    rt.scale(sphere2, Point3D(0, 0, 0), f);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setShadingMode(Raytracer::SCENE_MODE_PHONG);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("WOODEN MONKEY SCENE : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "wmonkey_1.bmp");
    printf("WOODEN MONKEY SCENE : 1 :: Done!\n");
}
示例#2
0
/**
 * Wooden Monkey Scene 1
 */
void refraction_scene_1()
{
    printf("REFRACTION SCENE : 1 ----------------------------------\n\n");
    Raytracer rt;
    int width = 16 * 20 * 2;
    int height = 12 * 20 * 2;

    // Camera parameters.
    Point3D eye1(0, 0, 1), eye2(4, 2, 1);
    Vector3D view1(0, 0, -1), view2(-4, -2, -6);
    Vector3D up(0, 1, 0);
    double fov = 60;

    // Defines a material for shading.
    Material gold( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                   Colour(0.628281, 0.555802, 0.366065),
                   51.2, LARGE_SPH_REFLECT, LARGE_SPH_REFRAC_INDX, LARGE_SPH_REFRACT);
    Material jade( Colour(0, 0, 0), Colour(0.54, 0.89, 0.63),
                   Colour(0.316228, 0.316228, 0.316228),
                   12.8);
    // Defines a material for shading.
    Material gold_nonRefract( Colour(0.3, 0.3, 0.3), Colour(0.75164, 0.60648, 0.22648),
                              Colour(0.628281, 0.555802, 0.366065),
                              51.2, 0.8 );

    // Defines a point light source.
    double l0c = 0.5;
    PointLight * light0 = new PointLight(
        Point3D(-2, 2, 5),
        Colour(l0c, l0c, l0c),
        0.2);
    rt.addLightSource(light0);

    // Add a unit square into the scene with material mat.
    SceneDagNode* sphere = rt.addObject( new UnitSphere(), &gold );
    SceneDagNode* sphere2 = rt.addObject( new UnitSphere(), &gold_nonRefract );
    SceneDagNode* plane = rt.addObject( new UnitSquare(), &jade );
    SceneDagNode* sphere3 = rt.addObject( new UnitSphere(), &RED);
    SceneDagNode* sphere4 = rt.addObject( new UnitSphere(), &GREEN_TRANSP);
    SceneDagNode* plane2 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane3 = rt.addObject( new UnitSquare(), &jade );
//    SceneDagNode* plane4 = rt.addObject( new UnitSquare(), &jade );

    // Apply some transformations to the unit square.
    double factor1[3] = { 1.0, 2.0, 1.0 };
    double factor2[3] = { 6.0, 6.0, 6.0 };
    rt.translate(sphere, Vector3D(0, 0, -5));
    rt.rotate(sphere, 'x', -45);
    rt.rotate(sphere, 'z', 45);
    rt.scale(sphere, Point3D(0, 0, 0), factor1);

    rt.translate(plane, Vector3D(0, 0, -7));
    rt.rotate(plane, 'z', 45);
    rt.scale(plane, Point3D(0, 0, 0), factor2);

    double f[3] = { 0.5, 0.5, 0.5 };
    rt.translate(sphere2, Vector3D(3, 0, -5));
    rt.scale(sphere2, Point3D(0, 0, 0), f);

    rt.translate(sphere3, Vector3D(0, 2, -5));
    rt.scale(sphere3, Point3D(0, 0, 0), f);

    double f2[3] = { 0.6, 0.6, 0.6 };
    rt.translate(sphere4, Vector3D(-2, 1, -3));
    rt.scale(sphere4, Point3D(0, 0, 0), f2);

    double fp2[3] = { 3.0, 3.0, 3.0 };
    rt.translate(plane2,Vector3D(-4,1,-5));
    rt.rotate(plane2, 'z', 45);
    rt.rotate(plane2, 'y', 45);
    rt.scale(plane2, Point3D(0, 0, 0), fp2);

//    rt.translate(plane3,Vector3D(-2,0,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane3, 'x', 90);
//	rt.scale(plane3, Point3D(0, 0, 0), fp2);
//
//    rt.translate(plane4,Vector3D(-2,1,-5));
//    rt.rotate(plane2, 'z', 45);
//    rt.rotate(plane4, 'y', 90);
//	rt.scale(plane4, Point3D(0, 0, 0), fp2);

    rt.setAAMode(Raytracer::AA_SUPER_SAMPLING);
    rt.setShadingMode(Raytracer::SCENE_MODE_PHONG);
    rt.setShadows(Raytracer::SHADOW_CAST);
    rt.setEnvMapMode(Raytracer::ENV_MAP_CUBE_SKYBOX);
    rt.setColorSpaceMode(Raytracer::COLOR_ENC_SRGB_GAMMA_CORRECT);
    rt.setReflDepth(4);

    //set the texture map for the objects of interest in the scene if texture map flag is ON
    if (TEXTURE_MAP_FLAG) {
        // load texture image
        TextureMap txtmp;
        txtmp = TextureMap(TEXTURE_IMG);
        TextureMap txtmp2 = TextureMap(TEXTURE_IMG2);
        TextureMap txtmp3 = TextureMap(TEXTURE_IMG3);

        //for now, we are only using texture map for sphere
        sphere->useTextureMapping = true;
        sphere->obj->setTextureMap(txtmp);

        sphere2->useTextureMapping = false;

        sphere4->useTextureMapping = true;
        sphere4->setTextMapOfObject(txtmp2);

        plane2->useTextureMapping = true;
        plane2->setTextMapOfObject(txtmp3);

//        plane3->useTextureMapping = true;
//        plane3->setTextMapOfObject(txtmp3);
//
//        plane4->useTextureMapping = true;
//        plane4->setTextMapOfObject(txtmp3);
    }
    // refraction if it's turned on
    if (REFRACTION_FLAG) {
        rt.setRefractionMode(REFRACTION_FLAG);
    }

    if ( rt.getEnvMapMode() != Raytracer::NONE ) {
        // load images
        EnvMap env;
        if ( _DEBUG ) {
            env = EnvMap(
                      "EnvMaps/DebugMaps/posx.bmp",
                      "EnvMaps/DebugMaps/posy.bmp",
                      "EnvMaps/DebugMaps/posz.bmp",
                      "EnvMaps/DebugMaps/negx.bmp",
                      "EnvMaps/DebugMaps/negy.bmp",
                      "EnvMaps/DebugMaps/negz.bmp"
                  );
        } else {
            env = EnvMap(
                      "EnvMaps/SaintLazarusChurch/posx.bmp",
                      "EnvMaps/SaintLazarusChurch/posy.bmp",
                      "EnvMaps/SaintLazarusChurch/posz.bmp",
                      "EnvMaps/SaintLazarusChurch/negx.bmp",
                      "EnvMaps/SaintLazarusChurch/negy.bmp",
                      "EnvMaps/SaintLazarusChurch/negz.bmp"
                  );
        }

        rt.setEnvMap(env);
    }

    printf("REFRACTION SCENE : 1 :: Rendering...\n");
    rt.render(width, height, eye2, view2, up, fov, "refraction_2.bmp");
    Point3D eye3(0, 0, 1);
    Vector3D view3(0, 0, -1);
    printf("REFRACTION SCENE : 2 :: Rendering...\n");
    rt.render(width, height, eye3, view3, up, fov, "refraction_1.bmp");

    printf("REFRACTION SCENE : 1 :: Done!\n");
}