1 |
da56b12f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 org.distorted.library.effect.MatrixEffectMove;
|
23 |
|
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
24 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
25 |
|
|
import org.distorted.library.main.DistortedEffects;
|
26 |
|
|
import org.distorted.library.main.DistortedNode;
|
27 |
|
|
import org.distorted.library.main.DistortedTexture;
|
28 |
|
|
import org.distorted.library.mesh.MeshBase;
|
29 |
|
|
import org.distorted.library.type.Static3D;
|
30 |
|
|
import org.distorted.library.type.Static4D;
|
31 |
|
|
import org.distorted.objectlib.helpers.FactoryBandaged3x3Cubit;
|
32 |
|
|
|
33 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
public class BandagedCubit
|
36 |
|
|
{
|
37 |
|
|
private static final Static3D CENTER = new Static3D(0,0,0);
|
38 |
|
|
|
39 |
|
|
private final DistortedNode mNode;
|
40 |
|
|
private final DistortedTexture mTexture;
|
41 |
|
|
private final DistortedEffects mEffects;
|
42 |
|
|
private final MeshBase mMesh;
|
43 |
|
|
private final float[] mPosition;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
|
|
private Static3D computeMove(float[] position)
|
48 |
|
|
{
|
49 |
|
|
int numCenters = position.length/3;
|
50 |
|
|
float totalX=0.0f, totalY=0.0f, totalZ=0.0f;
|
51 |
|
|
|
52 |
|
|
for(int center=0; center<numCenters; center++)
|
53 |
|
|
{
|
54 |
|
|
totalX += position[3*center ];
|
55 |
|
|
totalY += position[3*center+1];
|
56 |
|
|
totalZ += position[3*center+2];
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
totalX /= numCenters;
|
60 |
|
|
totalY /= numCenters;
|
61 |
|
|
totalZ /= numCenters;
|
62 |
|
|
|
63 |
|
|
return new Static3D(totalX,totalY,totalZ);
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67 |
|
|
// PUBLIC API
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
|
70 |
77efd5ad
|
Leszek Koltunski
|
public BandagedCubit(float[] position, Static4D quat1, Static4D quat2, Static3D scale)
|
71 |
da56b12f
|
Leszek Koltunski
|
{
|
72 |
|
|
mPosition = position;
|
73 |
|
|
|
74 |
|
|
FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
|
75 |
|
|
mMesh = factory.createMesh(position);
|
76 |
|
|
|
77 |
|
|
mTexture = new DistortedTexture();
|
78 |
77efd5ad
|
Leszek Koltunski
|
mTexture.setColorARGB(0xffffff55);
|
79 |
da56b12f
|
Leszek Koltunski
|
|
80 |
|
|
Static3D move = computeMove(position);
|
81 |
|
|
|
82 |
77efd5ad
|
Leszek Koltunski
|
MatrixEffectScale scaleEffect = new MatrixEffectScale(scale);
|
83 |
|
|
MatrixEffectQuaternion quat1Effect = new MatrixEffectQuaternion(quat2, CENTER);
|
84 |
|
|
MatrixEffectQuaternion quat2Effect = new MatrixEffectQuaternion(quat1, CENTER);
|
85 |
da56b12f
|
Leszek Koltunski
|
MatrixEffectMove moveEffect = new MatrixEffectMove(move);
|
86 |
|
|
|
87 |
|
|
mEffects = new DistortedEffects();
|
88 |
|
|
mEffects.apply(quat1Effect);
|
89 |
|
|
mEffects.apply(quat2Effect);
|
90 |
|
|
mEffects.apply(scaleEffect);
|
91 |
|
|
mEffects.apply(moveEffect);
|
92 |
|
|
|
93 |
|
|
mNode = new DistortedNode(mTexture,mEffects,mMesh);
|
94 |
|
|
}
|
95 |
|
|
|
96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
97 |
|
|
|
98 |
|
|
public DistortedNode getNode()
|
99 |
|
|
{
|
100 |
|
|
return mNode;
|
101 |
|
|
}
|
102 |
|
|
}
|