blob: e25e04afa98e8861170755be470326b34c7d6f47 [file] [log] [blame]
Romain Guy59206df2009-09-09 13:07:58 -07001// 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(PVSky)
17#pragma stateFragment(PFBackground)
Jason Samscc924472009-10-05 14:37:53 -070018#pragma stateStore(PFSBackground)
Romain Guy59206df2009-09-09 13:07:58 -070019
Mike Cleron70ebeb82009-11-12 07:49:08 -080020#define LEAVES_TEXTURES_COUNT 8
Romain Guy59206df2009-09-09 13:07:58 -070021#define LEAF_SIZE 0.55f
Mike Cleron5b219fc2009-11-19 23:23:13 -080022#define LEAVES_COUNT 14
Romain Guy59206df2009-09-09 13:07:58 -070023
Romain Guyf0bb9562009-10-07 12:25:24 -070024float skyOffsetX;
25float skyOffsetY;
Jason Sams756f9742009-11-15 10:16:07 -080026float g_DT;
27int g_LastTime;
Romain Guy59206df2009-09-09 13:07:58 -070028
29struct vert_s {
Romain Guy59206df2009-09-09 13:07:58 -070030 float x;
31 float y;
32 float z;
Jason Samsd6c1f692009-10-07 18:08:08 -070033 float s;
34 float t;
Romain Guy59206df2009-09-09 13:07:58 -070035};
36
Jason Sams2cfcc6d2009-10-21 17:51:46 -070037struct drop_s {
Jason Samsb344cf42009-11-06 11:50:42 -080038 float ampS;
39 float ampE;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070040 float spread;
Jason Samsac8dd7e2009-10-22 14:52:02 -070041 float spread2;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070042 float invSpread;
Jason Samsac8dd7e2009-10-22 14:52:02 -070043 float invSpread2;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070044 float x;
45 float y;
46};
47struct drop_s gDrops[10];
Jason Sams2cfcc6d2009-10-21 17:51:46 -070048int gMaxDrops;
49
Mike Cleron5b219fc2009-11-19 23:23:13 -080050struct Leaves_s {
51 float x;
52 float y;
53 float scale;
54 float angle;
55 float spin;
56 float u1;
57 float u2;
58 float altitude;
59 float rippled;
60 float deltaX;
61 float deltaY;
62 int newLeaf;
63};
64
65struct Leaves_s gLeavesStore[LEAVES_COUNT];
66
67struct Leaves_s* gLeaves[LEAVES_COUNT];
68
69struct Leaves_s* gNextLeaves[LEAVES_COUNT];
70
Jason Sams2cfcc6d2009-10-21 17:51:46 -070071void init() {
72 int ct;
73 gMaxDrops = 10;
74 for (ct=0; ct<gMaxDrops; ct++) {
Jason Samsb344cf42009-11-06 11:50:42 -080075 gDrops[ct].ampS = 0;
76 gDrops[ct].ampE = 0;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070077 gDrops[ct].spread = 1;
Jason Samsac8dd7e2009-10-22 14:52:02 -070078 gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070079 gDrops[ct].invSpread = 1 / gDrops[ct].spread;
Jason Samsac8dd7e2009-10-22 14:52:02 -070080 gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread;
Jason Sams2cfcc6d2009-10-21 17:51:46 -070081 }
Romain Guy59206df2009-09-09 13:07:58 -070082}
83
Romain Guy59014c62009-10-09 12:27:18 -070084void initLeaves() {
Mike Cleron5b219fc2009-11-19 23:23:13 -080085 struct Leaves_s *leaf = gLeavesStore;
Jason Sams873e9932009-10-22 14:03:52 -070086 float width = State->glWidth * 2;
Romain Guy59014c62009-10-09 12:27:18 -070087 float height = State->glHeight;
88
89 int i;
Mike Cleron5b219fc2009-11-19 23:23:13 -080090 for (i = 0; i < LEAVES_COUNT; i ++) {
91 gLeaves[i] = leaf;
Romain Guy59014c62009-10-09 12:27:18 -070092 int sprite = randf(LEAVES_TEXTURES_COUNT);
Romain Guy2d427942009-10-14 15:43:27 -070093 leaf->x = randf2(-width * 0.5f, width * 0.5f);
94 leaf->y = randf2(-height * 0.5f, height * 0.5f);
Romain Guy59014c62009-10-09 12:27:18 -070095 leaf->scale = randf2(0.4f, 0.5f);
96 leaf->angle = randf2(0.0f, 360.0f);
Romain Guy2d427942009-10-14 15:43:27 -070097 leaf->spin = degf(randf2(-0.02f, 0.02f)) * 0.25f;
Romain Guy59014c62009-10-09 12:27:18 -070098 leaf->u1 = sprite / (float) LEAVES_TEXTURES_COUNT;
99 leaf->u2 = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
100 leaf->altitude = -1.0f;
101 leaf->rippled = 1.0f;
Jason Sams756f9742009-11-15 10:16:07 -0800102 leaf->deltaX = randf2(-0.02f, 0.02f) / 2.0f;
103 leaf->deltaY = -0.08f * randf2(0.9f, 1.1f) / 2.0f;
Romain Guy59014c62009-10-09 12:27:18 -0700104 leaf++;
105 }
106}
107
Jason Samsb344cf42009-11-06 11:50:42 -0800108void updateDrop(int ct) {
Jason Sams756f9742009-11-15 10:16:07 -0800109 gDrops[ct].spread += 30.f * g_DT;
Jason Samsb344cf42009-11-06 11:50:42 -0800110 gDrops[ct].spread2 = gDrops[ct].spread * gDrops[ct].spread;
111 gDrops[ct].invSpread = 1 / gDrops[ct].spread;
112 gDrops[ct].invSpread2 = gDrops[ct].invSpread * gDrops[ct].invSpread;
113 gDrops[ct].ampE = gDrops[ct].ampS * gDrops[ct].invSpread;
114}
115
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700116void drop(int x, int y, float s) {
Jason Sams6eec5982009-10-23 17:47:12 -0700117 int ct;
118 int iMin = 0;
119 float minAmp = 10000.f;
120 for (ct = 0; ct < gMaxDrops; ct++) {
Jason Samsb344cf42009-11-06 11:50:42 -0800121 if (gDrops[ct].ampE < minAmp) {
Jason Sams6eec5982009-10-23 17:47:12 -0700122 iMin = ct;
Jason Samsb344cf42009-11-06 11:50:42 -0800123 minAmp = gDrops[ct].ampE;
Jason Sams6eec5982009-10-23 17:47:12 -0700124 }
125 }
Jason Samsb344cf42009-11-06 11:50:42 -0800126 gDrops[iMin].ampS = s;
127 gDrops[iMin].spread = 0;
Jason Sams6eec5982009-10-23 17:47:12 -0700128 gDrops[iMin].x = x;
129 gDrops[iMin].y = State->meshHeight - y - 1;
Jason Samsb344cf42009-11-06 11:50:42 -0800130 updateDrop(iMin);
Romain Guy59206df2009-09-09 13:07:58 -0700131}
132
133void generateRipples() {
Romain Guy59014c62009-10-09 12:27:18 -0700134 int rippleMapSize = State->rippleMapSize;
Romain Guy59206df2009-09-09 13:07:58 -0700135 int width = State->meshWidth;
136 int height = State->meshHeight;
137 int index = State->rippleIndex;
Jason Sams873e9932009-10-22 14:03:52 -0700138 float ratio = (float)State->meshWidth / State->glWidth;
139 float xShift = State->xOffset * ratio * 2;
Romain Guy59206df2009-09-09 13:07:58 -0700140
Jason Sams2430b672009-09-24 13:01:52 -0700141 float *vertices = loadSimpleMeshVerticesF(NAMED_WaterMesh, 0);
Romain Guy59206df2009-09-09 13:07:58 -0700142 struct vert_s *vert = (struct vert_s *)vertices;
143
Romain Guy59014c62009-10-09 12:27:18 -0700144 float fw = 1.0f / width;
145 float fh = 1.0f / height;
Jason Sams73f2f5f2009-11-10 16:13:23 -0800146 int x, y, ct;
147 struct vert_s *v = vert;
148 for (y=0; y < height; y++) {
149 for (x=0; x < width; x++) {
150 struct drop_s * d = &gDrops[0];
151 float z = 0;
Romain Guy59206df2009-09-09 13:07:58 -0700152
Jason Sams73f2f5f2009-11-10 16:13:23 -0800153 for (ct = 0; ct < gMaxDrops; ct++) {
154 if (d->ampE > 0.01f) {
155 float dx = (d->x - xShift) - x;
156 float dy = d->y - y;
157 float dist2 = dx*dx + dy*dy;
158 if (dist2 < d->spread2) {
159 float dist = sqrtf(dist2);
160 float a = d->ampE * (dist * d->invSpread);
161 z += sinf(d->spread - dist) * a;
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700162 }
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700163 }
Jason Sams73f2f5f2009-11-10 16:13:23 -0800164 d++;
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700165 }
Jason Sams73f2f5f2009-11-10 16:13:23 -0800166 v->z = z;
167 v ++;
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700168 }
Romain Guy59206df2009-09-09 13:07:58 -0700169 }
Jason Sams73f2f5f2009-11-10 16:13:23 -0800170 for (ct = 0; ct < gMaxDrops; ct++) {
171 updateDrop(ct);
172 }
Romain Guy59206df2009-09-09 13:07:58 -0700173
Jason Sams73f2f5f2009-11-10 16:13:23 -0800174 v = vert;
175 for (y = 0; y < height; y += 1) {
176 for (x = 0; x < width; x += 1) {
Romain Guy59206df2009-09-09 13:07:58 -0700177 struct vec3_s n1, n2, n3;
178 vec3Sub(&n1, (struct vec3_s *)&(v+1)->x, (struct vec3_s *)&v->x);
179 vec3Sub(&n2, (struct vec3_s *)&(v+width)->x, (struct vec3_s *)&v->x);
180 vec3Cross(&n3, &n1, &n2);
Romain Guy59206df2009-09-09 13:07:58 -0700181
182 // Average of previous normal and N1 x N2
183 vec3Sub(&n1, (struct vec3_s *)&(v+width+1)->x, (struct vec3_s *)&v->x);
184 vec3Cross(&n2, &n1, &n2);
185 vec3Add(&n3, &n3, &n2);
Jason Samsb344cf42009-11-06 11:50:42 -0800186 //vec3Norm(&n3); // Not necessary for our constrained mesh.
Romain Guy59206df2009-09-09 13:07:58 -0700187
Jason Sams73f2f5f2009-11-10 16:13:23 -0800188 v->s = (float)x * fw + n3.x;// * 0.2;
189 v->t = (float)y * fh + n3.y;// * 0.2;
190 v->z = 0;
Romain Guy59206df2009-09-09 13:07:58 -0700191 v += 1;
Romain Guy59206df2009-09-09 13:07:58 -0700192 }
193 }
194}
195
Jason Sams6eec5982009-10-23 17:47:12 -0700196void genLeafDrop(struct Leaves_s *leaf, float amp) {
197 float nx = (leaf->x + State->glWidth * 0.5f) / State->glWidth;
198 float ny = (leaf->y + State->glHeight * 0.5f) / State->glHeight;
199 drop(nx * State->meshWidth, State->meshHeight - ny * State->meshHeight, amp);
200
201}
202
Mike Cleron5b219fc2009-11-19 23:23:13 -0800203int drawLeaf(struct Leaves_s *leaf) {
Romain Guya6d4d982009-10-15 12:37:13 -0700204
Romain Guy59014c62009-10-09 12:27:18 -0700205 float x = leaf->x;
Romain Guy59014c62009-10-09 12:27:18 -0700206 float y = leaf->y;
Romain Guy59206df2009-09-09 13:07:58 -0700207
Romain Guy59014c62009-10-09 12:27:18 -0700208 float u1 = leaf->u1;
209 float u2 = leaf->u2;
Romain Guy59206df2009-09-09 13:07:58 -0700210
Romain Guy59014c62009-10-09 12:27:18 -0700211 float a = leaf->altitude;
212 float s = leaf->scale;
213 float r = leaf->angle;
Romain Guy59206df2009-09-09 13:07:58 -0700214
215 float tz = 0.0f;
216 if (a > 0.0f) {
217 tz = -a;
Romain Guy59206df2009-09-09 13:07:58 -0700218 }
219
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700220 float matrix[16];
Romain Guy59014c62009-10-09 12:27:18 -0700221 if (a > 0.0f) {
Jason Sams73f2f5f2009-11-10 16:13:23 -0800222
Mike Cleronfc6bdef2009-11-10 13:31:30 -0800223 float alpha = 1.0f;
Mike Cleron701a47f2009-11-10 12:55:26 -0800224 if (a >= 0.4f) alpha = 1.0f - (a - 0.4f) / 0.1f;
Jason Sams73f2f5f2009-11-10 16:13:23 -0800225
Mike Cleron701a47f2009-11-10 12:55:26 -0800226 color(0.0f, 0.0f, 0.0f, alpha * 0.15f);
Romain Guya6d4d982009-10-15 12:37:13 -0700227
Jason Sams6eec5982009-10-23 17:47:12 -0700228 if (State->rotate) {
Romain Guya6d4d982009-10-15 12:37:13 -0700229 matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);
230 } else {
231 matrixLoadIdentity(matrix);
232 }
Jason Sams73f2f5f2009-11-10 16:13:23 -0800233
Mike Cleron701a47f2009-11-10 12:55:26 -0800234 float shadowOffet = a / 5;
Jason Sams73f2f5f2009-11-10 16:13:23 -0800235
Mike Cleron701a47f2009-11-10 12:55:26 -0800236 matrixTranslate(matrix, (x - State->xOffset * 2) + (shadowOffet / 2), y - shadowOffet, tz);
Romain Guy59014c62009-10-09 12:27:18 -0700237 matrixScale(matrix, s, s, 1.0f);
238 matrixRotate(matrix, r, 0.0f, 0.0f, 1.0f);
239 vpLoadModelMatrix(matrix);
240
Jason Sams873e9932009-10-22 14:03:52 -0700241 drawQuadTexCoords(-LEAF_SIZE, -LEAF_SIZE, 0, u1, 1.0f,
242 LEAF_SIZE, -LEAF_SIZE, 0, u2, 1.0f,
243 LEAF_SIZE, LEAF_SIZE, 0, u2, 0.0f,
244 -LEAF_SIZE, LEAF_SIZE, 0, u1, 0.0f);
Romain Guy59014c62009-10-09 12:27:18 -0700245
Romain Guy59014c62009-10-09 12:27:18 -0700246 color(1.0f, 1.0f, 1.0f, alpha);
247 } else {
248 color(1.0f, 1.0f, 1.0f, 1.0f);
249 }
250
Jason Sams6eec5982009-10-23 17:47:12 -0700251 if (State->rotate) {
Romain Guya6d4d982009-10-15 12:37:13 -0700252 matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);
253 } else {
254 matrixLoadIdentity(matrix);
255 }
Jason Sams873e9932009-10-22 14:03:52 -0700256 matrixTranslate(matrix, x - State->xOffset * 2, y, tz);
Romain Guy59206df2009-09-09 13:07:58 -0700257 matrixScale(matrix, s, s, 1.0f);
258 matrixRotate(matrix, r, 0.0f, 0.0f, 1.0f);
259 vpLoadModelMatrix(matrix);
260
Jason Sams873e9932009-10-22 14:03:52 -0700261 drawQuadTexCoords(-LEAF_SIZE, -LEAF_SIZE, 0, u1, 1.0f,
262 LEAF_SIZE, -LEAF_SIZE, 0, u2, 1.0f,
263 LEAF_SIZE, LEAF_SIZE, 0, u2, 0.0f,
264 -LEAF_SIZE, LEAF_SIZE, 0, u1, 0.0f);
Romain Guy59206df2009-09-09 13:07:58 -0700265
Romain Guy59014c62009-10-09 12:27:18 -0700266 float spin = leaf->spin;
Romain Guy59206df2009-09-09 13:07:58 -0700267 if (a <= 0.0f) {
Romain Guy59014c62009-10-09 12:27:18 -0700268 float rippled = leaf->rippled;
Romain Guy59206df2009-09-09 13:07:58 -0700269 if (rippled < 0.0f) {
Jason Sams6eec5982009-10-23 17:47:12 -0700270 genLeafDrop(leaf, 1.5f);
271 //drop(((x + State->glWidth * 0.5f) / State->glWidth) * meshWidth,
272 // meshHeight - ((y + State->glHeight * 0.5f) / State->glHeight) * meshHeight, 1);
Romain Guy59206df2009-09-09 13:07:58 -0700273 spin /= 4.0f;
Romain Guy59014c62009-10-09 12:27:18 -0700274 leaf->spin = spin;
275 leaf->rippled = 1.0f;
Romain Guy59206df2009-09-09 13:07:58 -0700276 }
Jason Sams756f9742009-11-15 10:16:07 -0800277 leaf->x = x + leaf->deltaX * g_DT;
278 leaf->y = y + leaf->deltaY * g_DT;
Romain Guy59206df2009-09-09 13:07:58 -0700279 r += spin;
Romain Guy59014c62009-10-09 12:27:18 -0700280 leaf->angle = r;
Romain Guy59206df2009-09-09 13:07:58 -0700281 } else {
Jason Sams756f9742009-11-15 10:16:07 -0800282 a -= 0.15f * g_DT;
Romain Guy59014c62009-10-09 12:27:18 -0700283 leaf->altitude = a;
Romain Guy59206df2009-09-09 13:07:58 -0700284 r += spin * 2.0f;
Romain Guy59014c62009-10-09 12:27:18 -0700285 leaf->angle = r;
Romain Guy59206df2009-09-09 13:07:58 -0700286 }
287
Mike Cleron5b219fc2009-11-19 23:23:13 -0800288 int newLeaf = 0;
Jason Sams6eec5982009-10-23 17:47:12 -0700289 if (-LEAF_SIZE * s + x > State->glWidth || LEAF_SIZE * s + x < -State->glWidth ||
290 LEAF_SIZE * s + y < -State->glHeight / 2.0f) {
Romain Guy59206df2009-09-09 13:07:58 -0700291
292 int sprite = randf(LEAVES_TEXTURES_COUNT);
Jason Sams6eec5982009-10-23 17:47:12 -0700293 leaf->x = randf2(-State->glWidth, State->glWidth);
294 leaf->y = randf2(-State->glHeight * 0.5f, State->glHeight * 0.5f);
Jason Sams756f9742009-11-15 10:16:07 -0800295
Romain Guy59014c62009-10-09 12:27:18 -0700296 leaf->scale = randf2(0.4f, 0.5f);
Mike Cleron70ebeb82009-11-12 07:49:08 -0800297 leaf->spin = degf(randf2(-0.02f, 0.02f)) * 0.35f;
Romain Guy59014c62009-10-09 12:27:18 -0700298 leaf->u1 = sprite / (float) LEAVES_TEXTURES_COUNT;
299 leaf->u2 = (sprite + 1) / (float) LEAVES_TEXTURES_COUNT;
Mike Cleron70ebeb82009-11-12 07:49:08 -0800300 leaf->altitude = 0.7f;
Romain Guy59014c62009-10-09 12:27:18 -0700301 leaf->rippled = -1.0f;
Jason Sams756f9742009-11-15 10:16:07 -0800302 leaf->deltaX = randf2(-0.02f, 0.02f) / 2.0f;
303 leaf->deltaY = -0.08f * randf2(0.9f, 1.1f) / 2.0f;
Mike Cleron5b219fc2009-11-19 23:23:13 -0800304 leaf->newLeaf = 1;
305 newLeaf = 1;
Romain Guy59206df2009-09-09 13:07:58 -0700306 }
Mike Cleron5b219fc2009-11-19 23:23:13 -0800307 return newLeaf;
Romain Guy59206df2009-09-09 13:07:58 -0700308}
309
310void drawLeaves() {
Romain Guy59014c62009-10-09 12:27:18 -0700311 bindProgramFragment(NAMED_PFSky);
Romain Guy59206df2009-09-09 13:07:58 -0700312 bindProgramFragmentStore(NAMED_PFSLeaf);
313 bindProgramVertex(NAMED_PVSky);
Romain Guy59014c62009-10-09 12:27:18 -0700314 bindTexture(NAMED_PFSky, 0, NAMED_TLeaves);
315
316 color(1.0f, 1.0f, 1.0f, 1.0f);
Romain Guy59206df2009-09-09 13:07:58 -0700317
Mike Cleron5b219fc2009-11-19 23:23:13 -0800318 int newLeaves = 0;
Romain Guy59206df2009-09-09 13:07:58 -0700319 int i = 0;
Mike Cleron5b219fc2009-11-19 23:23:13 -0800320 for ( ; i < LEAVES_COUNT; i += 1) {
321 if (drawLeaf(gLeaves[i])) {
322 newLeaves = 1;
323
324 }
325 }
326
327 if (newLeaves > 0) {
328 int index = 0;
329
330 // Copy all the old leaves to the beginning of gNextLeaves
331 for (i=0; i < LEAVES_COUNT; i++) {
332 if (gLeaves[i]->newLeaf == 0) {
333 gNextLeaves[index] = gLeaves[i];
334 index++;
335 }
336 }
337
338 // Now copy all the newly falling leaves to the end of gNextLeaves
339 for (i=0; i < LEAVES_COUNT; i++) {
340 if (gLeaves[i]->newLeaf > 0) {
341 gNextLeaves[index] = gLeaves[i];
342 gNextLeaves[index]->newLeaf = 0;
343 index++;
344 }
345 }
346
347 // And move everything in gNextLeaves back to gLeaves
348 for (i=0; i < LEAVES_COUNT; i++) {
349 gLeaves[i] = gNextLeaves[i];
350 }
Romain Guy59206df2009-09-09 13:07:58 -0700351 }
352
353 float matrix[16];
354 matrixLoadIdentity(matrix);
355 vpLoadModelMatrix(matrix);
356}
357
358void drawRiverbed() {
359 bindTexture(NAMED_PFBackground, 0, NAMED_TRiverbed);
360
Jason Sams873e9932009-10-22 14:03:52 -0700361 float matrix[16];
Mike Cleron5b219fc2009-11-19 23:23:13 -0800362 matrixLoadScale(matrix, 0.5f * 960.0f / 1024.0f, -1.0f * 800.0f / 1024.0f, 1.0f);
Jason Samsb1cafe52009-10-27 18:20:55 -0700363 matrixTranslate(matrix, State->xOffset, 0.0f, 0.0f);
Jason Sams873e9932009-10-22 14:03:52 -0700364 vpLoadTextureMatrix(matrix);
Jason Samsb1cafe52009-10-27 18:20:55 -0700365
Jason Sams2430b672009-09-24 13:01:52 -0700366 drawSimpleMesh(NAMED_WaterMesh);
Jason Samsb1cafe52009-10-27 18:20:55 -0700367
368 matrixLoadIdentity(matrix);
369 vpLoadTextureMatrix(matrix);
Romain Guy59206df2009-09-09 13:07:58 -0700370}
371
Mike Cleronfc6bdef2009-11-10 13:31:30 -0800372/*
Romain Guy59206df2009-09-09 13:07:58 -0700373void drawSky() {
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700374 color(1.0f, 1.0f, 1.0f, 0.5f);
Romain Guy59206df2009-09-09 13:07:58 -0700375
376 bindProgramFragment(NAMED_PFSky);
377 bindProgramFragmentStore(NAMED_PFSLeaf);
378 bindTexture(NAMED_PFSky, 0, NAMED_TSky);
379
Romain Guyf0bb9562009-10-07 12:25:24 -0700380 float x = skyOffsetX + State->skySpeedX;
381 float y = skyOffsetY + State->skySpeedY;
Romain Guy59206df2009-09-09 13:07:58 -0700382
383 if (x > 1.0f) x = 0.0f;
384 if (x < -1.0f) x = 0.0f;
385 if (y > 1.0f) y = 0.0f;
386
Romain Guyf0bb9562009-10-07 12:25:24 -0700387 skyOffsetX = x;
388 skyOffsetY = y;
Romain Guy59206df2009-09-09 13:07:58 -0700389
390 float matrix[16];
Jason Sams873e9932009-10-22 14:03:52 -0700391 matrixLoadTranslate(matrix, x + State->xOffset, y, 0.0f);
Romain Guy59206df2009-09-09 13:07:58 -0700392 vpLoadTextureMatrix(matrix);
393
Jason Sams2430b672009-09-24 13:01:52 -0700394 drawSimpleMesh(NAMED_WaterMesh);
Romain Guy59206df2009-09-09 13:07:58 -0700395
396 matrixLoadIdentity(matrix);
397 vpLoadTextureMatrix(matrix);
398}
Mike Cleronfc6bdef2009-11-10 13:31:30 -0800399*/
Romain Guy59206df2009-09-09 13:07:58 -0700400
Romain Guy59206df2009-09-09 13:07:58 -0700401int main(int index) {
Jason Sams756f9742009-11-15 10:16:07 -0800402 // Compute dt in seconds.
403 int newTime = uptimeMillis();
404 g_DT = (newTime - g_LastTime) / 1000.f;
405 g_LastTime = newTime;
406 g_DT = minf(g_DT, 0.2f);
407
408
Romain Guy59206df2009-09-09 13:07:58 -0700409 if (Drop->dropX != -1) {
Jason Sams73f2f5f2009-11-10 16:13:23 -0800410 drop(Drop->dropX, Drop->dropY, 2);
Romain Guy59206df2009-09-09 13:07:58 -0700411 Drop->dropX = -1;
412 Drop->dropY = -1;
413 }
Romain Guy2d427942009-10-14 15:43:27 -0700414
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700415 int ct;
Jason Sams6eec5982009-10-23 17:47:12 -0700416 int add = 0;
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700417 for (ct = 0; ct < gMaxDrops; ct++) {
Jason Samsb344cf42009-11-06 11:50:42 -0800418 if (gDrops[ct].ampE < 0.005f) {
Jason Sams6eec5982009-10-23 17:47:12 -0700419 add = 1;
420 }
Jason Sams2cfcc6d2009-10-21 17:51:46 -0700421 }
Romain Guy2d427942009-10-14 15:43:27 -0700422
Jason Sams6eec5982009-10-23 17:47:12 -0700423 if (add) {
Mike Cleron5b219fc2009-11-19 23:23:13 -0800424 int i = (int)randf(LEAVES_COUNT);
425 genLeafDrop(gLeaves[i], randf(0.3f) + 0.1f);
Romain Guya454eca2009-10-14 18:22:20 -0700426 }
Romain Guy59206df2009-09-09 13:07:58 -0700427
Romain Guy59206df2009-09-09 13:07:58 -0700428 generateRipples();
Jason Sams2430b672009-09-24 13:01:52 -0700429 updateSimpleMesh(NAMED_WaterMesh);
Romain Guy59206df2009-09-09 13:07:58 -0700430
Romain Guya6d4d982009-10-15 12:37:13 -0700431 if (State->rotate) {
432 float matrix[16];
433 matrixLoadRotate(matrix, 90.0f, 0.0f, 0.0f, 1.0f);
434 vpLoadModelMatrix(matrix);
435 }
436
Romain Guy59206df2009-09-09 13:07:58 -0700437 drawRiverbed();
Mike Cleron701a47f2009-11-10 12:55:26 -0800438 // drawSky();
Romain Guy59206df2009-09-09 13:07:58 -0700439 drawLeaves();
Romain Guy59206df2009-09-09 13:07:58 -0700440
441 return 1;
442}