Beispiel #1
0
int main(
    int /*argc*/,
    char** /*argv*/)
{
    osg::ref_ptr<osg::Node> model = osgDB::readNodeFile("cessna.osg");
    osg::ref_ptr<osg::Group> root = new osg::Group;
    root->addChild(model);

    osg::Node* light0 = createLightSource(
        0,
        osg::Vec3(-20.0f, 0.0f, 0.0f),
        osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f));
    osg::Node* light1 = createLightSource(
        1,
        osg::Vec3(0.0f, -20.0f, 0.0f),
        osg::Vec4(0.0f, 1.0f, 1.0f, 1.0f));

    root->getOrCreateStateSet()->setMode(
        GL_LIGHT0,
        osg::StateAttribute::ON);
    root->getOrCreateStateSet()->setMode(
        GL_LIGHT1,
        osg::StateAttribute::ON);
    root->addChild(light0);
    root->addChild(light1);

    osgViewer::Viewer viewer;
    viewer.setSceneData(root.get());
    return viewer.run();
}
Beispiel #2
0
int main(int argc, char *argv[]) {
    
    FILE *input;
    char *fileName = argv[1];
    Sphere **sphereList = (Sphere **) malloc(sizeof(Sphere *));
    int sphereListLength = 0;
    View view;
    Point eyePoint;
    Light lightSource;
    Color ambientLight;
    FILE *output;
    
    tryOpen(&input, fileName);
    readSphereList(&input, sphereList, &sphereListLength);
    
    createView(&view);
    createEyePoint(&eyePoint);
    createLightSource(&lightSource);
    createAmbience(&ambientLight);
    
    output = fopen("image.ppm", "w");
    
    fprintf(output, "P3\n");
    fprintf(output, "%d %d\n", view.width, view.height);
    fprintf(output, "%d\n\n", 255);
    
    castAllRays(&view, &eyePoint, &ambientLight, &lightSource, sphereList, &sphereListLength, &output);
    
    free(sphereList);
    fclose(output);
    
}