diff options
author | David Mikos <metastability@opencompositing.org> | 2008-01-27 12:52:18 +1030 |
---|---|---|
committer | David Mikos <metastability@opencompositing.org> | 2008-01-27 12:52:18 +1030 |
commit | 03c9bfdc9b7de73032420b5968eaff69976b38da (patch) | |
tree | f6fb87b373152394814c81c9521e39427782555a | |
parent | 5d7953fd9aa3dc84e06975492daf1bc351216ebf (diff) | |
download | snowglobe-03c9bfdc9b7de73032420b5968eaff69976b38da.tar.gz snowglobe-03c9bfdc9b7de73032420b5968eaff69976b38da.tar.bz2 |
Possibly work better with multiple monitors. Remove global variables.
-rw-r--r-- | movement.c | 31 | ||||
-rw-r--r-- | snowglobe-internal.h | 34 | ||||
-rw-r--r-- | snowglobe.c | 31 | ||||
-rw-r--r-- | util.c | 7 |
4 files changed, 44 insertions, 59 deletions
@@ -16,11 +16,12 @@ SnowflakeTransform (snowflakeRec * snow) 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; + int sector = NRAND(as->hsize); + float ang = randf(as->arcAngle*toRadians)-0.5*as->arcAngle*toRadians; + float r = (as->radius-0.01*as->snow[i].size/2); + float factor = sinf(0.5*(PI-as->arcAngle*toRadians))/ + sinf(0.5*(PI-as->arcAngle*toRadians)+fabsf(ang)); + ang += (0.5+((float) sector))*as->arcAngle*toRadians; ang = fmodf(ang,2*PI); float d = randf(1); @@ -47,7 +48,7 @@ SnowflakeDrift (CompScreen *s, int index) snowflakeRec * snow = &(as->snow[index]); - float speed = snow->speed*speedFactor; + float speed = snow->speed*as->speedFactor; speed/=1000; float x = snow->x; float y = snow->y; @@ -75,7 +76,7 @@ SnowflakeDrift (CompScreen *s, int index) } - float bottom = (renderGround ? getHeight(as->ground, x, y) : -0.5)+0.01*snow->size/2; + float bottom = (snowglobeGetShowGround(s) ? getHeight(as->ground, x, y) : -0.5)+0.01*snow->size/2; if (z<bottom) { @@ -93,22 +94,22 @@ SnowflakeDrift (CompScreen *s, int index) } - float ang = atan2(y, x); + float ang = atan2f(y, x); int i; - for (i=0; i<hSize; i++) + for (i=0; i< as->hsize; i++) { - float cosAng = cosf(fmodf(2*i*PI/q-ang, 2*PI)); + float cosAng = cosf(fmodf(i*as->arcAngle*toRadians-ang, 2*PI)); if (cosAng<=0) continue; float r = hypotf(x, y); - float d = r*cosAng-(distance-0.01*snow->size/2); + float d = r*cosAng-(as->distance-0.01*snow->size/2); if (d>0) { - x -= d*cosf(ang)*fabsf(cosf(2*i*PI/q)); - y -= d*sinf(ang)*fabsf(sinf(2*i*PI/q)); + x -= d*cosf(ang)*fabsf(cosf(i*as->arcAngle*toRadians)); + y -= d*sinf(ang)*fabsf(sinf(i*as->arcAngle*toRadians)); } } @@ -116,6 +117,6 @@ SnowflakeDrift (CompScreen *s, int index) 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->psi = fmodf(snow->psi+snow->dpsi*as->speedFactor, 360); + snow->theta= fmodf(snow->theta+snow->dtheta*as->speedFactor, 360); } diff --git a/snowglobe-internal.h b/snowglobe-internal.h index ca96829..4db8748 100644 --- a/snowglobe-internal.h +++ b/snowglobe-internal.h @@ -104,10 +104,19 @@ typedef struct _SnowglobeScreen Water *water; Water *ground; - GLuint snowflakeDisplayList; - float xRotate; float vRotate; + + float waterHeight; //water surface height + + int hsize; + float distance; //perpendicular distance to wall from centre + float radius; //radius on which the hSize points lie + float arcAngle; //360 degrees / horizontal size + + float speedFactor; // multiply snowflake speeds by this value + + GLuint snowflakeDisplayList; } SnowglobeScreen; @@ -144,7 +153,7 @@ void SnowflakeTransform(snowflakeRec *); void newSnowflakePosition(SnowglobeScreen *, int); void SnowflakeDrift (CompScreen *, int); -void initializeWorldVariables(int, float); +void initializeWorldVariables(CompScreen *); void updateSpeedFactor(float); void RenderWater(int, float, Bool, Bool); @@ -160,28 +169,9 @@ float minimum(float,float); //my compiler at home didn't have min or fminf! float maximum(float,float); //nor did it have max or fmaxf! float symmDistr(void); //symmetric distribution -//maybe define a struct for these values -float speedFactor; // global variable (fish/crab speeds multiplied by this value) -float radius;//radius on which the hSize points lie -float distance;//perpendicular distance to wall from centre -float waterHeight; //water surface height -int waveGridSize; -float waveAmplitude; -float waveFrequency; -float smallWaveAmplitude; -float smallWaveFrequency; -Bool renderGround; - - - //All calculations that matter with angles are done clockwise from top. //I think of it as x=radius, y=0 being the top (towards 1st desktop from above view) //and the z coordinate as height. - -int hSize; // horizontal desktop size -float q; // equal to float version of hSize (replace with hSizef some time) - - #endif diff --git a/snowglobe.c b/snowglobe.c index 873eb2a..442a26b 100644 --- a/snowglobe.c +++ b/snowglobe.c @@ -86,7 +86,6 @@ initSnowglobe (CompScreen *s) { SNOWGLOBE_SCREEN (s); - CUBE_SCREEN (s); as->water = NULL; as->ground = NULL; @@ -95,7 +94,7 @@ initSnowglobe (CompScreen *s) as->snow = calloc(as->numSnowflakes, sizeof(snowflakeRec)); - initializeWorldVariables(s->hsize, cs->distance); + initializeWorldVariables(s); int i; for (i=0; i< as->numSnowflakes; i++) @@ -115,9 +114,7 @@ initSnowglobe (CompScreen *s) } - waterHeight = 50000; - - speedFactor = snowglobeGetSpeedFactor(s); + as->waterHeight = 50000; as->snowflakeDisplayList = glGenLists(1); glNewList(as->snowflakeDisplayList, GL_COMPILE); @@ -126,14 +123,18 @@ initSnowglobe (CompScreen *s) } void -initializeWorldVariables(int hs, float perpDistCentreToWall) -{ //precalculate some values +initializeWorldVariables(CompScreen *s) +{ + SNOWGLOBE_SCREEN (s); + CUBE_SCREEN (s); + + as->speedFactor = snowglobeGetSpeedFactor(s); - hSize = hs; - q = (float) hSize; + as->hsize = s->hsize * cs->nOutput; - distance = perpDistCentreToWall; - radius = perpDistCentreToWall/sin(PI*(0.5-1/q)); + as->arcAngle = 360.0f / as->hsize; + as->radius = cs->distance/sinf(0.5*(PI-as->arcAngle*toRadians)); + as->distance = cs->distance; } static void @@ -168,7 +169,8 @@ snowglobeSpeedFactorOptionChange (CompScreen *s, CompOption *opt, SnowglobeScreenOptions num) { - speedFactor = snowglobeGetSpeedFactor(s); + SNOWGLOBE_SCREEN (s); + as->speedFactor = snowglobeGetSpeedFactor(s); } static void @@ -199,9 +201,9 @@ snowglobePaintInside (CompScreen *s, int i; - waterHeight = 50000; + as->waterHeight = 50000; - if (hSize!=s->hsize) updateSnowglobe (s); + if (as->hsize!=s->hsize) updateSnowglobe (s); static const float mat_shininess[] = { 60.0 }; @@ -357,7 +359,6 @@ snowglobePreparePaintScreen (CompScreen *s, { SNOWGLOBE_SCREEN (s); - renderGround = snowglobeGetShowGround(s); int i; for (i = 0; i < as->numSnowflakes; i++) @@ -22,10 +22,3 @@ 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))); -} |