librtl

Soft

This example demonstrates rtl_soft objects using the csoft library. The csoft library must be linked with the application using the rtl_soft classes. The soft object in this example is rendered using the simple material that uses the atributes of the primitives in the csoft model.

#include <iostream.h>
#include <stdio.h>

#include <rtl/rtl.h>
#include <rtl/soft.h>
#include <csoft/csoft_build.h>

csoft_object* buildSoft();

void main()
{
    rtl_initialize();
    csoft_mapgroup::reset_mappings();
    
    rtl_world scene(20);
    jImage map(320,240);
    rtl_material floor;
    rtl_plane plane;
    rtl_soft soft = rtl_soft(buildSoft(),true);
    rtl_softmat smat(&soft);

    rtl_sphericallight l0(0.7);
    l0.position(jVec3(-2,10,15)), l0.colour(jColour(0.7,0.7,0.7));
    
    rtl_sphericallight l1(0.7);
    l1.position(jVec3(10,10,15)), l1.colour(jColour(0.7,0.7,0.7));

    scene.illumination()->add(&l0), scene.illumination()->add(&l1);

    scene.illumination()->flags().seton(rtl_illumination::Shadows|
                                        rtl_illumination::Recursion);
    
    scene.lookat(jVec3(2,3,6),jVec3(0,0.35,0),jNorm3(0,1,0));

    smat.kR(0.0);
    floor.kS(0.7);
    floor.kR(0.3);
    floor.n(50);

    scene.push();
    {
        scene.translate(-0.5,-0.5,-2);
        scene.material(&smat);
        scene.add(&soft);
    }
    scene.pop();

    scene.translate(0,-1,0);

    jImage floor_texture;
    ifstream ifs("woodtile8.ppm");
    jImage::readPPM(ifs,floor_texture);
    rtl_texturemap* tmap = new rtl_texturemap(floor_texture);
    tmap->transform(jMat4(jMat4::mScale,0.5,1,0.5));
    scene.texture(tmap);
    scene.material(&floor);
    scene.add(&plane);
    
    cerr.setf(ios::fixed);
    cerr.precision(3);

    rtl_voxel::MaxObjects = 3;
    rtl_voxel::MaxDepth = 1;
    scene.raytrace(map);
    
    jImage::writePPM(cout,map);

    rtl_terminate();
}

csoft_object* buildSoft()
{
    ifstream ifs("water2.ppm");
    jImage image;
    jImage::readPPM(ifs,image);
    
    csoft_build csoft;

    csoft.begin();
    {
        csoft.push();
        {
            csoft.translate(-0.6,0,0);
            csoft.texturemap(new csoft_texturemap(image));
            csoft.begin();
            {
                csoft.sphere();
            }
            csoft.end(new csoft_texgroup,
                      csoft_mapgroup::cylindrical,
                      csoft_magic,1,1,-1,0);
            csoft.translate(1.2,0,0);
            csoft.begin();
            {
                csoft.sphere();
            }
            csoft.end(new csoft_texgroup,
                      csoft_mapgroup::cylindrical,
                      csoft_magic,2,2,-1,0);
            csoft.colour(0, 0.4, 0.8);
            csoft.translate(-0.6,1.0,0);
            csoft.sphere();
        }
        csoft.pop();
    }
    csoft.end(new csoft_group);
 
    return csoft.object();
}


JSP / librtl v0.2 mtigges@cpsc.ucalgary.ca