diff options
Diffstat (limited to 'src/com/android/galaxy4/galaxy.rs')
-rw-r--r-- | src/com/android/galaxy4/galaxy.rs | 126 |
1 files changed, 67 insertions, 59 deletions
diff --git a/src/com/android/galaxy4/galaxy.rs b/src/com/android/galaxy4/galaxy.rs index 5117024..34f2411 100644 --- a/src/com/android/galaxy4/galaxy.rs +++ b/src/com/android/galaxy4/galaxy.rs @@ -7,38 +7,46 @@ typedef struct __attribute__((packed, aligned(4))) Particle { float3 position; - uchar4 color; + float pointSize; } Particle_t; typedef struct VpConsts { rs_matrix4x4 MVP; + float scaleSize; } VpConsts_t; VpConsts_t *vpConstants; - -// hold clouds Particle_t *spaceClouds; - -// hold bg stars Particle_t *bgStars; +Particle_t *staticStars; rs_mesh spaceCloudsMesh; rs_mesh bgStarsMesh; +rs_mesh staticStarsMesh; rs_program_vertex vertSpaceClouds; rs_program_vertex vertBgStars; +rs_program_vertex vertStaticStars; rs_program_fragment fragSpaceClouds; rs_program_fragment fragBgStars; +rs_program_fragment fragStaticStars; rs_program_vertex vertBg; rs_program_fragment fragBg; rs_allocation textureSpaceCloud; -rs_allocation textureFGStar; +rs_allocation textureStaticStar; +rs_allocation textureStaticStar2; rs_allocation textureBg; -static int gGalaxyRadius = 250; +float densityDPI; + +static int gGalaxyRadius = 300; +static float screenWidth; +static float screenHeight; -float xOffset; +static int numBgStars; +static int numClouds; +static int numStaticStars; #define PI 3.1415f #define TWO_PI 6.283f @@ -65,115 +73,115 @@ static float mapf(float minStart, float minStop, float maxStart, float maxStop, return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart)); } +void positionParticles() { + screenWidth = rsgGetWidth(); + screenHeight = rsgGetHeight(); + float wRatio = 1.0f; + float hRatio = 1.0f; + + if (screenWidth > screenHeight) { + wRatio = screenWidth/screenHeight; + screenHeight = screenWidth; + } else { + hRatio = screenHeight/screenWidth; + screenWidth = screenHeight; + } -void positionParticles(){ - rsDebug("************************&&&&&&&&&&&&&&& Called positionBGStars", rsUptimeMillis()); + float scale = gGalaxyRadius / (screenWidth * 0.5f); - float width = rsgGetWidth(); - float height = rsgGetHeight(); - - float scale = gGalaxyRadius / (width * 0.5f); - - // space clouds + // clouds Particle_t* particle = spaceClouds; - int size = rsAllocationGetDimX(rsGetAllocation(spaceClouds)); - for(int i=0; i<size; i++){ - + numClouds = rsAllocationGetDimX(rsGetAllocation(spaceClouds)); + for (int i=0; i<numClouds; i++) { float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f); - d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d); - float id = d / gGalaxyRadius; float z = randomGauss() * 0.4f * (1.0f - id); - if (d > gGalaxyRadius * 0.15f) { z *= 0.6f * (1.0f - id); } else { z *= 0.72f; } - particle->position.x = rsRand(TWO_PI); particle->position.y = d; + particle->pointSize = 1.0f; particle->position.z = z/5.0f; - particle->color = rsPackColorTo8888(1.0f, 0.0f, 1.0f); particle++; } - + // bg stars - size = rsAllocationGetDimX(rsGetAllocation(bgStars)); + numBgStars = rsAllocationGetDimX(rsGetAllocation(bgStars)); particle = bgStars; - for(int i=0; i<size; i++){ + for (int i=0; i<numBgStars; i++) { float d = fabs(randomGauss()) * gGalaxyRadius * 0.5f + rsRand(64.0f); - d = mapf(-4.0f, gGalaxyRadius + 4.0f, 0.0f, scale, d); - float id = d / gGalaxyRadius; float z = randomGauss() * 0.4f * (1.0f - id); - if (d > gGalaxyRadius * 0.15f) { z *= 0.6f * (1.0f - id); } else { z *= 0.72f; } - particle->position.x = rsRand(TWO_PI); particle->position.y = d; + particle->pointSize = 1.0f; particle->position.z = z/5.0f; - particle->color = rsPackColorTo8888(1.0f, 0.0f, 1.0f); particle++; } - - -} -static void drawBg(int width, int height){ - rsgBindTexture(fragBg, 0, textureBg); - rsgDrawRect(0.0f, 0.0f, width, height, 0.0f); + // static stars + numStaticStars = rsAllocationGetDimX(rsGetAllocation(staticStars)); + particle = staticStars; + for (int i=0; i<numStaticStars; i++) { + particle->position.x = rsRand(-wRatio, wRatio); + particle->position.y = rsRand(-hRatio, hRatio); + particle->pointSize = rsRand(1.0f, 10.0f); + particle++; + } } -int root(){ - float width = rsgGetWidth(); - float height = rsgGetHeight(); - - +int root() { + float xpos = 0.0f; + float ypos = 0.0f; + xpos = -(screenWidth-rsgGetWidth())/2.0f; + ypos = -(screenHeight-rsgGetHeight())/2.0f; + rsgClearColor(0.0f, 0.f, 0.f, 0.5f); - + // bg rsgBindProgramVertex(vertBg); rsgBindProgramFragment(fragBg); - drawBg(width, height); - - + rsgBindTexture(fragBg, 0, textureBg); + rsgDrawRect(xpos, ypos, screenWidth+xpos, screenHeight+ypos, 0.0f); + // space cloud rsgBindProgramVertex(vertSpaceClouds); - int size = rsAllocationGetDimX(rsGetAllocation(spaceClouds)); Particle_t *particle = spaceClouds; - - for(int i=0; i<size; i++){ + for (int i=0; i<numClouds; i++) { particle->position.x -= .065; particle++; } rsgBindProgramFragment(fragSpaceClouds); rsgBindTexture(fragSpaceClouds, 0, textureSpaceCloud); - rsgBindTexture(fragSpaceClouds, 1, textureFGStar); rsgDrawMesh(spaceCloudsMesh); - - - + // bg stars rsgBindProgramVertex(vertBgStars); - size = rsAllocationGetDimX(rsGetAllocation(bgStars)); particle = bgStars; - - for(int i=0; i<size; i++){ + for (int i=0; i<numBgStars; i++) { particle->position.x -= .007; particle++; } rsgBindProgramFragment(fragBgStars); rsgDrawMesh(bgStarsMesh); + // static stars + rsgBindTexture(fragStaticStars, 0, textureStaticStar); + rsgBindTexture(fragStaticStars, 1, textureStaticStar2); + rsgBindProgramVertex(vertStaticStars); + rsgBindProgramFragment(fragStaticStars); + rsgDrawMesh(staticStarsMesh); return 40; -} - +}
\ No newline at end of file |