#include <api.h>
#include <paramset.h>

int main(int argc, char** argv)
{
    int width = 638;
    int height = 383;
    string filename("TwoSpheres.png");
    int pixelsamples = 3;
    float fov = 60;
    string tonemapper("NonLinearOp");

    pbrtInit();
    pbrtLookAt
    (
        0, 2, -15,
        0, -1, -10,
        0, 1, 0
    );

    ParamSet cameraParams;
    cameraParams.AddFloat("fov", &fov);
    pbrtCamera("perspective", cameraParams);

    ParamSet filmParams;
    filmParams.AddInt("xresolution", &width);
    filmParams.AddInt("yresolution", &height);
    filmParams.AddString("filename", &filename);
    filmParams.AddString("tonemapper", &tonemapper);
    pbrtFilm("pngfilm", filmParams);

    ParamSet samplerParams;
    samplerParams.AddInt("pixelsamples", &pixelsamples);
    pbrtSampler("bestcandidate", samplerParams);

    pbrtWorldBegin();

        pbrtAttributeBegin();
            pbrtCoordSysTransform("camera");
        pbrtAttributeEnd();

        ParamSet lightParams;
        Point from(0, 5, -15);
        lightParams.AddPoint("from", &from);
        float intensity[] = {100, 100, 100};
        Spectrum I(intensity);
        lightParams.AddSpectrum("I", &I);
        pbrtLightSource("point", lightParams);

        float blue[] = {0, 0, 1};
        float red[] = {1, 0, 0};
        float white[] = {25, 25, 25};

        ParamSet bluePlastic;
        Spectrum Kd(blue);
        bluePlastic.AddSpectrum("Kd", &Kd);

        ParamSet redPlastic;
        Kd = Spectrum(red);
        Spectrum Ks(white);
        redPlastic.AddSpectrum("Kd", &Kd);
        redPlastic.AddSpectrum("Ks", &Ks);
        float roughness = 0.01f;
        redPlastic.AddFloat("roughness", &roughness);

        pbrtObjectBegin("pair");
            pbrtMaterial("plastic", bluePlastic);
            pbrtAttributeBegin();
                pbrtTranslate(-1, -1, -10);
                float radius = 1.5;
                ParamSet sphereParams;
                sphereParams.AddFloat("radius", &radius);
                pbrtShape("sphere", sphereParams);
            pbrtAttributeEnd();

            pbrtMaterial("plastic", redPlastic);
            pbrtAttributeBegin();
                pbrtTranslate(1, -1, -10);
                pbrtShape("sphere", sphereParams);
            pbrtAttributeEnd();
        pbrtObjectEnd();

        pbrtObjectInstance("pair", "kdtree");

    pbrtWorldEnd();

    pbrtCleanup();
}
