// The higher, the smaller the ripple
#define RIPPLE_HEIGHT 10.0f
-float g_SkyOffsetX;
-float g_SkyOffsetY;
+float skyOffsetX;
+float skyOffsetY;
struct vert_s {
float nx;
}
}
-float averageZ(float x1, float x2, float y1, float y2, float* vertices,
- int meshWidth, int meshHeight, float glWidth, float glHeight) {
-
- x1 = ((x1 + glWidth * 0.5f) / glWidth) * meshWidth;
- x2 = ((x2 + glWidth * 0.5f) / glWidth) * meshWidth;
- y1 = ((y1 + glHeight * 0.5f) / glHeight) * meshHeight;
- y2 = ((y2 + glHeight * 0.5f) / glHeight) * meshHeight;
-
- int quadX1 = clamp(x1, 0, meshWidth);
- int quadX2 = clamp(x2, 0, meshWidth);
- int quadY1 = clamp(y1, 0, meshHeight);
- int quadY2 = clamp(y2, 0, meshHeight);
-
- float z = 0.0f;
- int vertexCount = 0;
-
- int y = quadY1;
- for ( ; y < quadY2; y += 1) {
- int x = quadX1;
- int yOffset = y * meshWidth;
- for ( ; x < quadX2; x += 1) {
- z += vertices[(yOffset + x) << 3 + 7];
- vertexCount += 1;
- }
- }
-
- return 55.0f * z / vertexCount;
-}
-
void drawLeaf(int index, float* vertices, int meshWidth, int meshHeight,
float glWidth, float glHeight) {
float tz = 0.0f;
if (a > 0.0f) {
tz = -a;
- } else {
-// z1 = averageZ(x1, x, y1, y, vertices, meshWidth, meshHeight, glWidth, glHeight);
-// z2 = averageZ(x, x2, y1, y, vertices, meshWidth, meshHeight, glWidth, glHeight);
-// z3 = averageZ(x, x2, y, y2, vertices, meshWidth, meshHeight, glWidth, glHeight);
-// z4 = averageZ(x1, x, y, y2, vertices, meshWidth, meshHeight, glWidth, glHeight);
}
x1 -= x;
bindProgramFragmentStore(NAMED_PFSLeaf);
bindTexture(NAMED_PFSky, 0, NAMED_TSky);
- float x = g_SkyOffsetX + State->skySpeedX;
- float y = g_SkyOffsetY + State->skySpeedY;
+ float x = skyOffsetX + State->skySpeedX;
+ float y = skyOffsetY + State->skySpeedY;
if (x > 1.0f) x = 0.0f;
if (x < -1.0f) x = 0.0f;
if (y > 1.0f) y = 0.0f;
- g_SkyOffsetX = x;
- g_SkyOffsetY = y;
+ skyOffsetX = x;
+ skyOffsetY = y;
float matrix[16];
matrixLoadTranslate(matrix, x, y, 0.0f);
package com.android.wallpaper.fall;
-import android.renderscript.RenderScript;
import android.renderscript.ScriptC;
import android.renderscript.ProgramFragment;
import android.renderscript.ProgramStore;
import android.renderscript.ProgramVertex;
import android.renderscript.Allocation;
import android.renderscript.Sampler;
-import android.renderscript.Element;
import android.renderscript.Light;
import android.renderscript.Type;
import android.renderscript.SimpleMesh;
mWorldState.width = width;
mWorldState.height = height;
+ mWorldState.rotate = 1;
mState.data(mWorldState);
- mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
-
- // TODO: Resize everything else, including the mesh and glHeight
+ mPvOrthoAlloc.setupOrthoWindow(width, height);
}
@Override
public float glHeight;
public float skySpeedX;
public float skySpeedY;
+ public int rotate;
}
static class DropState {
mWorldState.glHeight = mGlHeight;
mWorldState.skySpeedX = random(-0.001f, 0.001f);
mWorldState.skySpeedY = random(0.00008f, 0.0002f);
+ mWorldState.rotate = mWidth > mHeight ? 1 : 0;
mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
mState = Allocation.createTyped(mRS, mStateType);
private int mTriangles;
private final float[] mFloatData5 = new float[5];
private WorldState mWorldState;
+ private float[] mBladesData;
GrassRS(int width, int height) {
super(width, height);
mWorldState.height = height;
mState.data(mWorldState);
- mPvOrthoAlloc.setupOrthoWindow(mWidth, mHeight);
+ final float[] blades = mBladesData;
+ for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) {
+ updateBlade(blades, i);
+ }
+ mBlades.data(blades);
- // TODO: REPOSITION BLADES
+ mPvOrthoAlloc.setupOrthoWindow(width, height);
}
@Override
private void createBlades() {
int triangles = 0;
- final float[] blades = new float[BLADES_COUNT * BLADE_STRUCT_FIELDS_COUNT];
+ mBladesData = new float[BLADES_COUNT * BLADE_STRUCT_FIELDS_COUNT];
+
+ final float[] blades = mBladesData;
for (int i = 0; i < blades.length; i+= BLADE_STRUCT_FIELDS_COUNT) {
triangles += createBlade(blades, i);
}
}
}
+ private void updateBlade(float[] blades, int index) {
+ final int xpos = random(-mWidth, mWidth);
+ blades[index + BLADE_STRUCT_XPOS] = xpos;
+ blades[index + BLADE_STRUCT_TURBULENCEX] = xpos * 0.006f;
+ blades[index + BLADE_STRUCT_YPOS] = mHeight;
+ }
+
private int createBlade(float[] blades, int index) {
final float size = random(4.0f) + 4.0f;
final int xpos = random(-mWidth, mWidth);