static void
snowglobeSpeedFactorOptionChange (CompScreen *s,
                                  CompOption            *opt,
                                  SnowglobeScreenOptions num)
{
    SNOWGLOBE_SCREEN (s);
    as->speedFactor = snowglobeGetSpeedFactor(s);
}
static void
freeSnowglobe (CompScreen *s)
{
    SNOWGLOBE_SCREEN (s);

    if (as->snow)
        free (as->snow);

    freeWater (as->water);
    freeWater (as->ground);

    glDeleteLists(as->snowflakeDisplayList,  1);
}
static void
snowglobeClearTargetOutput (CompScreen *s,
                            float      xRotate,
                            float      vRotate)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    UNWRAP (as, cs, clearTargetOutput);
    (*cs->clearTargetOutput) (s, xRotate, vRotate);
    WRAP (as, cs, clearTargetOutput, snowglobeClearTargetOutput);

    glClear (GL_DEPTH_BUFFER_BIT);
}
void
initializeWorldVariables(CompScreen *s)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    as->speedFactor = snowglobeGetSpeedFactor(s);

    as->hsize = s->hsize * cs->nOutput;

    as->arcAngle = 360.0f / as->hsize;
    as->radius = cs->distance/sinf(0.5*(PI-as->arcAngle*toRadians));
    as->distance = cs->distance;
}
static void
snowglobeDonePaintScreen (CompScreen * s)
{
    SNOWGLOBE_SCREEN (s);

    if (as->damage)
    {
        damageScreen (s);
        as->damage = FALSE;
    }

    UNWRAP (as, s, donePaintScreen);
    (*s->donePaintScreen) (s);
    WRAP (as, s, donePaintScreen, snowglobeDonePaintScreen);
}
static void
snowglobeFiniScreen (CompPlugin *p,
                     CompScreen *s)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    freeSnowglobe(s);

    UNWRAP (as, s, donePaintScreen);
    UNWRAP (as, s, preparePaintScreen);
    UNWRAP (as, cs, clearTargetOutput);
    UNWRAP (as, cs, paintInside);

    free(as);
}
예제 #7
0
void
updateGround (CompScreen *s, float time)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    int sDiv = snowglobeGetGridQuality (s);
    int size = s->hsize * cs->nOutput;

    Bool update = FALSE;

    if (!as->ground)
    {
	as->ground = genWater (size, sDiv, cs->distance, -0.5);
	update = TRUE;
    }

    if (!as->ground)
	return;

    if (as->ground->size != size || as->ground->sDiv != sDiv ||
	as->ground->distance != cs->distance)
    {
	freeWater (as->ground);
	as->ground = genWater (size, sDiv, cs->distance, -0.5);

	update = TRUE;
	if (!as->ground)
	    return;
    }

    if (!update)
	return;

    as->ground->wave1 = (float)(rand() & 15) / 15.0;
    as->ground->wave2 = (float)(rand() & 15) / 15.0;

    as->ground->bh  = -0.45;
    as->ground->wa  = 0.1;
    as->ground->swa = 0.02;
    as->ground->wf  = 2.0;
    as->ground->swf = 10.0;

    updateHeight (as->ground);
}
static void
snowglobePreparePaintScreen (CompScreen *s,
                             int        ms)
{
    SNOWGLOBE_SCREEN (s);

    int i;

    for (i = 0; i < as->numSnowflakes; i++)
    {
        SnowflakeDrift(s, i);
    }

    updateWater(s, (float)ms / 1000.0);
    updateGround(s, (float)ms / 1000.0);

    UNWRAP (as, s, preparePaintScreen);
    (*s->preparePaintScreen)(s, ms);
    WRAP (as, s, preparePaintScreen, snowglobePreparePaintScreen);
}
static void
initSnowglobe (CompScreen *s)
{

    SNOWGLOBE_SCREEN (s);

    as->water = NULL;
    as->ground = NULL;

    as->numSnowflakes = snowglobeGetNumSnowflakes(s);

    as->snow = calloc(as->numSnowflakes, sizeof(snowflakeRec));

    initializeWorldVariables(s);

    int i;
    for (i=0; i< as->numSnowflakes; i++)
    {
        as->snow[i].size = snowglobeGetSnowflakeSize(s)
                           +sqrt(randf(snowglobeGetSnowflakeSize(s)));

        newSnowflakePosition(as, i);

        as->snow[i].psi = randf(2*PI);
        as->snow[i].theta= randf(PI);

        as->snow[i].dpsi = randf(5);
        as->snow[i].dtheta = randf(5);

        as->snow[i].speed = randf(0.4)+0.2;

    }

    as->waterHeight = 50000;

    as->snowflakeDisplayList = glGenLists(1);
    glNewList(as->snowflakeDisplayList, GL_COMPILE);
    DrawSnowflake(0);
    glEndList();
}
예제 #10
0
void
updateWater (CompScreen *s, float time)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    int sDiv = 0;
    int size = s->hsize * cs->nOutput;

    if (!as->water)
	as->water = genWater (size, sDiv, cs->distance, -0.5);

    if (!as->water)
	return;



    if (as->water->size != size || as->water->sDiv != sDiv ||
	as->water->distance != cs->distance)
    {
	freeWater (as->water);
	as->water = genWater (size, sDiv, cs->distance, -0.5);

	if (!as->water)
	    return;
    }

    as->water->wave1 += 0;
    as->water->wave2 += 0;

    as->water->wave1 = 0;
    as->water->wave2 = 0;
    as->water->bh  = 0.5;

	as->water->wa  = 0.0;
	as->water->swa = 0.0;
	as->water->wf  = 0.0;
	as->water->swf = 0.0;

}
static void
snowglobePaintInside (CompScreen *s,
                      const ScreenPaintAttrib *sAttrib,
                      const CompTransform     *transform,
                      CompOutput              *output,
                      int                     size)
{
    SNOWGLOBE_SCREEN (s);
    CUBE_SCREEN (s);

    int i;

    as->waterHeight = 50000;

    if (as->hsize!=s->hsize) updateSnowglobe (s);


    static const float mat_shininess[] = { 60.0 };
    static const float mat_specular[] = { 0.8, 0.8, 0.8, 1.0 };
    static const float mat_diffuse[] = { 0.46, 0.66, 0.795, 1.0 };
    static const float mat_ambient[] = { 0.1, 0.1, 0.3, 1.0 };
    static const float lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
    static const float lmodel_localviewer[] = { 0.0 };

    ScreenPaintAttrib sA = *sAttrib;
    CompTransform mT = *transform;

    if (snowglobeGetShowWater(s))
        updateHeight(as->water);

    sA.yRotate += cs->invert * (360.0f / size) *
                  (cs->xRotations - (s->x* cs->nOutput));

    (*s->applyScreenTransform)(s, &sA, output, &mT);

    glPushMatrix();

    glLoadMatrixf(mT.m);

    glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f);

    glScalef(cs->outputXScale, cs->outputYScale, 1.0f);

    Bool enabledCull = FALSE;

    glPushAttrib(GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);

    glEnable(GL_BLEND);

    if (glIsEnabled(GL_CULL_FACE))
    {
        enabledCull = TRUE;
    }

    int cull;

    glGetIntegerv(GL_CULL_FACE_MODE, &cull);
    glEnable(GL_CULL_FACE);

    glCullFace(~cull & (GL_FRONT | GL_BACK));

    if (snowglobeGetShowWater(s))
    {
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, TRUE, FALSE);
    }
    glCullFace(cull);

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawGround(NULL, as->ground);

    }

    glPushMatrix();

    glColor4usv(defaultColor);

    glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
    glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer);

    glEnable(GL_NORMALIZE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT0);

    glEnable(GL_COLOR_MATERIAL);

    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    for (i = 0; i < as->numSnowflakes; i++)
    {
        glPushMatrix();
        SnowflakeTransform(&(as->snow[i]));

        float scale = 0.01*as->snow[i].size;
        glScalef(scale, scale, scale);

        initDrawSnowflake();
        glCallList(as->snowflakeDisplayList);
        finDrawSnowflake();
        glPopMatrix();
    }

    if (snowglobeGetShowSnowman(s))
    {
        glPushMatrix();

        float bottom = -0.5;
        if (snowglobeGetShowGround(s))
            bottom = getHeight(as->ground, 0, 0);
        glTranslatef(0, bottom, 0);

        float scale = 0.4*snowglobeGetSnowmanSize(s)*(0.5-bottom);
        glScalef(scale, scale, scale);

        glColor4f(1.0, 1.0, 1.0, 1.0);

        DrawSnowman(0);
        glPopMatrix();
    }

    glPopMatrix();

    if (snowglobeGetShowWater(s))
    {
        glEnable(GL_CULL_FACE);
        glColor4usv(snowglobeGetWaterColor(s));
        drawWater(as->water, snowglobeGetShowWater(s), 0);
    }

    if (snowglobeGetShowGround(s))
    {
        glColor4f(0.8, 0.8, 0.8, 1.0);
        drawBottomGround(s->hsize * cs->nOutput, cs->distance, -0.4999);
    }

    glDisable(GL_LIGHT1);
    glDisable(GL_NORMALIZE);

    if (!s->lighting)
        glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);

    if (enabledCull)
        glDisable(GL_CULL_FACE);

    glPopMatrix();

    glPopAttrib();

    as->damage = TRUE;

    UNWRAP (as, cs, paintInside);
    (*cs->paintInside)(s, sAttrib, transform, output, size);
    WRAP (as, cs, paintInside, snowglobePaintInside);
}