summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mikos <metastability@opencompositing.org>2008-01-13 14:17:11 +1030
committerDavid Mikos <metastability@opencompositing.org>2008-01-13 14:17:11 +1030
commit79dd1aea9bc1ffc2f8134ba9ef237264eca38725 (patch)
treee1194c875599a0a1580c43045e44c8db1d619664
parent7a9efa3b9c593e78216369d17a52d9fa33390219 (diff)
downloadsnowglobe-79dd1aea9bc1ffc2f8134ba9ef237264eca38725.tar.gz
snowglobe-79dd1aea9bc1ffc2f8134ba9ef237264eca38725.tar.bz2
Move snowflakes according to cube position.
-rw-r--r--movement.c140
-rw-r--r--snowflake.c32
-rw-r--r--snowglobe-internal.h19
-rw-r--r--snowglobe.c496
-rw-r--r--snowglobe.xml.in9
-rw-r--r--util.c30
6 files changed, 391 insertions, 335 deletions
diff --git a/movement.c b/movement.c
index 1d3c8af..901f190 100644
--- a/movement.c
+++ b/movement.c
@@ -1,4 +1,5 @@
#include "snowglobe-internal.h"
+#include "snowglobe_options.h"
#include <math.h>
#include <float.h>
@@ -7,67 +8,98 @@ void
SnowflakeTransform (snowflakeRec * snow)
{
- glTranslatef (snow->y, snow->z, snow->x);
- glRotatef (-snow->psi, 0.0, 1.0, 0.0);
- glRotatef (snow->theta, 1.0, 0.0, 0.0);
+ glTranslatef (snow->y, snow->z, snow->x);
+ glRotatef (-snow->psi, 0.0, 1.0, 0.0);
+ glRotatef (snow->theta, 1.0, 0.0, 0.0);
}
-void newSnowflakePosition(SnowglobeScreen *as, int i) {
- int sector = NRAND(hSize);
- float ang = randf(2*PI/q)-PI/q;
- float r = (radius-0.01*as->snow[i].size/2);
- float factor = sinf(PI*(0.5-1/q))/sinf(PI*(0.5-1/q)+fabsf(ang));
- ang += (0.5+((float) sector))*2*PI/q;
- ang = fmodf(ang,2*PI);
+void
+newSnowflakePosition(SnowglobeScreen *as, int i)
+{
+ int sector = NRAND(hSize);
+ float ang = randf(2*PI/q)-PI/q;
+ float r = (radius-0.01*as->snow[i].size/2);
+ float factor = sinf(PI*(0.5-1/q))/sinf(PI*(0.5-1/q)+fabsf(ang));
+ ang += (0.5+((float) sector))*2*PI/q;
+ ang = fmodf(ang,2*PI);
- float d = randf(1);
- d=(1-d*d)*r*factor;
+ float d = randf(1);
+ d=(1-d*d)*r*factor;
- as->snow[i].x = d*cosf(ang);
- as->snow[i].y = d*sinf(ang);
- as->snow[i].z = 0.5;
+ as->snow[i].x = d*cosf(ang);
+ as->snow[i].y = d*sinf(ang);
+ as->snow[i].z = 0.5;
}
+
void
-SnowflakeDrift (SnowglobeScreen *as, int index)
+SnowflakeDrift (CompScreen *s, int index)
{
- snowflakeRec * snow = &(as->snow[index]);
-
- float speed = snow->speed*speedFactor;
- speed/=1000;
- float x = snow->x;
- float y = snow->y;
- float z = snow->z;
-
- z-=speed;
- x+=2*(randf(2*speed)-speed);
- y+=2*(randf(2*speed)-speed);
-
- float bottom = (renderGround ? getHeight(as->ground, x, y) : -0.5);
-
- if (z<bottom) {
- z = 0.5; newSnowflakePosition(as, index);
- }
+ SNOWGLOBE_SCREEN (s);
+ CUBE_SCREEN (s);
- float ang = atan2(y,x);
-
- int i;
- for (i=0; i<hSize; i++) {
- float cosAng = cosf(fmodf(2*i*PI/q-ang, 2*PI));
- if (cosAng<=0) continue;
-
- float d = (distance-0.01*snow->size/2)/cosAng;
- float r = hypot(x,y);
- if (r>d) {
- x = d*cosf(ang);
- y = d*sinf(ang);
- }
+ //float oldXRotate = as->xRotate;
+ //float oldVRotate = as->vRotate;
+
+ (*cs->getRotation) (s, &(as->xRotate), &(as->vRotate));
+
+ snowflakeRec * snow = &(as->snow[index]);
+
+ float speed = snow->speed*speedFactor;
+ speed/=1000;
+ float x = snow->x;
+ float y = snow->y;
+ float z = snow->z;
+
+ float sideways = 2*(randf(2*speed)-speed);
+ float vertical = -speed;
+
+ z+=sideways*sinf(as->vRotate*toRadians)+vertical*cosf(as->vRotate*toRadians);
+ x+=sideways*cosf(as->xRotate*toRadians)*cosf(as->vRotate*toRadians)-vertical*cosf(as->xRotate*toRadians)*sinf(as->vRotate*toRadians);
+ y+=sideways*sinf(as->xRotate*toRadians)*cosf(as->vRotate*toRadians)+vertical*sinf(as->xRotate*toRadians)*sinf(as->vRotate*toRadians);
+
+ float bottom = (renderGround ? getHeight(as->ground, x, y) : -0.5)+0.01*snow->size/2;
+
+ if (z<bottom)
+ {
+ //if (snowglobeGetShakeCube(s))
+ //{
+ // z = bottom;
+ //}
+ //else {
+ z = 0.5;
+ newSnowflakePosition(as, index);
+ //}
+ }
+
+ float top = 0.5-0.01*snow->size/2;
+ if (z>top)
+ {
+ z = top;
+ }
+
+
+ float ang = atan2(y, x);
+
+ int i;
+ for (i=0; i<hSize; i++)
+ {
+ float cosAng = cosf(fmodf(2*i*PI/q-ang, 2*PI));
+ if (cosAng<=0)
+ continue;
+
+ float d = (distance-0.01*snow->size/2)/cosAng;
+ float r = hypot(x, y);
+ if (r>d)
+ {
+ x = d*cosf(ang);
+ y = d*sinf(ang);
}
-
- snow->x = x;
- snow->y = y;
- snow->z = z;
-
- snow->psi = fmodf(snow->psi+snow->dpsi*speedFactor, 360);
- snow->theta= fmodf(snow->theta+snow->dtheta*speedFactor, 360);
-
+ }
+
+ snow->x = x;
+ snow->y = y;
+ snow->z = z;
+
+ snow->psi = fmodf(snow->psi+snow->dpsi*speedFactor, 360);
+ snow->theta= fmodf(snow->theta+snow->dtheta*speedFactor, 360);
}
diff --git a/snowflake.c b/snowflake.c
index 7155bc2..087ab14 100644
--- a/snowflake.c
+++ b/snowflake.c
@@ -360,21 +360,25 @@ glVertex3fv(P0031);
glEnd ();
}
-void initDrawSnowflake() {
-glRotatef(180.0, 0.0, 1.0, 0.0);
-glRotatef(90.0, 0.0, 1.0, 0.0);
-glEnable(GL_CULL_FACE);
-glEnable(GL_DEPTH_TEST);
-glEnable(GL_RESCALE_NORMAL);
+void
+initDrawSnowflake()
+{
+ glRotatef(180.0, 0.0, 1.0, 0.0);
+ glRotatef(90.0, 0.0, 1.0, 0.0);
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+ glEnable(GL_RESCALE_NORMAL);
-glDisable (GL_COLOR_MATERIAL);
-glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, null_shininess);
-glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, null_ambient);
-glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, null_diffuse);
-glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, null_specular);
+ glDisable(GL_COLOR_MATERIAL);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, null_shininess);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, null_ambient);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, null_diffuse);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, null_specular);
}
-void finDrawSnowflake() {
-glDisable(GL_CULL_FACE);
+void
+finDrawSnowflake()
+{
+ glDisable(GL_CULL_FACE);
}
diff --git a/snowglobe-internal.h b/snowglobe-internal.h
index 5538a13..ca96829 100644
--- a/snowglobe-internal.h
+++ b/snowglobe-internal.h
@@ -39,10 +39,10 @@ extern int cubeDisplayPrivateIndex;
typedef struct _snowflakeRec
{
- float x, y, z;
- float theta, psi;
- float dpsi, dtheta;
- float speed, size;
+ float x, y, z;
+ float theta, psi;
+ float dpsi, dtheta;
+ float speed, size;
}
snowflakeRec;
@@ -89,7 +89,7 @@ SnowglobeDisplay;
typedef struct _SnowglobeScreen
{
- DonePaintScreenProc donePaintScreen;
+ DonePaintScreenProc donePaintScreen;
PreparePaintScreenProc preparePaintScreen;
CubeClearTargetOutputProc clearTargetOutput;
@@ -103,6 +103,11 @@ typedef struct _SnowglobeScreen
Water *water;
Water *ground;
+
+ GLuint snowflakeDisplayList;
+
+ float xRotate;
+ float vRotate;
}
SnowglobeScreen;
@@ -137,7 +142,7 @@ getHeight (Water *w, float x, float z);
void SnowflakeTransform(snowflakeRec *);
void newSnowflakePosition(SnowglobeScreen *, int);
-void SnowflakeDrift (SnowglobeScreen *, int);
+void SnowflakeDrift (CompScreen *, int);
void initializeWorldVariables(int, float);
void updateSpeedFactor(float);
@@ -167,7 +172,7 @@ float smallWaveAmplitude;
float smallWaveFrequency;
Bool renderGround;
-GLuint snowflakeDisplayList;
+
//All calculations that matter with angles are done clockwise from top.
diff --git a/snowglobe.c b/snowglobe.c
index 51282be..873eb2a 100644
--- a/snowglobe.c
+++ b/snowglobe.c
@@ -85,87 +85,90 @@ static void
initSnowglobe (CompScreen *s)
{
- SNOWGLOBE_SCREEN (s);
- CUBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
+ CUBE_SCREEN (s);
- as->water = NULL;
- as->ground = NULL;
+ as->water = NULL;
+ as->ground = NULL;
- as->numSnowflakes = snowglobeGetNumSnowflakes(s);
+ as->numSnowflakes = snowglobeGetNumSnowflakes(s);
- as->snow = calloc (as->numSnowflakes, sizeof(snowflakeRec) );
+ as->snow = calloc(as->numSnowflakes, sizeof(snowflakeRec));
- initializeWorldVariables(s->hsize, cs->distance);
+ initializeWorldVariables(s->hsize, cs->distance);
- int i;
- for (i=0; i< as->numSnowflakes; i++) {
- as->snow[i].size = snowglobeGetSnowflakeSize(s)+sqrt(randf(snowglobeGetSnowflakeSize(s)));
+ int i;
+ for (i=0; i< as->numSnowflakes; i++)
+ {
+ as->snow[i].size = snowglobeGetSnowflakeSize(s)
+ +sqrt(randf(snowglobeGetSnowflakeSize(s)));
- newSnowflakePosition(as, i);
+ newSnowflakePosition(as, i);
- as->snow[i].psi = randf(2*PI);
- as->snow[i].theta= randf(PI);
+ 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].dpsi = randf(5);
+ as->snow[i].dtheta = randf(5);
- as->snow[i].speed = randf(0.4)+0.2;
+ as->snow[i].speed = randf(0.4)+0.2;
- }
+ }
+ waterHeight = 50000;
- waterHeight = 50000;
+ speedFactor = snowglobeGetSpeedFactor(s);
- speedFactor = snowglobeGetSpeedFactor(s);
-
- snowflakeDisplayList = glGenLists(1);
- glNewList(snowflakeDisplayList, GL_COMPILE);
- DrawSnowflake(0);
- glEndList();
+ as->snowflakeDisplayList = glGenLists(1);
+ glNewList(as->snowflakeDisplayList, GL_COMPILE);
+ DrawSnowflake(0);
+ glEndList();
}
-void initializeWorldVariables(int hs, float perpDistCentreToWall) { //precalculate some values
+void
+initializeWorldVariables(int hs, float perpDistCentreToWall)
+{ //precalculate some values
- hSize = hs;
- q = (float) hSize;
+ hSize = hs;
+ q = (float) hSize;
- distance = perpDistCentreToWall;
- radius = perpDistCentreToWall/sin(PI*(0.5-1/q));
+ distance = perpDistCentreToWall;
+ radius = perpDistCentreToWall/sin(PI*(0.5-1/q));
}
static void
freeSnowglobe (CompScreen *s)
{
- SNOWGLOBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
- if (as->snow)
- free (as->snow);
+ if (as->snow)
+ free (as->snow);
- freeWater (as->water);
- freeWater (as->ground);
+ freeWater (as->water);
+ freeWater (as->ground);
- glDeleteLists(snowflakeDisplayList, 1);
+ glDeleteLists(as->snowflakeDisplayList, 1);
}
static void
updateSnowglobe (CompScreen *s)
{
- freeSnowglobe (s);
- initSnowglobe (s);
+ freeSnowglobe (s);
+ initSnowglobe (s);
}
static void
snowglobeScreenOptionChange (CompScreen *s,
CompOption *opt,
SnowglobeScreenOptions num)
{
- updateSnowglobe (s);
+ updateSnowglobe (s);
}
static void
snowglobeSpeedFactorOptionChange (CompScreen *s,
CompOption *opt,
SnowglobeScreenOptions num)
{
- speedFactor = snowglobeGetSpeedFactor(s);
+ speedFactor = snowglobeGetSpeedFactor(s);
}
static void
@@ -173,365 +176,360 @@ snowglobeClearTargetOutput (CompScreen *s,
float xRotate,
float vRotate)
{
- SNOWGLOBE_SCREEN (s);
- CUBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
+ CUBE_SCREEN (s);
- UNWRAP (as, cs, clearTargetOutput);
- (*cs->clearTargetOutput) (s, xRotate, vRotate);
- WRAP (as, cs, clearTargetOutput, snowglobeClearTargetOutput);
+ UNWRAP (as, cs, clearTargetOutput);
+ (*cs->clearTargetOutput) (s, xRotate, vRotate);
+ WRAP (as, cs, clearTargetOutput, snowglobeClearTargetOutput);
- glClear (GL_DEPTH_BUFFER_BIT);
+ glClear (GL_DEPTH_BUFFER_BIT);
}
-static void snowglobePaintInside (CompScreen *s,
+static void
+snowglobePaintInside (CompScreen *s,
const ScreenPaintAttrib *sAttrib,
const CompTransform *transform,
CompOutput *output,
int size)
{
- SNOWGLOBE_SCREEN (s);
- CUBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
+ CUBE_SCREEN (s);
- waterHeight = 50000;
+ int i;
- if (hSize!=s->hsize) updateSnowglobe (s);
+ waterHeight = 50000;
- int i;
+ if (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;
+ 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 };
- if (snowglobeGetShowWater (s))
- updateHeight (as->water);
+ ScreenPaintAttrib sA = *sAttrib;
+ CompTransform mT = *transform;
- sA.yRotate += cs->invert * (360.0f / size) *
- (cs->xRotations - (s->x * cs->nOutput));
+ if (snowglobeGetShowWater(s))
+ updateHeight(as->water);
- (*s->applyScreenTransform) (s, &sA, output, &mT);
+ sA.yRotate += cs->invert * (360.0f / size) *
+ (cs->xRotations - (s->x* cs->nOutput));
- glPushMatrix();
+ (*s->applyScreenTransform)(s, &sA, output, &mT);
- glLoadMatrixf (mT.m);
+ glPushMatrix();
- glTranslatef (cs->outputXOffset, -cs->outputYOffset, 0.0f);
+ glLoadMatrixf(mT.m);
- glScalef (cs->outputXScale, cs->outputYScale, 1.0f);
+ glTranslatef(cs->outputXOffset, -cs->outputYOffset, 0.0f);
- Bool enabledCull = FALSE;
+ glScalef(cs->outputXScale, cs->outputYScale, 1.0f);
- glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);
+ Bool enabledCull = FALSE;
- glEnable (GL_BLEND);
+ glPushAttrib(GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT | GL_LIGHTING_BIT);
- if (glIsEnabled (GL_CULL_FACE))
- {
- enabledCull = TRUE;
- }
+ glEnable(GL_BLEND);
- int cull;
+ if (glIsEnabled(GL_CULL_FACE))
+ {
+ enabledCull = TRUE;
+ }
- glGetIntegerv (GL_CULL_FACE_MODE, &cull);
- glEnable (GL_CULL_FACE);
+ int cull;
- glCullFace (~cull & (GL_FRONT | GL_BACK));
+ glGetIntegerv(GL_CULL_FACE_MODE, &cull);
+ glEnable(GL_CULL_FACE);
- if (snowglobeGetShowWater (s))
- {
- glColor4usv (snowglobeGetWaterColor (s));
- drawWater (as->water, TRUE, FALSE);
- }
- glCullFace (cull);
+ 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);
-
- }
+ if (snowglobeGetShowGround(s))
+ {
+ glColor4f(0.8, 0.8, 0.8, 1.0);
+ drawGround(NULL, as->ground);
- glPushMatrix();
+ }
- glColor4usv (defaultColor);
+ glPushMatrix();
- 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);
+ glColor4usv(defaultColor);
- glEnable (GL_NORMALIZE);
- glEnable (GL_LIGHTING);
- glEnable (GL_LIGHT1);
- glEnable (GL_LIGHT0);
+ 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_COLOR_MATERIAL);
+ glEnable(GL_NORMALIZE);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT1);
+ glEnable(GL_LIGHT0);
- glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- for (i = 0; i < as->numSnowflakes; i++)
- {
- glPushMatrix();
- SnowflakeTransform (& (as->snow[i]) );
+ glEnable(GL_COLOR_MATERIAL);
- float scale = 0.01*as->snow[i].size;
- glScalef (scale, scale, scale);
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- initDrawSnowflake();
- glCallList(snowflakeDisplayList);
- finDrawSnowflake();
- glPopMatrix();
- }
+ for (i = 0; i < as->numSnowflakes; i++)
+ {
+ glPushMatrix();
+ SnowflakeTransform(&(as->snow[i]));
- if (snowglobeGetShowSnowman(s)) {
- glPushMatrix();
-
- float bottom = -0.5;
- if (snowglobeGetShowGround(s)) bottom = getHeight(as->ground, 0,0);
- glTranslatef (0, bottom, 0);
+ float scale = 0.01*as->snow[i].size;
+ glScalef(scale, scale, scale);
- float scale = 0.4*snowglobeGetSnowmanSize(s)*(0.5-bottom);
- glScalef (scale, scale, scale);
+ initDrawSnowflake();
+ glCallList(as->snowflakeDisplayList);
+ finDrawSnowflake();
+ glPopMatrix();
+ }
- glColor4f (1.0, 1.0, 1.0, 1.0);
+ if (snowglobeGetShowSnowman(s))
+ {
+ glPushMatrix();
- DrawSnowman(0);
- glPopMatrix();
- }
+ 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();
+ }
- if (snowglobeGetShowWater (s))
- {
- glEnable (GL_CULL_FACE);
- glColor4usv (snowglobeGetWaterColor (s));
- drawWater (as->water, snowglobeGetShowWater (s), 0);
- }
+ glPopMatrix();
- if (snowglobeGetShowGround (s))
- {
- glColor4f (0.8, 0.8, 0.8, 1.0);
- drawBottomGround (s->hsize * cs->nOutput, cs->distance, -0.4999);
- }
+ 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_LIGHT1);
- glDisable (GL_NORMALIZE);
+ glDisable(GL_DEPTH_TEST);
- if (!s->lighting)
- glDisable (GL_LIGHTING);
+ if (enabledCull)
+ glDisable(GL_CULL_FACE);
- glDisable (GL_DEPTH_TEST);
+ glPopMatrix();
- if (enabledCull)
- glDisable (GL_CULL_FACE);
+ glPopAttrib();
- glPopMatrix();
-
- glPopAttrib();
+ as->damage = TRUE;
- as->damage = TRUE;
-
- UNWRAP (as, cs, paintInside);
- (*cs->paintInside) (s, sAttrib, transform, output, size);
- WRAP (as, cs, paintInside, snowglobePaintInside);
+ UNWRAP (as, cs, paintInside);
+ (*cs->paintInside)(s, sAttrib, transform, output, size);
+ WRAP (as, cs, paintInside, snowglobePaintInside);
}
static void
snowglobePreparePaintScreen (CompScreen *s,
int ms)
{
- SNOWGLOBE_SCREEN (s);
-
- renderGround = snowglobeGetShowGround(s);
- int i;
+ SNOWGLOBE_SCREEN (s);
- for (i = 0; i < as->numSnowflakes; i++)
- {
- SnowflakeDrift (as, i);
- }
+ renderGround = snowglobeGetShowGround(s);
+ int i;
- updateWater (s, (float)ms / 1000.0);
- updateGround (s, (float)ms / 1000.0);
+ 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);
+ UNWRAP (as, s, preparePaintScreen);
+ (*s->preparePaintScreen)(s, ms);
+ WRAP (as, s, preparePaintScreen, snowglobePreparePaintScreen);
}
static void
snowglobeDonePaintScreen (CompScreen * s)
{
- SNOWGLOBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
- if (as->damage)
- {
- damageScreen (s);
- as->damage = FALSE;
- }
+ if (as->damage)
+ {
+ damageScreen (s);
+ as->damage = FALSE;
+ }
- UNWRAP (as, s, donePaintScreen);
- (*s->donePaintScreen) (s);
- WRAP (as, s, donePaintScreen, snowglobeDonePaintScreen);
+ UNWRAP (as, s, donePaintScreen);
+ (*s->donePaintScreen) (s);
+ WRAP (as, s, donePaintScreen, snowglobeDonePaintScreen);
}
static Bool
snowglobeInitDisplay (CompPlugin *p,
CompDisplay *d)
{
- SnowglobeDisplay *ad;
+ SnowglobeDisplay *ad;
- if (!checkPluginABI ("core", CORE_ABIVERSION) ||
- !checkPluginABI ("cube", CUBE_ABIVERSION))
- return FALSE;
+ if (!checkPluginABI("core", CORE_ABIVERSION)
+ || !checkPluginABI("cube", CUBE_ABIVERSION))
+ return FALSE;
- if (!getPluginDisplayIndex (d, "cube", &cubeDisplayPrivateIndex))
- return FALSE;
+ if (!getPluginDisplayIndex(d, "cube", &cubeDisplayPrivateIndex))
+ return FALSE;
- ad = malloc (sizeof (SnowglobeDisplay));
+ ad = malloc(sizeof(SnowglobeDisplay));
- if (!ad)
- return FALSE;
+ if (!ad)
+ return FALSE;
- ad->screenPrivateIndex = allocateScreenPrivateIndex (d);
+ ad->screenPrivateIndex = allocateScreenPrivateIndex(d);
- if (ad->screenPrivateIndex < 0)
- {
- free (ad);
- return FALSE;
- }
+ if (ad->screenPrivateIndex < 0)
+ {
+ free(ad);
+ return FALSE;
+ }
- d->base.privates[snowglobeDisplayPrivateIndex].ptr = ad;
+ d->base.privates[snowglobeDisplayPrivateIndex].ptr = ad;
- return TRUE;
+ return TRUE;
}
static void
snowglobeFiniDisplay (CompPlugin *p,
CompDisplay *d)
{
- SNOWGLOBE_DISPLAY (d);
+ SNOWGLOBE_DISPLAY (d);
- freeScreenPrivateIndex (d, ad->screenPrivateIndex);
- free (ad);
+ freeScreenPrivateIndex(d, ad->screenPrivateIndex);
+ free(ad);
}
static Bool
snowglobeInitScreen (CompPlugin *p,
CompScreen *s)
{
- static const float ambient[] = { 0.3, 0.3, 0.3, 1.0 };
- static const float diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
- static const float position[] = { 0.0, 1.0, 0.0, 0.0 };
-
- SnowglobeScreen *as;
+ static const float ambient[] = { 0.3, 0.3, 0.3, 1.0 };
+ static const float diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
+ static const float position[] = { 0.0, 1.0, 0.0, 0.0 };
- SNOWGLOBE_DISPLAY (s->display);
- CUBE_SCREEN (s);
+ SnowglobeScreen *as;
- as = malloc (sizeof (SnowglobeScreen) );
+ SNOWGLOBE_DISPLAY (s->display);
+ CUBE_SCREEN (s);
- if (!as)
- return FALSE;
+ as = malloc(sizeof(SnowglobeScreen));
- s->base.privates[ad->screenPrivateIndex].ptr = as;
-
- as->damage = FALSE;
+ if (!as)
+ return FALSE;
- glLightfv (GL_LIGHT1, GL_AMBIENT, ambient);
- glLightfv (GL_LIGHT1, GL_DIFFUSE, diffuse);
- glLightfv (GL_LIGHT1, GL_POSITION, position);
+ s->base.privates[ad->screenPrivateIndex].ptr = as;
- initSnowglobe (s);
+ as->damage = FALSE;
+ glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
+ glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
+ glLightfv(GL_LIGHT1, GL_POSITION, position);
- snowglobeSetSpeedFactorNotify (s, snowglobeSpeedFactorOptionChange);
+ initSnowglobe(s);
- snowglobeSetNumSnowflakesNotify (s, snowglobeScreenOptionChange);
- snowglobeSetSnowflakeSizeNotify (s, snowglobeScreenOptionChange);
+ snowglobeSetSpeedFactorNotify(s, snowglobeSpeedFactorOptionChange);
+ snowglobeSetNumSnowflakesNotify(s, snowglobeScreenOptionChange);
+ snowglobeSetSnowflakeSizeNotify(s, snowglobeScreenOptionChange);
- WRAP (as, s, donePaintScreen, snowglobeDonePaintScreen);
- WRAP (as, s, preparePaintScreen, snowglobePreparePaintScreen);
- WRAP (as, cs, clearTargetOutput, snowglobeClearTargetOutput);
- WRAP (as, cs, paintInside, snowglobePaintInside);
+ WRAP (as, s, donePaintScreen, snowglobeDonePaintScreen);
+ WRAP (as, s, preparePaintScreen, snowglobePreparePaintScreen);
+ WRAP (as, cs, clearTargetOutput, snowglobeClearTargetOutput);
+ WRAP (as, cs, paintInside, snowglobePaintInside);
- return TRUE;
+ return TRUE;
}
static void
snowglobeFiniScreen (CompPlugin *p,
CompScreen *s)
{
- SNOWGLOBE_SCREEN (s);
- CUBE_SCREEN (s);
+ SNOWGLOBE_SCREEN (s);
+ CUBE_SCREEN (s);
- freeSnowglobe (s);
+ freeSnowglobe(s);
- UNWRAP (as, s, donePaintScreen);
- UNWRAP (as, s, preparePaintScreen);
- UNWRAP (as, cs, clearTargetOutput);
- UNWRAP (as, cs, paintInside);
+ UNWRAP (as, s, donePaintScreen);
+ UNWRAP (as, s, preparePaintScreen);
+ UNWRAP (as, cs, clearTargetOutput);
+ UNWRAP (as, cs, paintInside);
- free (as);
+ free(as);
}
static Bool
snowglobeInit (CompPlugin * p)
{
- snowglobeDisplayPrivateIndex = allocateDisplayPrivateIndex();
+ snowglobeDisplayPrivateIndex = allocateDisplayPrivateIndex();
- if (snowglobeDisplayPrivateIndex < 0)
- return FALSE;
+ if (snowglobeDisplayPrivateIndex < 0)
+ return FALSE;
- return TRUE;
+ return TRUE;
}
static void
snowglobeFini (CompPlugin * p)
{
- if (snowglobeDisplayPrivateIndex >= 0)
- freeDisplayPrivateIndex (snowglobeDisplayPrivateIndex);
+ if (snowglobeDisplayPrivateIndex >= 0)
+ freeDisplayPrivateIndex (snowglobeDisplayPrivateIndex);
}
static CompBool
snowglobeInitObject (CompPlugin *p,
CompObject *o)
{
- static InitPluginObjectProc dispTab[] = {
- (InitPluginObjectProc) 0, /* InitCore */
- (InitPluginObjectProc) snowglobeInitDisplay,
- (InitPluginObjectProc) snowglobeInitScreen
- };
+ static InitPluginObjectProc dispTab[] = {
+ (InitPluginObjectProc) 0, /* InitCore */
+ (InitPluginObjectProc) snowglobeInitDisplay,
+ (InitPluginObjectProc) snowglobeInitScreen
+ };
- RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
+ RETURN_DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), TRUE, (p, o));
}
static void
snowglobeFiniObject (CompPlugin *p,
CompObject *o)
{
- static FiniPluginObjectProc dispTab[] = {
- (FiniPluginObjectProc) 0, /* FiniCore */
- (FiniPluginObjectProc) snowglobeFiniDisplay,
- (FiniPluginObjectProc) snowglobeFiniScreen
- };
+ static FiniPluginObjectProc dispTab[] = {
+ (FiniPluginObjectProc) 0, /* FiniCore */
+ (FiniPluginObjectProc) snowglobeFiniDisplay,
+ (FiniPluginObjectProc) snowglobeFiniScreen
+ };
- DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
+ DISPATCH (o, dispTab, ARRAY_SIZE (dispTab), (p, o));
}
CompPluginVTable snowglobeVTable = {
@@ -550,5 +548,5 @@ CompPluginVTable snowglobeVTable = {
CompPluginVTable *
getCompPluginInfo (void)
{
- return &snowglobeVTable;
+ return &snowglobeVTable;
}
diff --git a/snowglobe.xml.in b/snowglobe.xml.in
index f0e9973..767af31 100644
--- a/snowglobe.xml.in
+++ b/snowglobe.xml.in
@@ -7,6 +7,8 @@
<deps>
<relation type="after">
<plugin>cube</plugin>
+ <plugin>rotate</plugin>
+ <plugin>mswitch</plugin>
</relation>
<requirement>
<plugin>cube</plugin>
@@ -15,7 +17,7 @@
<screen>
<option name="speed_factor" type="float">
<short>Speed factor</short>
- <long>Multiply the speed of the fish by this factor.</long>
+ <long>Multiply the speed of the snowflakes by this factor.</long>
<default>1</default>
<min>0.5</min>
<max>10</max>
@@ -49,6 +51,11 @@
<max>1</max>
<precision>0.01</precision>
</option>
+ <option name="shake_cube" type="bool">
+ <short>Interaction</short>
+ <long>Snowflakes fall according to cube orientation.</long>
+ <default>true</default>
+ </option>
<group>
<short>Water / Ground</short>
<option name="show_water" type="bool">
diff --git a/util.c b/util.c
index ddba2b3..d38c331 100644
--- a/util.c
+++ b/util.c
@@ -5,17 +5,27 @@
#include <float.h>
-
-float randf (float x) { //return random number in range [0,x)
- return rand()/(((double)RAND_MAX + 1) / x);
+float
+randf (float x)
+{ //return random number in range [0,x)
+ return rand()/(((double)RAND_MAX + 1) / x);
}
-float minimum (float x, float y) {
- return ((x) < (y) ? (x) : (y));
+
+float
+minimum (float x, float y)
+{
+ return ((x) < (y) ? (x) : (y));
}
-float maximum (float x, float y) {
- return ((x) > (y) ? (x) : (y));
+
+float
+maximum (float x, float y)
+{
+ return ((x) > (y) ? (x) : (y));
}
-float symmDistr() { //returns number in range [-1, 1] with bias towards 0, symmetric about 0.
- float x = 2*randf(1)-1;
- return x*(1-cbrt(1-fabsf(x)));
+
+float
+symmDistr()
+{ //returns number in range [-1, 1] with bias towards 0, symmetric about 0.
+ float x = 2*randf(1)-1;
+ return x*(1-cbrt(1-fabsf(x)));
}