summaryrefslogtreecommitdiffstats
path: root/libs/rs/java/Balls
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-12-08 16:14:36 -0800
committerJason Sams <rjsams@android.com>2010-12-08 16:14:36 -0800
commit5476b450e50939940dcf3f15c92335cee2fc572d (patch)
tree2129f5a5abfdfa6d43ae3e884d759d4614604c41 /libs/rs/java/Balls
parentaf8962e48ecf0ff3833084f540ca7e2f05295560 (diff)
downloadframeworks_base-5476b450e50939940dcf3f15c92335cee2fc572d.zip
frameworks_base-5476b450e50939940dcf3f15c92335cee2fc572d.tar.gz
frameworks_base-5476b450e50939940dcf3f15c92335cee2fc572d.tar.bz2
Allocation API update.
Change-Id: I9b4a71f9e94c7d3978f06b7971051ab4f8472503
Diffstat (limited to 'libs/rs/java/Balls')
-rw-r--r--libs/rs/java/Balls/src/com/android/balls/BallsRS.java4
-rw-r--r--libs/rs/java/Balls/src/com/android/balls/ball_physics.rs113
-rw-r--r--libs/rs/java/Balls/src/com/android/balls/balls.rs23
-rw-r--r--libs/rs/java/Balls/src/com/android/balls/balls.rsh7
4 files changed, 89 insertions, 58 deletions
diff --git a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
index 83b755f..897b231 100644
--- a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
+++ b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
@@ -21,7 +21,7 @@ import android.renderscript.*;
import android.util.Log;
public class BallsRS {
- public static final int PART_COUNT = 1000;
+ public static final int PART_COUNT = 900;
public BallsRS() {
}
@@ -55,7 +55,7 @@ public class BallsRS {
" vec4 pos = vec4(0.0, 0.0, 0.0, 1.0);\n" +
" pos.xy = ATTRIB_position;\n" +
" gl_Position = UNI_MVP * pos;\n" +
- " varColor = ATTRIB_color;\n" +
+ " varColor = vec4(1.0, 1.0, 1.0, 1.0);\n" +
" gl_PointSize = ATTRIB_size;\n" +
"}\n";
sb.setShader(t);
diff --git a/libs/rs/java/Balls/src/com/android/balls/ball_physics.rs b/libs/rs/java/Balls/src/com/android/balls/ball_physics.rs
index 47eaf1b..7c86c67 100644
--- a/libs/rs/java/Balls/src/com/android/balls/ball_physics.rs
+++ b/libs/rs/java/Balls/src/com/android/balls/ball_physics.rs
@@ -30,17 +30,21 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
float2 vec2 = vec * vec;
float len2 = vec2.x + vec2.y;
- if (len2 < 1000) {
- if (len2 > (4*4)) {
+ if (len2 < 10000) {
+ //float minDist = ballIn->size + bPtr[xin].size;
+ float forceScale = ballIn->size * bPtr[xin].size;
+ forceScale *= forceScale;
+
+ if (len2 > 16 /* (minDist*minDist)*/) {
// Repulsion
float len = sqrt(len2);
- if (len < arcInvStr) {
- arcInvStr = len;
- arcID = xin;
- }
- fv -= (vec / (len * len * len)) * 20000.f;
+ //if (len < arcInvStr) {
+ //arcInvStr = len;
+ //arcID = xin;
+ //}
+ fv -= (vec / (len * len * len)) * 20000.f * forceScale;
} else {
- if (len2 < 0.1) {
+ if (len2 < 1) {
if (xin == x) {
continue;
}
@@ -51,9 +55,9 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
} else {
ballOut->position.x -= 1.f;
}
- ballOut->color.rgb = 1.f;
- ballOut->arcID = -1;
- ballOut->arcStr = 0;
+ //ballOut->color.rgb = 1.f;
+ //ballOut->arcID = -1;
+ //ballOut->arcStr = 0;
return;
}
// Collision
@@ -70,57 +74,76 @@ void root(const Ball_t *ballIn, Ball_t *ballOut, const BallControl_t *ctl, uint3
}
}
- fv -= gGravityVector;
+ fv /= ballIn->size * ballIn->size * ballIn->size;
+ fv -= gGravityVector * 4.f;
fv *= ctl->dt;
- {
+ if (touchPressure > 0.1f) {
float2 tp = {touchX, touchY};
float2 vec = tp - ballIn->position;
float2 vec2 = vec * vec;
- float len2 = vec2.x + vec2.y;
-
- if (len2 > 0.2) {
- float len = sqrt(len2);
- fv -= (vec / (len * len)) * touchPressure * 1000.f;
- }
+ float len2 = max(2.f, vec2.x + vec2.y);
+ fv -= (vec / len2) * touchPressure * 400.f;
}
- ballOut->delta = ballIn->delta * 0.998f;
- ballOut->position = ballIn->position;
-
- ballOut->delta += fv;
- ballOut->position += ballOut->delta * ctl->dt;
+ ballOut->delta = (ballIn->delta * (1.f - 0.004f)) + fv;
+ ballOut->position = ballIn->position + (ballOut->delta * ctl->dt);
- if (ballOut->position.x > gMaxPos.x) {
- if (ballOut->delta.x > 0) {
- ballOut->delta.x *= -0.7;
+ const float wallForce = 400.f;
+ if (ballOut->position.x > (gMaxPos.x - 20.f)) {
+ float d = gMaxPos.x - ballOut->position.x;
+ if (d < 0.f) {
+ if (ballOut->delta.x > 0) {
+ ballOut->delta.x *= -0.7;
+ }
+ ballOut->position.x = gMaxPos.x;
+ } else {
+ ballOut->delta.x -= min(wallForce / (d * d), 10.f);
}
- ballOut->position.x = gMaxPos.x;
}
- if (ballOut->position.y > gMaxPos.y) {
- if (ballOut->delta.y > 0) {
- ballOut->delta.y *= -0.7;
+
+ if (ballOut->position.x < (gMinPos.x + 20.f)) {
+ float d = ballOut->position.x - gMinPos.x;
+ if (d < 0.f) {
+ if (ballOut->delta.x < 0) {
+ ballOut->delta.x *= -0.7;
+ }
+ ballOut->position.x = gMinPos.x + 1.f;
+ } else {
+ ballOut->delta.x += min(wallForce / (d * d), 10.f);
}
- ballOut->position.y = gMaxPos.y - 1.f;
}
- if (ballOut->position.x < gMinPos.x) {
- if (ballOut->delta.x < 0) {
- ballOut->delta.x *= -0.7;
+
+ if (ballOut->position.y > (gMaxPos.y - 20.f)) {
+ float d = gMaxPos.y - ballOut->position.y;
+ if (d < 0.f) {
+ if (ballOut->delta.y > 0) {
+ ballOut->delta.y *= -0.7;
+ }
+ ballOut->position.y = gMaxPos.y;
+ } else {
+ ballOut->delta.y -= min(wallForce / (d * d), 10.f);
}
- ballOut->position.x = gMinPos.x + 1.f;
}
- if (ballOut->position.y < gMinPos.y) {
- if (ballOut->delta.y < 0) {
- ballOut->delta.y *= -0.7;
+
+ if (ballOut->position.y < (gMinPos.y + 20.f)) {
+ float d = ballOut->position.y - gMinPos.y;
+ if (d < 0.f) {
+ if (ballOut->delta.y < 0) {
+ ballOut->delta.y *= -0.7;
+ }
+ ballOut->position.y = gMinPos.y + 1.f;
+ } else {
+ ballOut->delta.y += min(wallForce / (d * d * d), 10.f);
}
- ballOut->position.y = gMinPos.y + 1.f;
}
- ballOut->color.b = 1.f;
- ballOut->color.r = min(sqrt(length(ballOut->delta)) * 0.1f, 1.f);
- ballOut->color.g = min(sqrt(length(fv) * 0.1f), 1.f);
- ballOut->arcID = arcID;
- ballOut->arcStr = 8 / arcInvStr;
+ //ballOut->color.b = 1.f;
+ //ballOut->color.r = min(sqrt(length(ballOut->delta)) * 0.1f, 1.f);
+ //ballOut->color.g = min(sqrt(length(fv) * 0.1f), 1.f);
+ //ballOut->arcID = arcID;
+ //ballOut->arcStr = 8 / arcInvStr;
+ ballOut->size = ballIn->size;
//rsDebug("physics pos out", ballOut->position);
}
diff --git a/libs/rs/java/Balls/src/com/android/balls/balls.rs b/libs/rs/java/Balls/src/com/android/balls/balls.rs
index 9fd4722..c41ed0f 100644
--- a/libs/rs/java/Balls/src/com/android/balls/balls.rs
+++ b/libs/rs/java/Balls/src/com/android/balls/balls.rs
@@ -14,7 +14,7 @@ rs_mesh arcMesh;
typedef struct __attribute__((packed, aligned(4))) Point {
float2 position;
- uchar4 color;
+ //uchar4 color;
float size;
} Point_t;
Point_t *point;
@@ -42,8 +42,14 @@ void initParts(int w, int h)
balls1[ct].position.y = rsRand(0.f, (float)h);
balls1[ct].delta.x = 0.f;
balls1[ct].delta.y = 0.f;
- balls1[ct].arcID = -1;
- balls1[ct].color = 0.f;
+ //balls1[ct].arcID = -1;
+ //balls1[ct].color = 0.f;
+ balls1[ct].size = 1.f;
+
+ float r = rsRand(100.f);
+ if (r > 90.f) {
+ balls1[ct].size += pow(10.f, rsRand(0.f, 2.f)) * 0.07;
+ }
}
}
@@ -73,9 +79,9 @@ int root() {
uint32_t arcIdx = 0;
for (uint32_t ct=0; ct < bc.dimX; ct++) {
point[ct].position = bout[ct].position;
- point[ct].color = rsPackColorTo8888(bout[ct].color);
- point[ct].size = 6.f + bout[ct].color.g * 6.f;
-
+ ///point[ct].color = 0xff;//rsPackColorTo8888(bout[ct].color);
+ point[ct].size = 6.f /*+ bout[ct].color.g * 6.f*/ * bout[ct].size;
+/*
if (bout[ct].arcID >= 0) {
arc[arcIdx].position = bout[ct].position;
arc[arcIdx].color.r = min(bout[ct].arcStr, 1.f) * 0xff;
@@ -86,11 +92,12 @@ int root() {
arc[arcIdx+1].color = arc[arcIdx].color;
arcIdx += 2;
}
+ */
}
frame++;
- rsgBindProgramFragment(gPFLines);
- rsgDrawMesh(arcMesh, 0, 0, arcIdx);
+ //rsgBindProgramFragment(gPFLines);
+ //rsgDrawMesh(arcMesh, 0, 0, arcIdx);
rsgBindProgramFragment(gPFPoints);
rsgDrawMesh(partMesh);
rsClearObject(&bc.ain);
diff --git a/libs/rs/java/Balls/src/com/android/balls/balls.rsh b/libs/rs/java/Balls/src/com/android/balls/balls.rsh
index ed3c31a..fc886f9 100644
--- a/libs/rs/java/Balls/src/com/android/balls/balls.rsh
+++ b/libs/rs/java/Balls/src/com/android/balls/balls.rsh
@@ -2,9 +2,10 @@
typedef struct __attribute__((packed, aligned(4))) Ball {
float2 delta;
float2 position;
- float3 color;
- int arcID;
- float arcStr;
+ //float3 color;
+ float size;
+ //int arcID;
+ //float arcStr;
} Ball_t;
Ball_t *balls;