diff --git a/libs/rs/java/Fountain/res/raw/fountain.rs b/libs/rs/java/Fountain/res/raw/fountain.rs index 8b6994178e939..67f7ef51c9006 100644 --- a/libs/rs/java/Fountain/res/raw/fountain.rs +++ b/libs/rs/java/Fountain/res/raw/fountain.rs @@ -12,8 +12,8 @@ rs_mesh partMesh; typedef struct __attribute__((packed, aligned(4))) Point_s { float2 delta; - rs_position2 pos; - rs_color4u color; + float2 position; + uchar4 color; } Point_t; Point_t *point; @@ -28,8 +28,8 @@ int root() { Point_t * p = point; for (int ct=0; ct < size; ct++) { p->delta.y += 0.15f; - p->pos += p->delta; - if ((p->pos.y > height) && (p->delta.y > 0)) { + p->position += p->delta; + if ((p->position.y > height) && (p->delta.y > 0)) { p->delta.y *= -0.3f; } p++; @@ -42,16 +42,18 @@ int root() { void addParticles(int rate, int x, int y) { - rsDebug("partColor", partColor); - rsDebug("partColor x", partColor.x); - rsDebug("partColor y", partColor.y); - rsDebug("partColor z", partColor.z); - rsDebug("partColor w", partColor.w); + //rsDebug("partColor", partColor); + //rsDebug("partColor x", partColor.x); + //rsDebug("partColor y", partColor.y); + //rsDebug("partColor z", partColor.z); + //rsDebug("partColor w", partColor.w); float rMax = ((float)rate) * 0.005f; int size = rsAllocationGetDimX(rsGetAllocation(point)); - rs_color4u c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z); + uchar4 c = rsPackColorTo8888(partColor.x, partColor.y, partColor.z); + + //rsDebug("color ", ((int *)&c)[0]); Point_t * np = &point[newPart]; float2 p = {x, y}; @@ -60,7 +62,7 @@ void addParticles(int rate, int x, int y) float len = rsRand(rMax); np->delta.x = len * sin(angle); np->delta.y = len * cos(angle); - np->pos = p; + np->position = p; np->color = c; newPart++; np++; diff --git a/libs/rs/java/Fountain/res/raw/fountain_bc.bc b/libs/rs/java/Fountain/res/raw/fountain_bc.bc index 45475faf662e4..7b2e88bef8f82 100644 Binary files a/libs/rs/java/Fountain/res/raw/fountain_bc.bc and b/libs/rs/java/Fountain/res/raw/fountain_bc.bc differ diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java index ba09a161217a6..6f601344c55fb 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java @@ -27,26 +27,36 @@ public class FountainRS { public FountainRS() { } + private Resources mRes; + private RenderScriptGL mRS; + private ScriptC_Fountain mScript; public void init(RenderScriptGL rs, Resources res, int width, int height) { mRS = rs; mRes = res; - initRS(); + + ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT); + + SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); + int vtxSlot = smb.addVertexType(points.getType()); + smb.setPrimitive(Primitive.POINT); + SimpleMesh sm = smb.create(); + sm.bindVertexAllocation(points.getAllocation(), vtxSlot); + + mScript = new ScriptC_Fountain(mRS, mRes, true); + mScript.set_partMesh(sm); + mScript.bind_point(points); + mRS.contextBindRootScript(mScript); } Float4 tmpColor = new Float4(); boolean holdingColor = false; + java.util.Random mRand = new java.util.Random(); public void newTouchPosition(int x, int y, int rate) { if (rate > 0) { - if (true/*!holdingColor*/) { - tmpColor.x = ((x & 0x1) != 0) ? 0.f : 1.f; - tmpColor.y = ((x & 0x2) != 0) ? 0.f : 1.f; - tmpColor.z = ((x & 0x4) != 0) ? 0.f : 1.f; - if ((tmpColor.x + tmpColor.y + tmpColor.z) < 0.9f) { - tmpColor.x = 0.8f; - tmpColor.y = 0.5f; - tmpColor.z = 1.0f; - } - android.util.Log.e("rs", "set color " + tmpColor.x + ", " + tmpColor.y + ", " + tmpColor.z); + if (!holdingColor) { + tmpColor.x = mRand.nextFloat() * 0.5f + 0.5f; + tmpColor.y = mRand.nextFloat(); + tmpColor.z = mRand.nextFloat(); mScript.set_partColor(tmpColor); } mScript.invokable_addParticles(rate, x, y); @@ -56,32 +66,6 @@ public class FountainRS { } } - - - ///////////////////////////////////////// - - private Resources mRes; - - private ScriptField_Point mPoints; - private ScriptC_Fountain mScript; - private RenderScriptGL mRS; - private SimpleMesh mSM; - - private void initRS() { - mPoints = new ScriptField_Point(mRS, PART_COUNT); - - SimpleMesh.Builder smb = new SimpleMesh.Builder(mRS); - int vtxSlot = smb.addVertexType(mPoints.getType()); - smb.setPrimitive(Primitive.POINT); - mSM = smb.create(); - mSM.bindVertexAllocation(mPoints.getAllocation(), vtxSlot); - - mScript = new ScriptC_Fountain(mRS, mRes, true); - mScript.set_partMesh(mSM); - mScript.bind_point(mPoints); - mRS.contextBindRootScript(mScript); - } - } diff --git a/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java index edd18d589d61f..b091f39ec91a7 100644 --- a/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java +++ b/libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java @@ -31,7 +31,7 @@ public class ScriptField_Point Element.Builder eb = new Element.Builder(rs); eb.add(Element.createVector(rs, Element.DataType.FLOAT_32, 2), "delta"); - eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "pos"); + eb.add(Element.createAttrib(rs, Element.DataType.FLOAT_32, Element.DataKind.POSITION, 2), "position"); eb.add(Element.createAttrib(rs, Element.DataType.UNSIGNED_8, Element.DataKind.COLOR, 4), "color"); mElement = eb.create();