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 |
|
|
import org.distorted.library.effect.MatrixEffectRotate;
|
17 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
18 |
|
|
import org.distorted.library.main.DistortedEffects;
|
19 |
|
|
import org.distorted.library.main.DistortedNode;
|
20 |
|
|
import org.distorted.library.main.DistortedScreen;
|
21 |
|
|
import org.distorted.library.main.DistortedTexture;
|
22 |
|
|
import org.distorted.library.mesh.MeshQuad;
|
23 |
|
|
import org.distorted.library.message.EffectListener;
|
24 |
|
|
import org.distorted.library.type.Dynamic1D;
|
25 |
|
|
import org.distorted.library.type.Static1D;
|
26 |
|
|
import org.distorted.library.type.Static3D;
|
27 |
|
|
import org.distorted.main.R;
|
28 |
|
|
|
29 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30 |
|
|
|
31 |
|
|
public class OverlayStars extends OverlayGeneric implements EffectListener
|
32 |
|
|
{
|
33 |
|
|
private ListenerOverlay mListener;
|
34 |
|
|
private DistortedNode mNode;
|
35 |
|
|
private DistortedScreen mScreen;
|
36 |
|
|
|
37 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38 |
|
|
|
39 |
|
|
private DistortedNode createNode(Resources res, int totS, int newS)
|
40 |
|
|
{
|
41 |
|
|
Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.star);
|
42 |
|
|
DistortedTexture texture = new DistortedTexture();
|
43 |
|
|
texture.setTexture(bmp);
|
44 |
|
|
|
45 |
|
|
float scale = 10;
|
46 |
|
|
|
47 |
|
|
Static1D point0 = new Static1D(0);
|
48 |
|
|
Static1D point360 = new Static1D(360);
|
49 |
|
|
Dynamic1D angle = new Dynamic1D();
|
50 |
|
|
angle.add(point0);
|
51 |
|
|
angle.add(point360);
|
52 |
|
|
angle.setCount(1.0f);
|
53 |
|
|
angle.setDuration(5000);
|
54 |
|
|
Static3D axis = new Static3D(0,0,1);
|
55 |
|
|
Static3D center = new Static3D(0,0,0);
|
56 |
|
|
|
57 |
|
|
DistortedEffects effects = new DistortedEffects();
|
58 |
|
|
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
|
59 |
|
|
MatrixEffectRotate rotateEffect = new MatrixEffectRotate(angle,axis,center);
|
60 |
|
|
effects.apply(scaleEffect);
|
61 |
|
|
effects.apply(rotateEffect);
|
62 |
|
|
|
63 |
|
|
rotateEffect.notifyWhenFinished(this);
|
64 |
|
|
|
65 |
|
|
MeshQuad mesh = new MeshQuad();
|
66 |
|
|
|
67 |
|
|
return new DistortedNode(texture,effects,mesh);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
71 |
|
|
|
72 |
|
|
public long startOverlay(DistortedScreen screen, ListenerOverlay listener, DataGeneric data)
|
73 |
|
|
{
|
74 |
|
|
mScreen = screen;
|
75 |
|
|
mListener= listener;
|
76 |
|
|
DataStars stars = (DataStars)data;
|
77 |
|
|
int totS = stars.getTotal();
|
78 |
|
|
int newS = stars.getNew();
|
79 |
|
|
Resources res = stars.getResources();
|
80 |
|
|
|
81 |
|
|
mNode = createNode(res,totS,newS);
|
82 |
|
|
mScreen.attach(mNode);
|
83 |
|
|
|
84 |
|
|
return 0;
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88 |
|
|
|
89 |
|
|
public void effectFinished(long id)
|
90 |
|
|
{
|
91 |
|
|
mScreen.detach(mNode);
|
92 |
|
|
mListener.overlayFinished(id);
|
93 |
|
|
}
|
94 |
|
|
}
|