Project

General

Profile

Download (5.68 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / wind / WindEffectsManager.java @ 107e4b72

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.effect.MatrixEffectScale;
25
import org.distorted.library.effect.MatrixEffectShear;
26
import org.distorted.library.effect.VertexEffectDeform;
27
import org.distorted.library.effect.VertexEffectWave;
28
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.type.Dynamic;
31
import org.distorted.library.type.Dynamic5D;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.library.type.Static5D;
35

    
36
class WindEffectsManager
37
  {
38
  private int mHeight, mWidth;
39

    
40
  private Static3D  shearFactor;
41
  private Static3D  scaleFactor;
42
  private Static3D  deformForce;
43
  private Static5D  windFactor11, windFactor12;
44
  private Dynamic5D windDynamic1;
45
  private Static5D  windFactor21, windFactor22;
46
  private Dynamic5D windDynamic2;
47
  private Static5D  windFactor31, windFactor32;
48
  private Dynamic5D windDynamic3;
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

    
52
  WindEffectsManager(DistortedTexture texture)
53
    {
54
    mHeight = texture.getHeight();
55
    mWidth  = texture.getWidth();
56

    
57
    shearFactor = new Static3D(0,0,0);
58
    scaleFactor = new Static3D(1,1,1);
59
    deformForce = new Static3D(mWidth/3,0,0);
60

    
61
    windFactor11 = new Static5D(mHeight/10,mHeight/5, 180, 0, 90);
62
    windFactor12 = new Static5D(mHeight/10,mHeight/5,-180, 0, 90);
63
    windDynamic1 = new Dynamic5D(1000,0.0f);
64
    windDynamic1.add(windFactor11);
65
    windDynamic1.add(windFactor12);
66
    windDynamic1.setMode(Dynamic.MODE_JUMP);
67
    windDynamic1.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
68

    
69
    windFactor21 = new Static5D(mHeight/10,mHeight/5,-180, 90, 10);
70
    windFactor22 = new Static5D(mHeight/10,mHeight/5,+180, 90, 10);
71
    windDynamic2 = new Dynamic5D(1000,0.0f);
72
    windDynamic2.add(windFactor21);
73
    windDynamic2.add(windFactor22);
74
    windDynamic2.setMode(Dynamic.MODE_JUMP);
75
    windDynamic2.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
76

    
77
    windFactor31 = new Static5D(mHeight/10,mHeight/10,-180, 90, 90);
78
    windFactor32 = new Static5D(mHeight/10,mHeight/10,+180, 90, 90);
79
    windDynamic3 = new Dynamic5D(1000,0.0f);
80
    windDynamic3.add(windFactor31);
81
    windDynamic3.add(windFactor32);
82
    windDynamic3.setMode(Dynamic.MODE_JUMP);
83
    windDynamic3.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
84
    }
85

    
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

    
88
  void apply(DistortedEffects effects, int wind)
89
    {
90
    Static3D midLeft = new Static3D(0,mHeight/2,0);
91
    Static3D midRight = new Static3D(mWidth,mHeight/2,0);
92
    Static4D windRegion = new Static4D(0,0,mWidth,mHeight);
93

    
94
    setWind(wind);
95

    
96
    effects.apply( new MatrixEffectShear(shearFactor,midLeft) );
97
    effects.apply( new MatrixEffectScale(scaleFactor) );
98
    effects.apply( new VertexEffectDeform(deformForce,midRight) );
99
    effects.apply( new VertexEffectWave(windDynamic1, midRight, windRegion) );
100
    effects.apply( new VertexEffectWave(windDynamic2, midRight, windRegion) );
101
    effects.apply( new VertexEffectWave(windDynamic3, midRight, windRegion) );
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  synchronized void setWind(int wind)
107
    {
108
    float tanAngle = (wind-50)/50.0f;
109

    
110
    shearFactor.set2(tanAngle);
111
    scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle));
112
    windDynamic1.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
113
    windDynamic2.setDuration( wind > 0 ?  80000/wind : Long.MAX_VALUE);
114
    windDynamic3.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
115

    
116
    float waveA = (mHeight/(20.0f-0.15f*wind));
117
    windFactor21.set1(waveA);
118
    windFactor22.set1(waveA);
119

    
120
    float waveB = (mHeight/(wind+5.0f));
121
    windFactor31.set1(waveB);
122
    windFactor32.set1(waveB);
123
    }
124
  }
(2-2/4)