Project

General

Profile

« Previous | Next » 

Revision e7a26998

Added by Leszek Koltunski about 8 years ago

Progress with WindManager.

View differences:

src/main/java/org/distorted/examples/wind/WindEffectsManager.java
31 31

  
32 32
class WindEffectsManager
33 33
  {
34
  private int mHeight, mWidth;
35

  
34 36
  private Static3D  shearFactor;
35 37
  private Dynamic3D shearDynamic;
36 38
  private Static3D  scaleFactor;
37 39
  private Dynamic3D scaleDynamic;
38 40
  private Static3D  deformForce;
39
  private Static5D  windFactor1, windFactor2;
40
  private Dynamic5D windDynamic;
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;
41 47

  
42 48
///////////////////////////////////////////////////////////////////////////////////////////////////
43 49

  
44 50
  WindEffectsManager(DistortedObject obj)
45 51
    {
46
    int h = obj.getHeight();
47
    int w = obj.getWidth();
52
    mHeight = obj.getHeight();
53
    mWidth  = obj.getWidth();
48 54

  
49 55
    shearFactor = new Static3D(0,0,0);
50 56
    shearDynamic= new Dynamic3D();
......
54 60
    scaleDynamic= new Dynamic3D();
55 61
    scaleDynamic.add(scaleFactor);
56 62

  
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
    windDynamic.setAccessMode(Dynamic.ACCESS_SEQUENTIAL);
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);
66 88
    }
67 89

  
68 90
///////////////////////////////////////////////////////////////////////////////////////////////////
69 91

  
70 92
  synchronized void apply(DistortedObject obj, int wind)
71 93
    {
72
    int h = obj.getHeight();
73
    int w = obj.getWidth();
74

  
75
    Static3D midLeft = new Static3D(0,h/2,0);
76
    Static3D midRight = new Static3D(w,h/2,0);
77
    Static4D windRegion = new Static4D(0,0,w,h);
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);
78 97

  
79 98
    setWind(wind);
80 99

  
81 100
    obj.shear(shearDynamic,midLeft);
82 101
    obj.scale(scaleDynamic);
83 102
    obj.deform(deformForce,midRight);
84
    obj.wave(windDynamic, midRight, windRegion);
103
    obj.wave(windDynamic1, midRight, windRegion);
104
    obj.wave(windDynamic2, midRight, windRegion);
105
    obj.wave(windDynamic3, midRight, windRegion);
85 106
    }
86 107

  
87 108
///////////////////////////////////////////////////////////////////////////////////////////////////
......
92 113

  
93 114
    shearFactor.set2(tanAngle);
94 115
    scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle));
95
    windDynamic.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE);
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);
96 127
    }
97 128
  }

Also available in: Unified diff