1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2016 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Distorted. //
|
5
|
// //
|
6
|
// Distorted 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
|
// Distorted 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 Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.examples.aroundtheworld;
|
21
|
|
22
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
23
|
|
24
|
import org.distorted.library.DistortedObject;
|
25
|
import org.distorted.library.type.Dynamic;
|
26
|
import org.distorted.library.type.Dynamic3D;
|
27
|
import org.distorted.library.type.Dynamic5D;
|
28
|
import org.distorted.library.type.Static3D;
|
29
|
import org.distorted.library.type.Static4D;
|
30
|
import org.distorted.library.type.Static5D;
|
31
|
|
32
|
class AroundTheWorldEffectsManager
|
33
|
{
|
34
|
private int mHeight, mWidth;
|
35
|
|
36
|
private Static3D shearFactor;
|
37
|
private Dynamic3D shearDynamic;
|
38
|
private Static3D scaleFactor;
|
39
|
private Dynamic3D scaleDynamic;
|
40
|
private Static3D deformForce;
|
41
|
private Static5D windFactor11, windFactor12;
|
42
|
private Dynamic5D windDynamic1;
|
43
|
private Static5D windFactor21, windFactor22;
|
44
|
private Dynamic5D windDynamic2;
|
45
|
private Static5D windFactor31, windFactor32;
|
46
|
private Dynamic5D windDynamic3;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
AroundTheWorldEffectsManager(DistortedObject obj)
|
51
|
{
|
52
|
mHeight = obj.getHeight();
|
53
|
mWidth = obj.getWidth();
|
54
|
|
55
|
shearFactor = new Static3D(0,0,0);
|
56
|
shearDynamic= new Dynamic3D();
|
57
|
shearDynamic.add(shearFactor);
|
58
|
|
59
|
scaleFactor = new Static3D(1,1,1);
|
60
|
scaleDynamic= new Dynamic3D();
|
61
|
scaleDynamic.add(scaleFactor);
|
62
|
|
63
|
deformForce = new Static3D(mWidth/3,0,0);
|
64
|
|
65
|
windFactor11 = new Static5D(mHeight/10,mHeight/5, 180, 0, 90);
|
66
|
windFactor12 = new Static5D(mHeight/10,mHeight/5,-180, 0, 90);
|
67
|
windDynamic1 = new Dynamic5D(1000,0.0f);
|
68
|
windDynamic1.add(windFactor11);
|
69
|
windDynamic1.add(windFactor12);
|
70
|
windDynamic1.setMode(Dynamic.MODE_JUMP);
|
71
|
windDynamic1.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
|
72
|
|
73
|
windFactor21 = new Static5D(mHeight/10,mHeight/5,-180, 90, 10);
|
74
|
windFactor22 = new Static5D(mHeight/10,mHeight/5,+180, 90, 10);
|
75
|
windDynamic2 = new Dynamic5D(1000,0.0f);
|
76
|
windDynamic2.add(windFactor21);
|
77
|
windDynamic2.add(windFactor22);
|
78
|
windDynamic2.setMode(Dynamic.MODE_JUMP);
|
79
|
windDynamic2.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
|
80
|
|
81
|
windFactor31 = new Static5D(mHeight/10,mHeight/10,-180, 90, 90);
|
82
|
windFactor32 = new Static5D(mHeight/10,mHeight/10,+180, 90, 90);
|
83
|
windDynamic3 = new Dynamic5D(1000,0.0f);
|
84
|
windDynamic3.add(windFactor31);
|
85
|
windDynamic3.add(windFactor32);
|
86
|
windDynamic3.setMode(Dynamic.MODE_JUMP);
|
87
|
windDynamic3.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
synchronized void apply(DistortedObject obj, int wind)
|
93
|
{
|
94
|
Static3D midLeft = new Static3D(0,mHeight/2,0);
|
95
|
Static3D midRight = new Static3D(mWidth,mHeight/2,0);
|
96
|
Static4D windRegion = new Static4D(0,0,mWidth,mHeight);
|
97
|
|
98
|
setWind(wind);
|
99
|
|
100
|
obj.shear(shearDynamic,midLeft);
|
101
|
obj.scale(scaleDynamic);
|
102
|
obj.deform(deformForce,midRight);
|
103
|
obj.wave(windDynamic1, midRight, windRegion);
|
104
|
obj.wave(windDynamic2, midRight, windRegion);
|
105
|
obj.wave(windDynamic3, midRight, windRegion);
|
106
|
}
|
107
|
|
108
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109
|
|
110
|
synchronized void setWind(int wind)
|
111
|
{
|
112
|
float tanAngle = (wind-50)/50.0f;
|
113
|
|
114
|
shearFactor.set2(tanAngle);
|
115
|
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle));
|
116
|
windDynamic1.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
|
117
|
windDynamic2.setDuration( wind > 0 ? 80000/wind : Long.MAX_VALUE);
|
118
|
windDynamic3.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
|
119
|
|
120
|
float waveA = (mHeight/(20.0f-0.15f*wind));
|
121
|
windFactor21.set1(waveA);
|
122
|
windFactor22.set1(waveA);
|
123
|
|
124
|
float waveB = (mHeight/(wind+5.0f));
|
125
|
windFactor31.set1(waveB);
|
126
|
windFactor32.set1(waveB);
|
127
|
}
|
128
|
}
|