1 |
d7f0c07d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.overlays;
|
11 |
|
|
|
12 |
|
|
import android.content.res.Resources;
|
13 |
|
|
import android.graphics.Bitmap;
|
14 |
|
|
import android.graphics.BitmapFactory;
|
15 |
|
|
|
16 |
b4cbe056
|
Leszek Koltunski
|
import org.distorted.library.effect.VertexEffectMove;
|
17 |
|
|
import org.distorted.library.effect.VertexEffectRotate;
|
18 |
|
|
import org.distorted.library.effect.VertexEffectScale;
|
19 |
d7f0c07d
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
20 |
|
|
import org.distorted.library.main.DistortedNode;
|
21 |
|
|
import org.distorted.library.main.DistortedScreen;
|
22 |
|
|
import org.distorted.library.main.DistortedTexture;
|
23 |
b4cbe056
|
Leszek Koltunski
|
import org.distorted.library.main.InternalOutputSurface;
|
24 |
|
|
import org.distorted.library.mesh.MeshJoined;
|
25 |
d7f0c07d
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshQuad;
|
26 |
|
|
import org.distorted.library.message.EffectListener;
|
27 |
|
|
import org.distorted.library.type.Dynamic1D;
|
28 |
b4cbe056
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic3D;
|
29 |
d7f0c07d
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
30 |
|
|
import org.distorted.library.type.Static3D;
|
31 |
|
|
import org.distorted.main.R;
|
32 |
|
|
|
33 |
b4cbe056
|
Leszek Koltunski
|
import java.util.Random;
|
34 |
|
|
|
35 |
d7f0c07d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public class OverlayStars extends OverlayGeneric implements EffectListener
|
38 |
|
|
{
|
39 |
b4cbe056
|
Leszek Koltunski
|
private static final int DUR_ALL = 10000;
|
40 |
|
|
private static final int DUR_MOV = 5000;
|
41 |
|
|
|
42 |
d7f0c07d
|
Leszek Koltunski
|
private ListenerOverlay mListener;
|
43 |
|
|
private DistortedNode mNode;
|
44 |
|
|
private DistortedScreen mScreen;
|
45 |
b4cbe056
|
Leszek Koltunski
|
private final Static3D mPointE = new Static3D(0,0,2);
|
46 |
|
|
private float mWidth, mHeight;
|
47 |
|
|
private Random mRandom;
|
48 |
|
|
|
49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
50 |
|
|
|
51 |
|
|
private Dynamic3D createRandomMove()
|
52 |
|
|
{
|
53 |
|
|
Dynamic3D move = new Dynamic3D();
|
54 |
|
|
move.setDuration(DUR_MOV);
|
55 |
|
|
move.setCount(0.5f);
|
56 |
|
|
|
57 |
|
|
float widthS = (mRandom.nextFloat()-0.5f)*mWidth;
|
58 |
|
|
float widthM = widthS + (mRandom.nextFloat()-0.5f)*mWidth*0.2f;
|
59 |
|
|
|
60 |
|
|
Static3D pointS = new Static3D(widthS,mHeight/2,2);
|
61 |
|
|
Static3D pointM = new Static3D(widthM,mHeight/4,2);
|
62 |
|
|
|
63 |
|
|
move.add(pointS);
|
64 |
|
|
move.add(pointM);
|
65 |
|
|
move.add(mPointE);
|
66 |
|
|
|
67 |
|
|
return move;
|
68 |
|
|
}
|
69 |
d7f0c07d
|
Leszek Koltunski
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
private DistortedNode createNode(Resources res, int totS, int newS)
|
73 |
|
|
{
|
74 |
b4cbe056
|
Leszek Koltunski
|
// texture /////////////////////////////////////////////////////
|
75 |
d7f0c07d
|
Leszek Koltunski
|
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.star);
|
76 |
|
|
DistortedTexture texture = new DistortedTexture();
|
77 |
|
|
texture.setTexture(bmp);
|
78 |
|
|
|
79 |
b4cbe056
|
Leszek Koltunski
|
// mesh ////////////////////////////////////////////////////////
|
80 |
|
|
|
81 |
|
|
MeshQuad[] mesh = new MeshQuad[newS+1];
|
82 |
|
|
|
83 |
|
|
for(int i=0; i<newS+1; i++)
|
84 |
|
|
{
|
85 |
|
|
mesh[i] = new MeshQuad();
|
86 |
|
|
mesh[i].setEffectAssociation(0,(i==0?0:1),i);
|
87 |
|
|
}
|
88 |
d7f0c07d
|
Leszek Koltunski
|
|
89 |
b4cbe056
|
Leszek Koltunski
|
MeshJoined wholeMesh = new MeshJoined(mesh);
|
90 |
|
|
|
91 |
|
|
// effects: main ///////////////////////////////////////////////
|
92 |
|
|
DistortedEffects effects = new DistortedEffects();
|
93 |
|
|
|
94 |
|
|
float scaleM = mWidth*0.3f;
|
95 |
|
|
float scaleP = mWidth*0.1f;
|
96 |
|
|
|
97 |
|
|
Static3D moveM = new Static3D(0,0,1);
|
98 |
d7f0c07d
|
Leszek Koltunski
|
Static1D point0 = new Static1D(0);
|
99 |
|
|
Static1D point360 = new Static1D(360);
|
100 |
|
|
Dynamic1D angle = new Dynamic1D();
|
101 |
|
|
angle.add(point0);
|
102 |
|
|
angle.add(point360);
|
103 |
90f78d6b
|
Leszek Koltunski
|
angle.setCount(0.5f);
|
104 |
b4cbe056
|
Leszek Koltunski
|
angle.setDuration(DUR_ALL);
|
105 |
d7f0c07d
|
Leszek Koltunski
|
Static3D axis = new Static3D(0,0,1);
|
106 |
|
|
Static3D center = new Static3D(0,0,0);
|
107 |
|
|
|
108 |
b4cbe056
|
Leszek Koltunski
|
VertexEffectMove mainMove = new VertexEffectMove(moveM);
|
109 |
|
|
VertexEffectScale mainScale = new VertexEffectScale(scaleM);
|
110 |
|
|
VertexEffectRotate mainRotate = new VertexEffectRotate(angle,axis,center);
|
111 |
|
|
mainMove.setMeshAssociation(2,0);
|
112 |
|
|
mainScale.setMeshAssociation(2,0);
|
113 |
|
|
mainRotate.setMeshAssociation(2,0);
|
114 |
|
|
mainRotate.notifyWhenFinished(this);
|
115 |
|
|
|
116 |
|
|
// effects: moving stars ///////////////////////////////////////
|
117 |
|
|
VertexEffectScale scaleE = new VertexEffectScale(scaleP);
|
118 |
|
|
scaleE.setMeshAssociation(1,-1);
|
119 |
|
|
effects.apply(scaleE);
|
120 |
|
|
|
121 |
|
|
for(int i=1; i<newS+1; i++)
|
122 |
|
|
{
|
123 |
|
|
Dynamic3D moveP = createRandomMove();
|
124 |
|
|
VertexEffectMove moveE= new VertexEffectMove(moveP);
|
125 |
|
|
moveE.setMeshAssociation(2,i);
|
126 |
|
|
effects.apply(moveE);
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
// main effect queue ///////////////////////////////////////////
|
130 |
|
|
effects.apply(mainMove);
|
131 |
|
|
effects.apply(mainScale);
|
132 |
|
|
effects.apply(mainRotate);
|
133 |
|
|
|
134 |
|
|
return new DistortedNode(texture,effects,wholeMesh);
|
135 |
d7f0c07d
|
Leszek Koltunski
|
}
|
136 |
|
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
|
139 |
|
|
public long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data)
|
140 |
|
|
{
|
141 |
b4cbe056
|
Leszek Koltunski
|
if( mRandom==null ) mRandom = new Random();
|
142 |
|
|
|
143 |
d7f0c07d
|
Leszek Koltunski
|
mScreen = screen;
|
144 |
|
|
mListener= listener;
|
145 |
|
|
DataStars stars = (DataStars)data;
|
146 |
|
|
int totS = stars.getTotal();
|
147 |
|
|
int newS = stars.getNew();
|
148 |
|
|
Resources res = stars.getResources();
|
149 |
|
|
|
150 |
b4cbe056
|
Leszek Koltunski
|
mWidth = mScreen.getWidth();
|
151 |
|
|
mHeight= mScreen.getHeight();
|
152 |
|
|
|
153 |
d7f0c07d
|
Leszek Koltunski
|
mNode = createNode(res,totS,newS);
|
154 |
b4cbe056
|
Leszek Koltunski
|
mNode.glDepthMask(false);
|
155 |
|
|
mNode.glStencilMask(0);
|
156 |
|
|
mNode.enableDepthStencil(InternalOutputSurface.NO_DEPTH_NO_STENCIL);
|
157 |
d7f0c07d
|
Leszek Koltunski
|
mScreen.attach(mNode);
|
158 |
|
|
|
159 |
|
|
return 0;
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
|
|
public void effectFinished(long id)
|
165 |
|
|
{
|
166 |
|
|
mScreen.detach(mNode);
|
167 |
|
|
mListener.overlayFinished(id);
|
168 |
|
|
}
|
169 |
b4cbe056
|
Leszek Koltunski
|
|
170 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171 |
|
|
|
172 |
|
|
@SuppressWarnings("unused")
|
173 |
|
|
public static void enableEffects()
|
174 |
|
|
{
|
175 |
|
|
VertexEffectMove.enable();
|
176 |
|
|
VertexEffectScale.enable();
|
177 |
|
|
VertexEffectRotate.enable();
|
178 |
|
|
}
|
179 |
d7f0c07d
|
Leszek Koltunski
|
}
|