blob: a78133bc30da06fdedc419cf2d051ba4efcd29af [file] [log] [blame]
Romain Guye04d27e2009-08-21 16:30:52 -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(PVBackground)
17#pragma stateFragment(PFBackground)
18#pragma stateFragmentStore(PFSBackground)
19
Romain Guye04d27e2009-08-21 16:30:52 -070020#define ELLIPSE_RATIO 0.892f
21
Romain Guy909dff32009-09-04 17:54:17 -070022float angle;
23float distance;
24
25void init() {
26 angle = 0.0f;
27 distance = 0.0f;
28}
29
Romain Guye04d27e2009-08-21 16:30:52 -070030void drawSpace(float xOffset, int width, int height) {
31 bindTexture(NAMED_PFBackground, 0, NAMED_TSpace);
32 drawQuadTexCoords(
Romain Guy9e6f2342009-08-24 18:40:21 -070033 0.0f, 0.0f, 0.0f, 0.0f, 1.0f,
34 width, 0.0f, 0.0f, 2.0f, 1.0f,
35 width, height, 0.0f, 2.0f, 0.0f,
36 0.0f, height, 0.0f, 0.0f, 0.0f);
Romain Guye04d27e2009-08-21 16:30:52 -070037}
38
39void drawLights(float xOffset, int width, int height) {
Romain Guy909dff32009-09-04 17:54:17 -070040 bindProgramVertex(NAMED_PVStars);
Romain Guye04d27e2009-08-21 16:30:52 -070041 bindProgramFragment(NAMED_PFBackground);
42 bindTexture(NAMED_PFBackground, 0, NAMED_TLight1);
Romain Guy909dff32009-09-04 17:54:17 -070043
44 float scale = 512.0f / width;
45 float x = -scale + xOffset - scale * 0.05f;
46 float y = -scale;
47
48 scale *= 2.0f;
49
50 drawQuad(x, y, 0.0f,
51 x + scale * 1.1f, y, 0.0f,
52 x + scale * 1.1f, y + scale, 0.0f,
53 x, y + scale, 0.0f);
Romain Guye04d27e2009-08-21 16:30:52 -070054}
55
Romain Guye04d27e2009-08-21 16:30:52 -070056void drawParticles(float xOffset, int width, int height) {
Romain Guy909dff32009-09-04 17:54:17 -070057 bindProgramVertex(NAMED_PVStars);
58 bindProgramFragment(NAMED_PFStars);
Jason Sams16b673e2009-09-03 15:43:30 -070059 bindProgramFragmentStore(NAMED_PFSLights);
Romain Guy909dff32009-09-04 17:54:17 -070060 bindTexture(NAMED_PFStars, 0, NAMED_TFlares);
61
62 float matrix[16];
63 matrixLoadTranslate(matrix, 0.0f, 0.0f, 10.0f - 6.0f * distance);
64 matrixScale(matrix, 6.15f, 6.0f, 1.0f);
65 matrixRotate(matrix, angle, 1.0f, 0.5f, 0.0f);
66 vpLoadModelMatrix(matrix);
67
68 // quadratic attenuation
69 pointAttenuation(0.1f, 0.0f, 0.06f);
Romain Guye04d27e2009-08-21 16:30:52 -070070
Jason Sams16b673e2009-09-03 15:43:30 -070071 int radius = State->galaxyRadius;
72 int particlesCount = State->particlesCount;
Romain Guye04d27e2009-08-21 16:30:52 -070073
Romain Guy909dff32009-09-04 17:54:17 -070074 float w = xOffset;
75
76 struct Stars_s *star = Stars;
77 struct Particles_s *vtx = Particles;
Romain Guye04d27e2009-08-21 16:30:52 -070078
79 int i = 0;
80 for ( ; i < particlesCount; i++) {
Jason Sams16b673e2009-09-03 15:43:30 -070081 float a = star->angle + star->speed;
82 float x = star->distance * sinf(a);
83 float y = star->distance * cosf(a) * ELLIPSE_RATIO;
84
85 vtx->x = star->t * x + star->s * y + w;
Romain Guy909dff32009-09-04 17:54:17 -070086 vtx->y = star->s * x - star->t * y;
Jason Sams16b673e2009-09-03 15:43:30 -070087 star->angle = a;
Romain Guy909dff32009-09-04 17:54:17 -070088 star++;
89 vtx++;
Romain Guye04d27e2009-08-21 16:30:52 -070090 }
91
92 uploadToBufferObject(NAMED_ParticlesBuffer);
Jason Sams16b673e2009-09-03 15:43:30 -070093 drawSimpleMeshRange(NAMED_ParticlesMesh, 0, particlesCount);
Romain Guye04d27e2009-08-21 16:30:52 -070094}
95
96int main(int index) {
Jason Sams16b673e2009-09-03 15:43:30 -070097 int width = State->width;
98 int height = State->height;
99
Romain Guy909dff32009-09-04 17:54:17 -0700100 float x = lerpf(1.0f, -1.0f, State->xOffset);
Romain Guye04d27e2009-08-21 16:30:52 -0700101
102 drawSpace(x, width, height);
103 drawParticles(x, width, height);
104 drawLights(x, width, height);
Romain Guy909dff32009-09-04 17:54:17 -0700105
106// if (angle < 68.0f) {
107// angle += 0.4f;
108// distance = angle / 68.0f;
109// }
110
Romain Guye04d27e2009-08-21 16:30:52 -0700111 return 1;
112}