Project

General

Profile

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

examples / src / main / java / org / distorted / examples / wind / WindEffectsManager.java @ 21819119

1 815687bb Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 21819119 Leszek Koltunski
import org.distorted.library.type.Dynamic3D;
26
import org.distorted.library.type.Static3D;
27 815687bb Leszek Koltunski
28
class WindEffectsManager
29
  {
30 21819119 Leszek Koltunski
  private Static3D shearFactor;
31
  private Dynamic3D shearDynamic;
32
  private Static3D scaleFactor;
33
  private Dynamic3D scaleDynamic;
34 815687bb Leszek Koltunski
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 21819119 Leszek Koltunski
  WindEffectsManager()
38 815687bb Leszek Koltunski
    {
39 21819119 Leszek Koltunski
    shearFactor = new Static3D(0,0,0);
40
    shearDynamic= new Dynamic3D();
41
    shearDynamic.add(shearFactor);
42 815687bb Leszek Koltunski
43 21819119 Leszek Koltunski
    scaleFactor = new Static3D(1,1,1);
44
    scaleDynamic= new Dynamic3D();
45
    scaleDynamic.add(scaleFactor);
46
    }
47
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49
50
  synchronized void apply(DistortedObject obj, int wind)
51
    {
52
    Static3D center = new Static3D(0,obj.getHeight()/2,0);
53
    setWind(wind);
54
55
    obj.shear(shearDynamic,center);
56
    obj.scale(scaleDynamic);
57
    }
58
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61
  synchronized void setWind(int wind)
62
    {
63
    float tanAngle = (wind-50)/50.0f;
64
65
    shearFactor.set2(tanAngle);
66
    scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle));
67 815687bb Leszek Koltunski
    }
68
  }