Project

General

Profile

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

examples / src / main / java / org / distorted / examples / aroundtheworld / AroundTheWorldEffectsManager.java @ acd5fc11

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.Dynamic1D;
27
import org.distorted.library.type.Dynamic2D;
28
import org.distorted.library.type.Dynamic3D;
29
import org.distorted.library.type.Dynamic5D;
30
import org.distorted.library.type.Static1D;
31
import org.distorted.library.type.Static2D;
32
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
import org.distorted.library.type.Static5D;
35

    
36
class AroundTheWorldEffectsManager
37
  {
38
  private float mWhiteness, mBlackness, mAsianness;  // those always sum up to 1
39

    
40
  // WHITENESS
41
  // Vertex effects:
42
  // a) make the lips smaller (SINK)
43
  private Static4D wRegionLips;
44
  private Static3D wCenterLips;
45
  private Static1D wLipsFactor;
46
  private Dynamic1D wLipsDyn;
47

    
48
  // ASIANNESS
49
  // Vertex Effects:
50
  // a) move lips & nose higher (DISTORT)
51
  private Static4D aRegionLipsNose;
52
  private Static3D aCenterLipsNose;
53
  private Static3D aLipsNoseFactor;
54
  private Dynamic3D aLipsNoseDyn;
55
  // b) make the nose broader (PINCH)
56
  private Static4D aRegionNoseBroader;
57
  private Static3D aCenterNoseBroader;
58
  private Static2D aNoseBroaderFactor;
59
  private Dynamic2D aNoseBroaderDyn;
60
  // c) make the nostrils more visible (DISTORT)
61
  private Static4D aRegionNostrils;
62
  private Static3D aCenterNostrils;
63
  private Static3D aNostrilsFactor;
64
  private Dynamic3D aNostrilsDyn;
65
  // d) rotate eyes (2 x SWIRL)
66
  private Static4D aRegionEyes;
67
  private Static3D aCenterLEye, aCenterREye;
68
  private Static1D aLEyeFactor, aREyeFactor;
69
  private Dynamic1D aLEyeDyn, aREyeDyn;
70
  // e) move eyebrow higher (DISTORT)
71
  private Static4D aRegionEyebrows;
72
  private Static3D aCenterEyebrows;
73
  private Static3D aEyebrowsFactor;
74
  private Dynamic3D aEyebrowsDyn;
75

    
76
  // Fragment effects:
77
  // a) change color of the skin to more brown and less red (CHROMA)
78
  private Static4D aRegionSkinColor;
79
  private Static3D aChromaSkin;
80
  private Static1D aChromaSkinFactor;
81
  private Dynamic1D aChromaSkinDyn;
82
  // b) darken both eyes (2 x SMOOTH_CHROMA)
83
  private Static4D aRegionLEyeColor, aRegionREyeColor;
84
  private Static3D aChromaEyes;
85
  private Static1D aChromaEyesFactor;
86
  private Dynamic1D aChromaEyesDyn;
87

    
88
  // BLACKNESS
89

    
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

    
92
  AroundTheWorldEffectsManager()
93
    {
94
    mWhiteness = 1;
95
    mBlackness = 0;
96
    mAsianness = 0;
97

    
98
    // WHITENESS
99
    // Vertex Effects
100
    wRegionLips = new Static4D(0,0,100,100);
101
    wCenterLips = new Static3D(300,500,0);
102
    wLipsFactor = new Static1D(0.7f);
103
    wLipsDyn    = new Dynamic1D();
104
    wLipsDyn.add(wLipsFactor);
105

    
106
    // ASIANNESS
107
    // Vertex Effects
108
    aRegionLipsNose    = new Static4D(0,0,267,267);
109
    aCenterLipsNose    = new Static3D(300,560,0);
110
    aLipsNoseDyn       = new Dynamic3D();
111
    aLipsNoseFactor    = new Static3D(0,0,0);
112
    aLipsNoseDyn.add(aLipsNoseFactor);
113

    
114
    aRegionNoseBroader = new Static4D(0,0,130,130);
115
    aCenterNoseBroader = new Static3D(300,307,0);
116
    aNoseBroaderDyn    = new Dynamic2D();
117
    aNoseBroaderFactor = new Static2D(0,90);
118
    aNoseBroaderDyn.add(aNoseBroaderFactor);
119

    
120
    aRegionNostrils    = new Static4D(0,0,60,60);
121
    aCenterNostrils    = new Static3D(300,336,0);
122
    aNostrilsDyn       = new Dynamic3D();
123
    aNostrilsFactor    = new Static3D(0,0,0);
124
    aNostrilsDyn.add(aNostrilsFactor);
125

    
126
    aRegionEyes        = new Static4D(0,0,83,83);
127
    aCenterLEye        = new Static3D(176,230,0);
128
    aCenterREye        = new Static3D(420,230,0);
129
    aLEyeDyn           = new Dynamic1D();
130
    aREyeDyn           = new Dynamic1D();
131
    aLEyeFactor        = new Static1D(0);
132
    aREyeFactor        = new Static1D(0);
133
    aLEyeDyn.add(aLEyeFactor);
134
    aREyeDyn.add(aREyeFactor);
135

    
136
    aRegionEyebrows    = new Static4D(0,0,142,142);
137
    aCenterEyebrows    = new Static3D(300,100,0);
138
    aEyebrowsDyn       = new Dynamic3D();
139
    aEyebrowsFactor    = new Static3D(0,0,0);
140
    aEyebrowsDyn.add(aEyebrowsFactor);
141

    
142
    // Fragment Effects
143
    aRegionSkinColor   = new Static4D(300,300,600,600);
144
    aRegionLEyeColor   = new Static4D(172,230,29,25);
145
    aRegionREyeColor   = new Static4D(423,230,29,25);
146

    
147
    aChromaSkin        = new Static3D(0.5f, 0.5f, 0.5f);
148
    aChromaEyes        = new Static3D(0.5f, 0.14f, 0.14f);
149
    aChromaSkinFactor  = new Static1D(0.0f);
150
    aChromaEyesFactor  = new Static1D(0.0f);
151

    
152
    aChromaSkinDyn = new Dynamic1D();
153
    aChromaSkinDyn.add(aChromaSkinFactor);
154
    aChromaEyesDyn = new Dynamic1D();
155
    aChromaEyesDyn.add(aChromaEyesFactor);
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  synchronized void apply(DistortedObject obj)
161
    {
162
    setRace(mBlackness, mAsianness);
163

    
164
    // WHITENESS
165
    obj.sink(wLipsDyn, wCenterLips, wRegionLips);
166

    
167
    // ASIANNESS
168
    obj.distort(aLipsNoseDyn, aCenterLipsNose, aRegionLipsNose);
169
    obj.pinch(aNoseBroaderDyn, aCenterNoseBroader, aRegionNoseBroader);
170
    obj.distort(aNostrilsDyn, aCenterNostrils, aRegionNostrils);
171
    obj.swirl(aLEyeDyn, aCenterLEye, aRegionEyes);
172
    obj.swirl(aREyeDyn, aCenterREye, aRegionEyes);
173
    obj.distort(aEyebrowsDyn, aCenterEyebrows, aRegionEyebrows);
174

    
175
    obj.chroma(aChromaSkinDyn, aChromaSkin, aRegionSkinColor, false);
176
    obj.chroma(aChromaEyesDyn, aChromaEyes, aRegionLEyeColor, true);
177
    obj.chroma(aChromaEyesDyn, aChromaEyes, aRegionREyeColor, true);
178

    
179
    // BLACKNESS
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  synchronized void setRace(float blackness, float asianness)
185
    {
186
    mWhiteness = 1 - blackness - asianness;
187
    mBlackness = blackness;
188
    mAsianness = asianness;
189

    
190
    //android.util.Log.e("manager", "blackness="+blackness+" asianness="+asianness);
191

    
192
    // WHITENESS
193
    wLipsFactor.set(1.0f-0.3f*mWhiteness);
194

    
195
    // ASIANNESS
196
    aLipsNoseFactor.set2(-23.0f*mAsianness);
197
    aNoseBroaderFactor.set1(1.0f+0.92f*mAsianness);
198
    aNostrilsFactor.set2(-12.0f*mAsianness);
199
    aLEyeFactor.set(+20.0f*mAsianness);
200
    aREyeFactor.set(-20.0f*mAsianness);
201
    aEyebrowsFactor.set2(-40.0f*mAsianness);
202

    
203
    aChromaSkinFactor.set(0.2f*mAsianness);
204
    aChromaEyesFactor.set(0.7f*mAsianness);
205

    
206
    // BLACKNESS
207
    }
208
  }
(2-2/6)