1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.objectlib.main;
|
21
|
|
22
|
import org.distorted.library.effect.MatrixEffectScale;
|
23
|
import org.distorted.library.main.DistortedEffects;
|
24
|
import org.distorted.library.main.DistortedNode;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
|
29
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
30
|
|
31
|
public class TwistyObjectNode extends DistortedNode
|
32
|
{
|
33
|
private final Static3D mScale;
|
34
|
private int mWidth, mHeight, mScaleFactor;
|
35
|
private float mCameraDist;
|
36
|
private float mObjectScale;
|
37
|
|
38
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39
|
|
40
|
public TwistyObjectNode(int surfaceW, int surfaceH)
|
41
|
{
|
42
|
super(new DistortedTexture(),new DistortedEffects(),new MeshSquare(20,20));
|
43
|
|
44
|
mObjectScale = 1.0f;
|
45
|
mScale= new Static3D(1,1,1);
|
46
|
setSize(surfaceW,surfaceH);
|
47
|
MatrixEffectScale scaleEffect = new MatrixEffectScale(mScale);
|
48
|
getEffects().apply(scaleEffect);
|
49
|
getMesh().setComponentCenter(0,0,0,-0.1f);
|
50
|
setFOV(60);
|
51
|
}
|
52
|
|
53
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
54
|
|
55
|
void setSize(int surfaceW, int surfaceH)
|
56
|
{
|
57
|
mWidth = surfaceW;
|
58
|
mHeight = surfaceH;
|
59
|
mScaleFactor= (int)(Math.min(mWidth,mHeight)*mObjectScale);
|
60
|
|
61
|
resizeFBO(mWidth,mHeight);
|
62
|
|
63
|
mScale.set(surfaceW,surfaceH,surfaceW);
|
64
|
}
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
float getCameraDist()
|
69
|
{
|
70
|
return mCameraDist;
|
71
|
}
|
72
|
|
73
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74
|
|
75
|
int getScaleFactor()
|
76
|
{
|
77
|
return mScaleFactor;
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
// PUBLIC API
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
|
84
|
public void setFOV(float fov)
|
85
|
{
|
86
|
double halfFOV = fov * (Math.PI/360);
|
87
|
mCameraDist = (0.5f*mHeight) / ((float)Math.tan(halfFOV)*mWidth);
|
88
|
setProjection( fov, 0.1f);
|
89
|
}
|
90
|
|
91
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
92
|
|
93
|
public void setScaleFactor(float scale)
|
94
|
{
|
95
|
mObjectScale = scale;
|
96
|
mScaleFactor = (int)(Math.min(mWidth,mHeight)*mObjectScale);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
public int getWidth()
|
102
|
{
|
103
|
return mWidth;
|
104
|
}
|
105
|
|
106
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
107
|
|
108
|
public int getHeight()
|
109
|
{
|
110
|
return mHeight;
|
111
|
}
|
112
|
}
|