• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2009 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma version(1)
16 #pragma stateVertex(PVBackground)
17 #pragma stateRaster(parent)
18 #pragma stateFragment(PFBackground)
19 
20 #define RSID_POINTS 1
21 
22 #define FADEOUT_LENGTH 100
23 #define FADEOUT_FACTOR 0.95f
24 #define FADEIN_LENGTH 15
25 
26 int fadeoutcounter = 0;
27 int fadeincounter = 0;
28 int wave1pos = 0;
29 int wave1amp = 0;
30 int wave2pos = 0;
31 int wave2amp= 0;
32 int wave3pos = 0;
33 int wave3amp= 0;
34 int wave4pos = 0;
35 int wave4amp= 0;
36 float idle[8192];
37 int waveCounter = 0;
38 
39 void makeIdleWave(float *points) {
40     int i;
41     // show a number of superimposed moving sinewaves
42     float amp1 = sinf(0.007 * wave1amp) * 120;
43     float amp2 = sinf(0.023 * wave2amp) * 80;
44     float amp3 = sinf(0.011 * wave3amp) * 40;
45     float amp4 = sinf(0.031 * wave4amp) * 20;
46     // calculate how many invisible lines there are on each side
47     int skip = (1024 - State->width) / 2;
48     int end = 1024 - skip;
49     for (i = skip; i < end; i++) {
50         float val = sinf(0.013 * (wave1pos + i)) * amp1
51                   + sinf(0.029 * (wave2pos + i)) * amp2;
52         float off = sinf(0.005 * (wave3pos + i)) * amp3
53                   + sinf(0.017 * (wave4pos + i)) * amp4;
54         if (val < 2.f && val > -2.f) val = 2.f;
55         points[i*8+1] = val + off;
56         points[i*8+5] = -val + off;
57     }
58     wave1pos++;
59     wave1amp++;
60     wave2pos--;
61     wave2amp++;
62     wave3pos++;
63     wave3amp++;
64     wave4pos++;
65     wave4amp++;
66 }
67 
68 int main(int launchID) {
69 
70     int i;
71 
72     // calculate how many invisible lines there are on each side
73     int width = State->width;
74     int skip = (1024 - width) / 2;
75     int end = 1024 - skip;
76 
77     if (State->idle) {
78 
79         // idle state animation
80         float *points = loadArrayF(RSID_POINTS, 0);
81         if (fadeoutcounter > 0) {
82             // fade waveform to 0
83             for (i = skip; i < end; i++) {
84                 float val = absf(points[i*8+1]);
85                 val = val * FADEOUT_FACTOR;
86                 if (val < 2.f) val = 2.f;
87                 points[i*8+1] = val;
88                 points[i*8+5] = -val;
89             }
90             fadeoutcounter--;
91             if (fadeoutcounter == 0) {
92                 wave1amp = 0;
93                 wave2amp = 0;
94                 wave3amp = 0;
95                 wave4amp = 0;
96             }
97         } else {
98             // idle animation
99             makeIdleWave(points);
100         }
101         fadeincounter = FADEIN_LENGTH;
102     } else {
103         if (fadeincounter > 0 && fadeoutcounter == 0) {
104             // morph from idle animation back to waveform
105             makeIdleWave(idle);
106             if (waveCounter != State->waveCounter) {
107                 waveCounter = State->waveCounter;
108                 float *points = loadArrayF(RSID_POINTS, 0);
109                 for (i = skip; i < end; i++) {
110                     float val = absf(points[i*8+1]);
111                     points[i*8+1] = (val * (FADEIN_LENGTH - fadeincounter) + idle[i*8+1] * fadeincounter) / FADEIN_LENGTH;
112                     points[i*8+5] = (-val * (FADEIN_LENGTH - fadeincounter) + idle[i*8+5] * fadeincounter) / FADEIN_LENGTH;
113                 }
114             }
115             fadeincounter--;
116             if (fadeincounter == 0) {
117                 fadeoutcounter = FADEOUT_LENGTH;
118             }
119         } else {
120             fadeoutcounter = FADEOUT_LENGTH;
121         }
122     }
123 
124     float mat1[16];
125     float yrot = State->yRotation;
126     float scale = 0.004165f * (1.0f + 2.f * absf(sinf(radf(yrot))));
127 
128     // Change the model matrix to account for the large model
129     // and to do the necessary rotations.
130     matrixLoadRotate(mat1, yrot, 0.f, 0.f, 1.f);
131     matrixScale(mat1, scale, scale, scale);
132     vpLoadModelMatrix(mat1);
133 
134     // Draw the visualizer.
135     uploadToBufferObject(NAMED_PointBuffer);
136     bindTexture(NAMED_PFBackground, 0, NAMED_Tlinetexture);
137     drawSimpleMeshRange(NAMED_CubeMesh, skip * 2, width * 2);
138 
139     return 1;
140 }
141