Merge pull request #3819 from arnova/subtitles_for_stacks
[vuplus_xbmc] / addons / visualization.vortex / resources / Presets / SpectrumSphere.vtx
1 // SpectrumSphere.vtx
2 // Author - morte0815
3
4 float time = 0;
5 float rx,rxamt,ry,ryamt;
6
7 float[] org_coordsX(70);
8 float[] org_coordsY(70);
9 float[] org_coordsZ(70);
10 float[] org_colorR(70);
11 float[] org_colorG(70);
12 float[] org_colorB(70);
13
14 float stacks = 8;
15 float segments = 8;
16
17 float velX,velY,velZ;
18 float posX,posY,posZ;
19 float signX,signY,signZ;
20 Map     map;
21
22 int x,y;
23
24 void Init()
25 {
26   velX= 0;
27   velY= 0;
28   velZ = 0;
29   posX= 0;
30   posY= 0;
31   posZ = 0;
32   posX= 0;
33   posY= 0;
34   posZ = 0;
35   signX= 1;
36   signY= 1;
37   signZ = 1;
38
39   if(BASS < 0.2f){signZ = 1;}
40   if(MIDDLE < 0.2f){signY = -1;}
41   if(TREBLE < 0.2f){signX = -1;}
42   
43   for (int i = 0; i< stacks; i++)
44   {
45     float temp = Cos(3.14159f/6.0f*i-3.14159f/2.0f);
46     for (int j = 0; j < segments; j++)
47     {
48       org_coordsY[Fabs(i*segments+j)] = Sin(3.14159f/6.0f*i-3.14159f/2.0f);
49       org_coordsX[Fabs(i*segments+j)] = Cos(2*3.14159f/segments*j) * temp;
50       org_coordsZ[Fabs(i*segments+j)] = Sin(2*3.14159f/segments*j) * temp;
51     }
52   }
53   for (int i = 0; i< stacks; i++)
54   {
55     for (int j = 0; j< segments; j++)
56     {
57       org_colorR[i*segments+j] = Sin(i);
58       org_colorG[i*segments+j] = Sin(j);
59       org_colorB[i*segments+j] = 1-Sin(j);
60     }
61   }
62   
63   
64   
65
66
67 }
68
69 void RenderSphere()
70 {
71   float addX=0;
72   float addY=0;
73   float addZ=0;
74   float scale = 0.5f;
75   float colorVal = 0;
76   gfxBegin(PRIM_TRIANGLELIST);
77     for (int i = 0; i< stacks-2; i++)
78     {
79       for (int j = 0; j< segments; j++)
80       {
81         float temp = i*segments+j;
82         addX = GetSpec(Fabs(temp/2)) * org_coordsX[temp]*scale;
83         addY = GetSpec(Fabs(temp/2)) * org_coordsY[temp]*scale;
84         addZ = GetSpec(Fabs(temp/2)) * org_coordsZ[temp]*scale;
85         colorVal = GetSpec(Fabs(temp/2));
86         
87         
88         gfxColour(org_colorR[temp],org_colorG[temp] ,org_colorB[temp] ,1);
89         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
90         
91         temp = (i+1)*segments+((j+1)%segments);
92         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
93         
94         temp = i*segments+((j+1)%segments);
95         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
96         
97         temp = i*segments+j;
98         addX = GetSpec(Fabs(temp/2)) * org_coordsX[temp]*scale;
99         addY = GetSpec(Fabs(temp/2)) * org_coordsY[temp]*scale;
100         addZ = GetSpec(Fabs(temp/2)) * org_coordsZ[temp]*scale;
101         colorVal = GetSpec(Fabs(temp/2));
102         
103         gfxColour(org_colorR[temp],org_colorG[temp],org_colorB[temp],1);
104         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
105         
106         temp = (i+1)*segments+j;
107         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
108         
109         temp = (i+1)*segments+((j+1)%segments);
110         gfxVertex(org_coordsX[temp] + addX,org_coordsY[temp] + addY,org_coordsZ[temp] + addZ);
111       }
112     }
113   gfxEnd();
114 }
115
116 void PushAround()
117 {
118     if (Abs(BASS) > 0.3f){velZ += BASS*3.0f;}
119     if (Abs(BASS) < 0.3f){velZ -= BASS*3.0f;}
120     if (Abs(MIDDLE) > 0.3f){velY += MIDDLE*3.0f;}
121     if (Abs(MIDDLE) < 0.3f){velY -= MIDDLE*3.0f;}
122     if (Abs(TREBLE) > 0.3f){velX += TREBLE*3.0f;}
123     if (Abs(TREBLE) < 0.3f){velX -= TREBLE*3.0f;}
124     
125    velX = Clamp(velX,-3.0f,3.0f);
126   velY = Clamp(velY,-3.0f,3.0f);
127   velZ = Clamp(velZ,-3.0f,3.0f);
128   
129   posX += signX*velX*TIMEPASS;
130   posY += signY*velY*TIMEPASS;
131   posZ += signZ*velZ*TIMEPASS;
132   
133   if (posX < -4 || posX > 4){signX = -signX;}
134   if (posY < -4 || posY > 4){signY = -signY;}
135   if (posZ < -4 || posZ > 4){signZ = -signZ;}
136   
137   gfxTranslate(posX,posY,posZ);
138  
139 }
140
141 void Render()
142 {
143     time += TIMEPASS;
144     for (y=0;y<24;y=y+1)
145         {
146                 for (x=0;x<32;x=x+1)
147                 {
148                   float dx = (x-16);
149                   float dy = (y-12);
150                   float s = Mag(dx,dy)/Mag(16,12);
151                   if (s == 0)
152                   {
153                     map.SetValues(x, y, 0.1, 0.1, 0.8,0.8, 0.8);
154           }
155                         map.SetValues(x, y, dx*s*0.1*Fabs(BASS), dy*s*0.1*Fabs(BASS), 0.8,0.8, 0.8);
156                 }
157         
158         }
159         map.Render();
160   
161         gfxSetRenderTarget(map);
162         gfxPushMatrix();
163     gfxTranslate(0,0,15);
164         
165     PushAround();                                   
166
167     if (BASS>0.3) ryamt = 1;
168         if (BASS<-0.3) ryamt = -1;
169                 ry = ry + (ryamt*TIMEPASS);
170
171         gfxRotate(ry*90,0,1,0);
172
173                 
174                 RenderSphere();
175                 
176                 gfxPopMatrix();
177
178         gfxSetRenderTarget(0);
179         gfxSetEnvTexture(NULL);
180         gfxSetTexture(map);
181   
182         gfxSetAspect(0);
183         gfxTranslate(0, 0, 2.414);
184         gfxColour(1, 1, 1, 1);
185         gfxTexRect(-1, 1, 1, -1);   
186 }