summaryrefslogtreecommitdiffstats
path: root/src/com/android/phasebeam/phasebeam.rs
blob: 77472ca9b4bd960292e8c1670bddd2089c2fae77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma version(1)

#pragma rs java_package_name(com.android.phasebeam)

#include "rs_graphics.rsh"
#pragma stateVertex(parent);
#pragma stateStore(parent);

rs_allocation textureDot;
rs_allocation textureBeam;

rs_program_vertex vertBg;
rs_program_fragment fragBg;

rs_program_vertex vertDots;
rs_program_fragment fragDots;

static int numBeamParticles;
static int numDotParticles;

typedef struct __attribute__((packed, aligned(4))) Particle {
    float3 position;
    float offsetX;
} Particle_t;

typedef struct VpConsts {
    rs_matrix4x4 MVP;
    float scaleSize;
} VpConsts_t;
VpConsts_t *vpConstants;

typedef struct VertexColor_s {
    float3 position;
    float offsetX;
    float4 color;
} VertexColor;

VertexColor* vertexColors;
Particle_t *dotParticles;
Particle_t *beamParticles;
rs_mesh dotMesh;
rs_mesh beamMesh;
rs_mesh gBackgroundMesh;

float densityDPI;
float xOffset = 0.5;

static float screenWidth;
static float screenHeight;
static float halfScreenWidth;
static float quarterScreenWidth;
static float quarterScreenHeight;
static float halfScreenHeight;

static float newOffset = 0.5;
static float oldOffset = 0.5;

void positionParticles(){
    screenWidth = rsgGetWidth();
    screenHeight = rsgGetHeight();
    halfScreenWidth = screenWidth/2.0f;
    halfScreenHeight = screenHeight/2.0f;
    quarterScreenWidth = screenWidth/4.0f;
    quarterScreenHeight = screenHeight/4.0f;
    Particle_t* particle = dotParticles;
    numDotParticles = rsAllocationGetDimX(rsGetAllocation(dotParticles));
    for(int i=0; i<numDotParticles; i++){


        particle->position.x = rsRand(0.0f, 3.0f);
        particle->position.y = rsRand(-1.25f, 1.25f);

        float z;
        if(i < 3){
            z = 14.0f;
        } if(i < 7){
            z = 25.0f;
        } else if(i < 4){
            z = rsRand(10.f, 20.f);
        } else if(i == 10){
            z = 24.0f;
            particle->position.x = 1.0;
        } else {
            z = rsRand(4.0f, 10.0f);
        }
        particle->position.z = z;
        particle->offsetX = 0;

        particle++;
    }


    Particle_t* beam = beamParticles;
    numBeamParticles = rsAllocationGetDimX(rsGetAllocation(beamParticles));
    for(int i=0; i<numBeamParticles; i++){
        float z;
        if(i < 20){
            z = rsRand(4.0f, 10.0f)/2.0f;
        } else {
            z = rsRand(4.0f, 35.0f)/2.0f;
        }
        beamParticles->position.x = rsRand(-1.25f, 1.25f);
        beamParticles->position.y = rsRand(-1.05f, 1.205f);

        beamParticles->position.z = z;
        beamParticles->offsetX = 0;
        beamParticles++;
    }
}

int root(){

    newOffset = xOffset*2;
    rsgClearColor(0.0f, 0.f, 0.f,1.0f);



    VertexColor* vert = vertexColors;
    for(int i=0; i<48; i++){
        vert->offsetX = -xOffset/2.0;
        vert++;
    }


    rsgBindProgramVertex(vertBg);
    rsgBindProgramFragment(fragBg);

    rsgDrawMesh(gBackgroundMesh);


    Particle_t* beam = beamParticles;
    Particle_t* particle = dotParticles;

    for(int i=0; i<numDotParticles; i++){

        if(newOffset==oldOffset){
            if(beam->position.x/beam->position.z > 0.5){
                beam->position.x = -1.0;
            }
            if(particle->position.x/particle->position.z > 0.5){
                particle->position.x = -1.0;
            }

            if(beam->position.y > 1.05){
                beam->position.y = -1.05;
                beam->position.x = rsRand(-1.25f, 1.25f);
            } else {
                beam->position.y = beam->position.y + 0.000160*beam->position.z;
            }
            if(particle->position.y > 1.25){
                particle->position.y = -1.25;
                particle->position.x = rsRand(0.0f, 3.0f);

            } else {
                particle->position.y = particle->position.y + 0.00022*particle->position.z;
            }


        }




        beam->position.x = beam->position.x + 0.0001010*beam->position.z;
        beam->offsetX = newOffset;
        beam++;
        particle->offsetX = newOffset;
        particle->position.x = particle->position.x + 0.0001560*beam->position.z;
        particle++;
    }



    rsgBindProgramVertex(vertDots);
    rsgBindProgramFragment(fragDots);

    rsgBindTexture(fragDots, 0, textureBeam);
    rsgDrawMesh(beamMesh);

    rsgBindTexture(fragDots, 0, textureDot);
    rsgDrawMesh(dotMesh);

    oldOffset = newOffset;

    return 55;

}