1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.bandaged;
|
21
|
|
22
|
import android.opengl.GLSurfaceView;
|
23
|
|
24
|
import org.distorted.library.main.DistortedLibrary;
|
25
|
import org.distorted.library.main.DistortedNode;
|
26
|
import org.distorted.library.main.DistortedScreen;
|
27
|
import org.distorted.library.type.Static4D;
|
28
|
|
29
|
import javax.microedition.khronos.egl.EGLConfig;
|
30
|
import javax.microedition.khronos.opengles.GL10;
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
|
35
|
{
|
36
|
private final BandagedCreatorView mView;
|
37
|
private final DistortedScreen mScreen;
|
38
|
|
39
|
private final BandagedCubit[] mCubits;
|
40
|
|
41
|
private float[][] POSITIONS = new float[][]
|
42
|
{
|
43
|
{-1.0f, +1.0f, +1.0f},
|
44
|
{-1.0f, +1.0f, +0.0f},
|
45
|
{-1.0f, +1.0f, -1.0f},
|
46
|
{-1.0f, 0.0f, +1.0f},
|
47
|
{-1.0f, 0.0f, +0.0f},
|
48
|
{-1.0f, 0.0f, -1.0f},
|
49
|
{-1.0f, -1.0f, +1.0f},
|
50
|
{-1.0f, -1.0f, +0.0f},
|
51
|
{-1.0f, -1.0f, -1.0f},
|
52
|
{ 0.0f, -1.0f, +1.0f},
|
53
|
{ 0.0f, -1.0f, +0.0f},
|
54
|
{ 0.0f, +1.0f, +1.0f},
|
55
|
{ 0.0f, +1.0f, +0.0f},
|
56
|
{ 0.0f, +1.0f, -1.0f},
|
57
|
{ 0.0f, 0.0f, +1.0f},
|
58
|
{ 0.0f, 0.0f, -1.0f},
|
59
|
{ 1.0f, +1.0f, +1.0f},
|
60
|
{ 1.0f, +1.0f, +0.0f},
|
61
|
{ 1.0f, +1.0f, -1.0f},
|
62
|
{ 1.0f, 0.0f, +1.0f},
|
63
|
{ 1.0f, 0.0f, +0.0f},
|
64
|
{ 1.0f, -1.0f, +1.0f},
|
65
|
{ 1.0f, 0.0f, -1.0f },
|
66
|
{ 1.0f, -1.0f, -1.0f },
|
67
|
{ 1.0f, -1.0f, +0.0f },
|
68
|
{ 0.0f, -1.0f, -1.0f },
|
69
|
};
|
70
|
|
71
|
Static4D mQuat1, mQuat2;
|
72
|
int mScreenMin;
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
BandagedCreatorRenderer(BandagedCreatorView v)
|
77
|
{
|
78
|
final float BRIGHTNESS = 0.333f;
|
79
|
|
80
|
mQuat1 = new Static4D(0,0,0,1);
|
81
|
mQuat2 = new Static4D(0,0,0,1);
|
82
|
|
83
|
mView = v;
|
84
|
mScreen = new DistortedScreen();
|
85
|
mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
|
86
|
|
87
|
mCubits = createCubits();
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
private BandagedCubit[] createCubits()
|
93
|
{
|
94
|
int len = POSITIONS.length;
|
95
|
BandagedCubit[] cubits = new BandagedCubit[len];
|
96
|
|
97
|
for(int c=0; c<len; c++)
|
98
|
{
|
99
|
cubits[c] = new BandagedCubit(POSITIONS[c],mQuat1,mQuat2,1.0f);
|
100
|
DistortedNode node = cubits[c].getNode();
|
101
|
mScreen.attach(node);
|
102
|
}
|
103
|
|
104
|
return cubits;
|
105
|
}
|
106
|
|
107
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108
|
|
109
|
@Override
|
110
|
public void onDrawFrame(GL10 glUnused)
|
111
|
{
|
112
|
long time = System.currentTimeMillis();
|
113
|
mScreen.render(time);
|
114
|
}
|
115
|
|
116
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117
|
|
118
|
@Override
|
119
|
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
120
|
{
|
121
|
mScreenMin = Math.min(width, height);
|
122
|
mScreen.resize(width,height);
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
@Override
|
128
|
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
129
|
{
|
130
|
DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
|
131
|
}
|
132
|
|
133
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134
|
|
135
|
public void distortedException(Exception ex)
|
136
|
{
|
137
|
android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
|
138
|
}
|
139
|
}
|