packages/wallpapers/Basic
Revision | 0ac0b3f704bedde5c3a117ac68e7cd4956cd73ef (tree) |
---|---|
Time | 2009-09-13 19:40:04 |
Author | Romain Guy <romainguy@andr...> |
Commiter | Romain Guy |
Tweak the galaxy and add better support for preview mode.
Change-Id: I3339d8066ec0f20ff12adcd9eedf2186d2ea4b01
@@ -23,8 +23,8 @@ float angle; | ||
23 | 23 | float distance; |
24 | 24 | |
25 | 25 | void init() { |
26 | - angle = 0.0f; | |
27 | - distance = 0.0f; | |
26 | + angle = 37.0f; | |
27 | + distance = 0.55f; | |
28 | 28 | } |
29 | 29 | |
30 | 30 | void drawSpace(float xOffset, int width, int height) { |
@@ -61,7 +61,7 @@ void drawParticles(float xOffset, int width, int height) { | ||
61 | 61 | |
62 | 62 | float matrix[16]; |
63 | 63 | matrixLoadTranslate(matrix, 0.0f, 0.0f, 10.0f - 6.0f * distance); |
64 | - matrixScale(matrix, 6.15f, 6.0f, 1.0f); | |
64 | + matrixScale(matrix, 6.6f, 6.0f, 1.0f); | |
65 | 65 | matrixRotate(matrix, angle, 1.0f, 0.5f, 0.0f); |
66 | 66 | vpLoadModelMatrix(matrix); |
67 | 67 |
@@ -103,9 +103,17 @@ int main(int index) { | ||
103 | 103 | drawParticles(x, width, height); |
104 | 104 | drawLights(x, width, height); |
105 | 105 | |
106 | - if (angle < 68.0f) { | |
107 | - angle += 0.4f; | |
108 | - distance = angle / 68.0f; | |
106 | + if (State->isPreview == 0) { | |
107 | + if (angle > 0.0f) { | |
108 | + angle -= 0.4f; | |
109 | + distance = angle / 68.0f; | |
110 | + } | |
111 | + } else { | |
112 | + // Unfortunately this cannot happen in init() | |
113 | + // since the State structure instance does not | |
114 | + // exist at this point | |
115 | + angle = 0.0f; | |
116 | + distance = 0.0f; | |
109 | 117 | } |
110 | 118 | |
111 | 119 | return 1; |
@@ -24,6 +24,7 @@ import android.renderscript.ScriptC; | ||
24 | 24 | public abstract class RenderScriptScene { |
25 | 25 | protected int mWidth; |
26 | 26 | protected int mHeight; |
27 | + protected boolean mPreview; | |
27 | 28 | protected Resources mResources; |
28 | 29 | protected RenderScript mRS; |
29 | 30 | protected ScriptC mScript; |
@@ -33,11 +34,16 @@ public abstract class RenderScriptScene { | ||
33 | 34 | mHeight = height; |
34 | 35 | } |
35 | 36 | |
36 | - public void init(RenderScript rs, Resources res) { | |
37 | + public void init(RenderScript rs, Resources res, boolean isPreview) { | |
37 | 38 | mRS = rs; |
38 | 39 | mResources = res; |
40 | + mPreview = isPreview; | |
39 | 41 | mScript = createScript(); |
40 | 42 | } |
43 | + | |
44 | + public boolean isPreview() { | |
45 | + return mPreview; | |
46 | + } | |
41 | 47 | |
42 | 48 | public int getWidth() { |
43 | 49 | return mWidth; |
@@ -72,7 +72,7 @@ public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends | ||
72 | 72 | super.onSurfaceChanged(holder, format, width, height); |
73 | 73 | if (mRenderer == null) { |
74 | 74 | mRenderer = createScene(width, height); |
75 | - mRenderer.init(mRs, getResources()); | |
75 | + mRenderer.init(mRs, getResources(), isPreview()); | |
76 | 76 | mRenderer.start(); |
77 | 77 | } else { |
78 | 78 | mRenderer.resize(width, height); |
@@ -37,7 +37,7 @@ class FallView extends RSSurfaceView { | ||
37 | 37 | |
38 | 38 | RenderScript RS = createRenderScript(false); |
39 | 39 | mRender = new FallRS(w, h); |
40 | - mRender.init(RS, getResources()); | |
40 | + mRender.init(RS, getResources(), false); | |
41 | 41 | mRender.start(); |
42 | 42 | } |
43 | 43 |
@@ -173,6 +173,7 @@ class GalaxyRS extends RenderScriptScene { | ||
173 | 173 | public int particlesCount; |
174 | 174 | public int galaxyRadius; |
175 | 175 | public float xOffset; |
176 | + public int isPreview; | |
176 | 177 | } |
177 | 178 | |
178 | 179 | static class GalaxyParticle { |
@@ -184,11 +185,17 @@ class GalaxyRS extends RenderScriptScene { | ||
184 | 185 | } |
185 | 186 | |
186 | 187 | private void createState() { |
188 | + boolean isPreview = isPreview(); | |
189 | + | |
187 | 190 | mGalaxyState = new GalaxyState(); |
188 | 191 | mGalaxyState.width = mWidth; |
189 | 192 | mGalaxyState.height = mHeight; |
190 | 193 | mGalaxyState.particlesCount = PARTICLES_COUNT; |
191 | 194 | mGalaxyState.galaxyRadius = GALAXY_RADIUS; |
195 | + mGalaxyState.isPreview = isPreview ? 1 : 0; | |
196 | + if (isPreview) { | |
197 | + mGalaxyState.xOffset = 0.5f; | |
198 | + } | |
192 | 199 | |
193 | 200 | mStateType = Type.createFromClass(mRS, GalaxyState.class, 1, "GalaxyState"); |
194 | 201 | mState = Allocation.createTyped(mRS, mStateType); |
@@ -209,23 +216,29 @@ class GalaxyRS extends RenderScriptScene { | ||
209 | 216 | |
210 | 217 | @SuppressWarnings({"PointlessArithmeticExpression"}) |
211 | 218 | private void createParticle(GalaxyParticle gp, int index, float scale) { |
212 | - float d = abs(randomGauss()) * GALAXY_RADIUS / 2.0f + random(-4.0f, 4.0f); | |
213 | - float z = randomGauss() * 0.5f * 0.8f * ((GALAXY_RADIUS - d) / (float) GALAXY_RADIUS); | |
219 | + float d = abs(randomGauss()) * GALAXY_RADIUS * 0.5f + random(64.0f); | |
220 | + float id = d / (float) GALAXY_RADIUS; | |
221 | + float z = randomGauss() * 0.4f * (1.0f - id); | |
214 | 222 | float p = -d * ELLIPSE_TWIST; |
215 | 223 | |
216 | - final float nd = d / (float) GALAXY_RADIUS; | |
217 | - | |
218 | 224 | int red, green, blue, alpha; |
219 | - if (d < GALAXY_RADIUS / 3.0f) { | |
220 | - red = (int) (220 + nd * 35); | |
225 | + if (d < GALAXY_RADIUS * 0.33f) { | |
226 | + red = (int) (220 + id * 35); | |
221 | 227 | green = 220; |
222 | 228 | blue = 220; |
223 | 229 | } else { |
224 | 230 | red = 180; |
225 | 231 | green = 180; |
226 | - blue = (int) constrain(140 + nd * 115, 140, 255); | |
232 | + blue = (int) constrain(140 + id * 115, 140, 255); | |
227 | 233 | } |
228 | - alpha = (int) (40 + nd * 215); | |
234 | + | |
235 | + if (d > GALAXY_RADIUS * 0.15f) { | |
236 | + z *= 0.6f * (1.0f - id); | |
237 | + } else { | |
238 | + z *= 0.72f; | |
239 | + } | |
240 | + | |
241 | + alpha = (int) (140 + (1.0f - id) * 115); | |
229 | 242 | int color = red | green << 8 | blue << 16 | alpha << 24; |
230 | 243 | |
231 | 244 | // Map to the projection coordinates (viewport.x = -1.0 -> 1.0) |
@@ -35,7 +35,7 @@ class GalaxyView extends RSSurfaceView { | ||
35 | 35 | |
36 | 36 | RenderScript RS = createRenderScript(false); |
37 | 37 | GalaxyRS render = new GalaxyRS(w, h); |
38 | - render.init(RS, getResources()); | |
38 | + render.init(RS, getResources(), false); | |
39 | 39 | render.setOffset(0.5f, 0.0f, 0, 0); |
40 | 40 | render.start(); |
41 | 41 | } |
@@ -35,7 +35,7 @@ class GrassView extends RSSurfaceView { | ||
35 | 35 | |
36 | 36 | RenderScript RS = createRenderScript(false); |
37 | 37 | GrassRS render = new GrassRS(w, h); |
38 | - render.init(RS, getResources()); | |
38 | + render.init(RS, getResources(), false); | |
39 | 39 | render.setOffset(0.5f, 0.0f, 0, 0); |
40 | 40 | render.start(); |
41 | 41 | } |