コード例 #1
0
int
main(void) {
    Camera * camera = create_camera();
    
    Canvas * canvas = new_canvas(CANVAS_W,
                                 CANVAS_H);
    
    int i;
    for(i = 0; i < MAX_SERPINSKY_PYRAMID_LEVEL; i++) {
        Scene * scene = new_scene(MAX_OBJECTS_NUMBER,
                                  MAX_LIGHT_SOURCES_NUMBER,
                                  BACKGROUND_COLOR);
    
        create_serpinsky_pyramid(scene, i);
        
        // Randomness causes unreproducible results
        // But in general - results are similar to Serpinsky pyramid
        //generate_random_spheres(scene, i * 400);

        prepare_scene(scene);
    
        printf("Number of polygons: %i. ", scene->last_object_index + 1);
    
        render_scene(scene,
                     camera,
                     canvas,
                     THREADS_NUM);
    
        release_scene(scene);
    }
    
    release_canvas(canvas);
    release_camera(camera);
    
    return 0;
}
コード例 #2
0
ファイル: HttpRestScene.cpp プロジェクト: sthdsnts/DMXStudio
// ----------------------------------------------------------------------------
//
bool HttpRestServices::edit_scene( CString& response, LPCSTR data, EditMode mode ) {
    if ( !studio.getVenue() || !studio.getVenue()->isRunning() )
        return false;

    SimpleJsonParser parser;
    UID scene_id;
    CString name, description;
    SceneNumber number;
    BPMRating bpm_rating;
    bool keep_groups;
    Scene* scene = NULL;
    UIDArray actors;
    PARSER_LIST animationParsers;
    std::vector<AbstractAnimation*> animations;
    Acts acts;

    try {
        parser.parse( data );

        scene_id = parser.get<ULONG>( "id" );
        name = parser.get<CString>( "name" );
        description = parser.get<CString>( "description" );
        number = parser.get<ULONG>( "number" );
        bpm_rating = (BPMRating)parser.get<UINT>( "bpm_rating" );
        keep_groups = parser.get<bool>( "keep_groups" );
        actors = parser.get<UIDArray>( "actors" );
        animationParsers = parser.get<PARSER_LIST>("animations");
        acts = parser.get<Acts>( "acts" );

        for ( PARSER_LIST::iterator it=animationParsers.begin(); it != animationParsers.end(); ++it ) {
            CString class_name = (*it).get<CString>( "class_name" );
            UIDArray animation_actors = (*it).get<UIDArray>( "actors" );
            SimpleJsonParser signalParser = (*it).get<SimpleJsonParser>( "signal" );
            SimpleJsonParser animationParser = (*it).get<SimpleJsonParser>( class_name );
            AnimationSignal signal = parseAnimationSignal( signalParser );

            ANIMATION_PARSER_FUNC anim_parser_func = animation_parsers[ class_name ];
            if ( anim_parser_func == NULL )
                throw std::exception( "Unknown animation class name from client" );

            animations.push_back( anim_parser_func( animationParser, signal, animation_actors ) );
        }
    }
    catch ( std::exception& e ) {
        throw StudioException( "JSON parser error (%s) data (%s)", e.what(), data );
    }

    if ( scene_id != 0 ) {
        scene = studio.getVenue()->getScene( scene_id );
        if ( !scene )
            return false;
    }

    // Make sure number is unique
    if ( mode != UPDATE || (scene && number != scene->getNumber()) ) {
        if ( studio.getVenue()->getSceneByNumber( number ) != NULL )
            return false;
    }

    switch ( mode ) {
    case NEW: {
        scene_id = studio.getVenue()->allocUID();
        Scene new_scene;
        new_scene.setUID( scene_id );
        studio.getVenue()->addScene( new_scene );
        scene = studio.getVenue()->getScene( scene_id );
        studio.getVenue()->moveDefaultFixturesToScene( scene_id, actors, keep_groups, true );
        break;
    }

    case COPY: {
        scene_id = studio.getVenue()->allocUID();
        Scene new_scene( *scene );
        new_scene.setUID( scene_id );
        studio.getVenue()->addScene( new_scene );
        scene = studio.getVenue()->getScene( scene_id );
    }

    // Fall through

    case UPDATE:
        // Verify actors - remove any that have been deselected
        UIDArray active_actors = scene->getActorUIDs();
        for ( UIDArray::iterator it=active_actors.begin(); it != active_actors.end(); ++it ) {
            if ( std::find( actors.begin(), actors.end(), *it ) == actors.end() )
                scene->removeActor( *it );
        }
        break;
    }

    scene->setName( name );
    scene->setSceneNumber( number );
    scene->setBPMRating( bpm_rating );
    scene->setDescription( description );
    scene->setActs( acts );

    scene->clearAnimations();
    for ( std::vector<AbstractAnimation*>::iterator it=animations.begin(); it != animations.end(); ++it )
        scene->addAnimation( *it );

    if ( mode != UPDATE )            // Switch to new scene
        studio.getVenue()->selectScene( scene->getUID() );
    else if ( studio.getVenue()->getCurrentSceneUID() == scene->getUID() )
        studio.getVenue()->loadScene( );

    return true;
}
コード例 #3
0
ファイル: shader.cpp プロジェクト: stelonix/tmpgl
	shader_program::shader_program() {
		new_scene();
	}
コード例 #4
0
ファイル: example.c プロジェクト: Uvlad/raytracing-render
int
main(void) {
    // Allocating scene
    Scene * scene = new_scene(MAX_OBJECTS_NUMBER,
                              MAX_LIGHT_SOURCES_NUMBER,
                              BACKGROUND_COLOR);
    
    // Allocating new sphere
    Float radius = 100;
    Point3d center = point3d(0, 0, 0);
    Color sphere_color = rgb(250, 30, 30);
    Material sphere_material = material(1, 5, 5, 10, 0, 10);
    Object3d * sphere = new_sphere(center,
                                   radius,
                                   sphere_color,
                                   sphere_material);
    
    // Adding sphere to the scene
    add_object(scene,
               sphere);
    
    // Allocating new triangle
    Object3d * triangle = new_triangle(point3d(-700, -700, -130), // vertex 1
                                       point3d( 700, -700, -130), // vertex 2
                                       point3d(   0,  400, -130), // vertex 3
                                       rgb(100, 255, 30),         // color
                                       material(1, 6, 0, 2, 0, 0) // surface params
                                       );
    
    // Adding triangle to the scene
    add_object(scene,
               triangle);
    
    // Loading 3D model of cow from *.obj file
    // defining transformations and parameters of 3D model
    // TODO: must be refactored...
    SceneFaceHandlerParams load_params =
    new_scene_face_handler_params(scene,
                                  // scale:
                                  40,
                                  // move dx, dy, dz:
                                  -150, -100, 30,
                                  // rotate around axises x, y, z:
                                  0, 0, 0,
                                  // color
                                  rgb(200, 200, 50),
                                  // surface params
                                  material(2, 3, 0, 0, 0, 0)
                                  );
    
    load_obj("./demo/models/cow.obj",
             // default handler which adding polygons of 3D model to scene:
             scene_face_handler,
             &load_params);
    
    // This function is requried (bulding k-d tree of entire scene)
    prepare_scene(scene);
    
    printf("\nNumber of polygons: %i\n", scene->last_object_index + 1);
    
    // Allocating new light source
    Color light_source_color = rgb(255, 255, 255);
    Point3d light_source_location = point3d(-300, 300, 300);
    LightSource3d * light_source = new_light_source(light_source_location,
                                                    light_source_color);
    // Adding light source to the scene
    add_light_source(scene,
                     light_source);
    
    // Adding fog
    Float density = 0.002;
    set_exponential_fog(scene, density);
    
    // Allocating camera
    // TODO: It's a pity, but quaternions are not implemented yet :(
    Point3d camera_location = point3d(0, 500, 0);
    Float focus = 320;
    Float x_angle = -1.57;
    Float y_angle = 0;
    Float z_angle = 3.14;
    Camera * camera = new_camera(camera_location,
                                 x_angle,
                                 y_angle,
                                 z_angle,
                                 focus);
    
    // Rotate camera if needed
    // rotate_camera(camera, d_x_angle, d_y_angle, d_z_angle);
    
    // Move camera if needed
    // move_camera(camera, vector3df(d_x, d_y, d_z));
    
    // Alocate new canvas, to render scene on it
    Canvas * canvas = new_canvas(CANVAS_W,
                                 CANVAS_H);
    
    render_scene(scene,
                 camera,
                 canvas,
                 THREADS_NUM);
    
    // Saving rendered image in PNG format
    write_png("example.png",
              canvas);
    
    release_canvas(canvas);
    release_scene(scene);
    release_camera(camera);
    
    return 0;
}