blob: 9d3f30b822b3c3bce8867e30c3aa15ca367fb4d3 [file] [log] [blame]
Jason Sams177f8442010-10-29 10:19:21 -07001#pragma version(1)
2#pragma rs java_package_name(com.android.balls)
3#include "rs_graphics.rsh"
4
5#include "balls.rsh"
6
7#pragma stateFragment(parent)
8
9rs_program_fragment gPF;
10rs_program_vertex gPV;
11rs_program_raster gPR;
12rs_program_store gPS;
13rs_mesh partMesh;
14rs_mesh arcMesh;
15
16typedef struct __attribute__((packed, aligned(4))) Point {
17 float2 position;
18 uchar4 color;
19 float size;
20} Point_t;
21Point_t *point;
22Point_t *arc;
23
24typedef struct VpConsts {
25 //rs_matrix4x4 Proj;
26 rs_matrix4x4 MVP;
27} VpConsts_t;
28VpConsts_t *vpConstants;
29
30
31#pragma rs export_func(initParts)
32
33rs_script physics_script;
34
35Ball_t *balls1;
36Ball_t *balls2;
37
38static int frame = 0;
39
40void initParts(int w, int h)
41{
42 uint32_t dimX = rsAllocationGetDimX(rsGetAllocation(balls1));
43
44 for (uint32_t ct=0; ct < dimX; ct++) {
45 balls1[ct].position.x = rsRand(0.f, (float)w);
46 balls1[ct].position.y = rsRand(0.f, (float)h);
47 balls1[ct].delta.x = 0.f;
48 balls1[ct].delta.y = 0.f;
49 balls1[ct].arcID = -1;
50 balls1[ct].color = 0.f;
51 }
52}
53
54
55
56int root() {
57 rsgClearColor(0.f, 0.f, 0.f, 1.f);
58
59 BallControl_t bc;
60 Ball_t *bout;
61
62 if (frame & 1) {
63 bc.ain = rsGetAllocation(balls2);
64 bc.aout = rsGetAllocation(balls1);
65 bout = balls2;
66 } else {
67 bc.ain = rsGetAllocation(balls1);
68 bc.aout = rsGetAllocation(balls2);
69 bout = balls1;
70 }
71
72 bc.dimX = rsAllocationGetDimX(bc.ain);
73 bc.dt = 1.f / 30.f;
74
75 rsForEach(physics_script, bc.ain, bc.aout, &bc);
76
77 uint32_t arcIdx = 0;
78 for (uint32_t ct=0; ct < bc.dimX; ct++) {
79 point[ct].position = bout[ct].position;
80 point[ct].color = rsPackColorTo8888(bout[ct].color);
81 point[ct].size = 6.f + bout[ct].color.g * 6.f;
82
83 if (bout[ct].arcID >= 0) {
84 arc[arcIdx].position = bout[ct].position;
85 arc[arcIdx].color.r = min(bout[ct].arcStr, 1.f) * 0xff;
86 arc[arcIdx].color.g = 0;
87 arc[arcIdx].color.b = 0;
88 arc[arcIdx].color.a = 0xff;
89 arc[arcIdx+1].position = bout[bout[ct].arcID].position;
90 arc[arcIdx+1].color = arc[arcIdx].color;
91 arcIdx += 2;
92 }
93 }
94
95 frame++;
96 rsgBindProgramFragment(gPF);
97 rsgBindProgramVertex(gPV);
98 rsgBindProgramRaster(gPR);
99 rsgBindProgramStore(gPS);
100 rsgDrawMesh(arcMesh, 0, 0, arcIdx);
101 rsgDrawMesh(partMesh);
102 return 1;
103}
104