Пример #1
0
// build the moon object
ssgBranch * cGrMoon::build( double moon_size )
{
	ssgDeRefDelete( moon_transform );
    moon_transform = new ssgTransform;
	moon_transform->ref();

    moon_cl = new ssgColourArray( 1 );
    sgVec4 color;
    sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
    moon_cl->add( color );

    moon_state = new ssgSimpleState();
    moon_state->setTexture( "data/textures/moon.rgba" );
    moon_state->setShadeModel( GL_SMOOTH );
    moon_state->enable( GL_LIGHTING );
    moon_state->enable( GL_CULL_FACE );
    moon_state->enable( GL_TEXTURE_2D );
    moon_state->enable( GL_COLOR_MATERIAL );
    moon_state->setColourMaterial( GL_DIFFUSE );
    moon_state->setMaterial( GL_AMBIENT, 0, 0, 0, 1 );
    moon_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
    moon_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
    moon_state->enable( GL_BLEND );
    moon_state->enable( GL_ALPHA_TEST );
    moon_state->setAlphaClamp( 0.01f );

    ssgBranch *moon = grMakeSphere( moon_state, moon_cl, moon_size, 15, 15,
				    grMoonOrbPreDraw, grMoonOrbPostDraw );

    moon_transform->addKid( moon );
	repaint( 0.0 );

    return moon_transform;
}
Пример #2
0
ssgBranch * cGrCelestialBody::build( ssgSimpleState *orb_state, ssgSimpleState *halo_state, double body_size )
{
    ssgVertexArray *halo_vl;
    ssgTexCoordArray *halo_tl;

    // clean-up previous
    ssgDeRefDelete( transform );

    // build the ssg scene graph sub tree for the sky and connected
    // into the provide scene graph branch
    transform = new ssgTransform;
    transform->ref();

    cl = new ssgColourArray( 1 );
    sgVec4 color;
    sgSetVec4( color, 1.0, 1.0, 1.0, 1.0 );
    cl->add( color );

    ssgBranch *orb = grMakeSphere( orb_state, cl, (float)body_size, 15, 15,
                                   grCelestialBodyOrbPreDraw, grCelestialBodyOrbPostDraw );

    transform->addKid( orb );

    // force a repaint of the colors with arbitrary defaults
    repaint( 0.0 );

    if (halo_state)
    {
        // Build ssg structure
        float size = float(body_size * 10.0);
        sgVec3 v3;
        halo_vl = new ssgVertexArray;
        sgSetVec3( v3, -size, 0.0, -size );
        halo_vl->add( v3 );
        sgSetVec3( v3, size, 0.0, -size );
        halo_vl->add( v3 );
        sgSetVec3( v3, -size, 0.0,  size );
        halo_vl->add( v3 );
        sgSetVec3( v3, size, 0.0,  size );
        halo_vl->add( v3 );

        sgVec2 v2;
        halo_tl = new ssgTexCoordArray;
        sgSetVec2( v2, 0.0f, 0.0f );
        halo_tl->add( v2 );
        sgSetVec2( v2, 1.0, 0.0 );
        halo_tl->add( v2 );
        sgSetVec2( v2, 0.0, 1.0 );
        halo_tl->add( v2 );
        sgSetVec2( v2, 1.0, 1.0 );
        halo_tl->add( v2 );

        ssgLeaf *halo =
            new ssgVtxTable ( GL_TRIANGLE_STRIP, halo_vl, NULL, halo_tl, cl );
        halo->setState( halo_state );

        halo->setCallback( SSG_CALLBACK_PREDRAW, grCelestialBodyHaloPreDraw );
        halo->setCallback( SSG_CALLBACK_POSTDRAW, grCelestialBodyHaloPostDraw );

        transform->addKid( halo );
        //transform->addKid(new ssgaLensFlare);
    }

    return transform;
}