Loading libs/rs/java/Fountain/res/raw/fountain.rs +13 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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++; Loading @@ -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}; Loading @@ -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++; Loading libs/rs/java/Fountain/res/raw/fountain_bc.bc −336 B (2.14 KiB) File changed.No diff preview for this file type. View original file View changed file libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +21 −37 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); } } libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading
libs/rs/java/Fountain/res/raw/fountain.rs +13 −11 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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++; Loading @@ -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}; Loading @@ -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++; Loading
libs/rs/java/Fountain/res/raw/fountain_bc.bc −336 B (2.14 KiB) File changed.No diff preview for this file type. View original file View changed file
libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java +21 −37 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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); } }
libs/rs/java/Fountain/src/com/android/fountain/ScriptField_Point.java +1 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading