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.wind;
|
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 WindEffectsManager
|
33
|
{
|
34
|
private Static3D shearFactor;
|
35
|
private Dynamic3D shearDynamic;
|
36
|
private Static3D scaleFactor;
|
37
|
private Dynamic3D scaleDynamic;
|
38
|
private Static3D deformForce;
|
39
|
private Static5D windFactor1, windFactor2;
|
40
|
private Dynamic5D windDynamic;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
WindEffectsManager(DistortedObject obj)
|
45
|
{
|
46
|
int h = obj.getHeight();
|
47
|
int w = obj.getWidth();
|
48
|
|
49
|
shearFactor = new Static3D(0,0,0);
|
50
|
shearDynamic= new Dynamic3D();
|
51
|
shearDynamic.add(shearFactor);
|
52
|
|
53
|
scaleFactor = new Static3D(1,1,1);
|
54
|
scaleDynamic= new Dynamic3D();
|
55
|
scaleDynamic.add(scaleFactor);
|
56
|
|
57
|
deformForce = new Static3D(w/3,0,0);
|
58
|
|
59
|
windFactor1 = new Static5D(h/10,h/5, 180, 0, 90);
|
60
|
windFactor2 = new Static5D(h/10,h/5,-180, 0, 90);
|
61
|
windDynamic = new Dynamic5D(1000,0.0f);
|
62
|
windDynamic.add(windFactor1);
|
63
|
windDynamic.add(windFactor2);
|
64
|
windDynamic.setMode(Dynamic.MODE_JUMP);
|
65
|
}
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
synchronized void apply(DistortedObject obj, int wind)
|
70
|
{
|
71
|
int h = obj.getHeight();
|
72
|
int w = obj.getWidth();
|
73
|
|
74
|
Static3D midLeft = new Static3D(0,h/2,0);
|
75
|
Static3D midRight = new Static3D(w,h/2,0);
|
76
|
Static4D windRegion = new Static4D(0,0,w,h);
|
77
|
|
78
|
setWind(wind);
|
79
|
|
80
|
obj.shear(shearDynamic,midLeft);
|
81
|
obj.scale(scaleDynamic);
|
82
|
obj.deform(deformForce,midRight);
|
83
|
obj.wave(windDynamic, midRight, windRegion);
|
84
|
}
|
85
|
|
86
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87
|
|
88
|
synchronized void setWind(int wind)
|
89
|
{
|
90
|
float tanAngle = (wind-50)/50.0f;
|
91
|
|
92
|
shearFactor.set2(tanAngle);
|
93
|
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle));
|
94
|
windDynamic.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
|
95
|
}
|
96
|
}
|