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