28 |
|
|
29 |
public class VobCSGenerator { |
public class VobCSGenerator { |
30 |
static public boolean dbg=false; |
static public boolean dbg=false; |
31 |
|
static public void p(String s) { System.out.print(s); } |
32 |
static public void pa(String s) { System.out.println(s); } |
static public void pa(String s) { System.out.println(s); } |
33 |
|
|
34 |
static public final int HORIZONTAL = 1; |
static public final int HORIZONTAL = 1; |
35 |
static public final int VERTICAL = 2; |
static public final int VERTICAL = 2; |
36 |
|
|
37 |
|
public float biggest_percent = 0.5f; |
38 |
|
public float percent_of_predecessor = 0.7f; |
39 |
|
public float smallest_percent = 0.2f; |
40 |
|
|
41 |
|
|
42 |
private int vob_cs[][]; |
private int vob_cs[][]; |
43 |
|
|
44 |
|
|
47 |
* focus_index begins from 0 |
* focus_index begins from 0 |
48 |
* or -1 if focus in home paper. |
* or -1 if focus in home paper. |
49 |
*/ |
*/ |
50 |
public VobCSGenerator(VobScene vs, int cs_into, int vob_count, int focus_index, float vob_width, float vob_height) { |
public VobCSGenerator(VobScene vs, int cs_into, int vob_count, |
51 |
|
int focus_index, float vob_width, float vob_height) { |
52 |
|
|
53 |
if (dbg) pa("Vobeja: "+ vob_count+" focus on: "+ focus_index); |
if (dbg) pa("Vobs: "+ vob_count+" focus on: "+ focus_index); |
54 |
if ( vob_count == 0) { |
if ( vob_count == 0) { |
55 |
pa("DEBUG: Might be an error - but there are no vob around!"); |
pa("DEBUG: Might be an error - but there are no vob around!"); |
56 |
return; |
return; |
57 |
} |
} |
58 |
|
|
59 |
|
|
60 |
// check out.. |
// check out.. -1 is exception |
61 |
if (focus_index == -1) focus_index++; |
if (focus_index == -1) focus_index++; |
62 |
if ( 0 <= focus_index && focus_index < vob_count); |
if ( 0 <= focus_index && focus_index < vob_count); |
63 |
else throw new Error("Focus out of vobs"); |
else throw new Error("Focus out of vobs"); |
65 |
GLVobCoorder glc = (GLVobCoorder)vs.coords; |
GLVobCoorder glc = (GLVobCoorder)vs.coords; |
66 |
|
|
67 |
// count how long the width is in given cs |
// count how long the width is in given cs |
68 |
float [] coords = { 0, 0,0, 1, 1,0 }; |
float [] coords = { 0,0,0, 1,1,0 }; |
69 |
float [] trans = new float[6]; |
float [] trans = new float[6]; |
70 |
|
|
71 |
glc.transformPoints3(cs_into, coords, trans); |
glc.transformPoints3(cs_into, coords, trans); |
72 |
float x_diff = trans[3] - trans[0]; |
float x_diff = trans[3] - trans[0]; |
73 |
float y_diff = trans[4] - trans[1]; |
float y_diff = trans[4] - trans[1]; |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
final int fake_count = 2 + vob_count; |
final int fake_count = 2 + vob_count; |
79 |
final int fake_focus = focus_index + 2; |
final int fake_focus = focus_index + 2; |
80 |
|
|
81 |
|
|
82 |
|
float spare_space = y_diff/vob_height - 1; |
83 |
|
pa("spare: " + spare_space); |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
float [] rations = new float[vob_count]; |
float [] rations = new float[vob_count]; |
91 |
float[] sigs = countSigmund(fake_focus); |
//float[] sigs = countSigmund(fake_focus); |
92 |
|
|
93 |
|
float[] sigs = countBoxAlgorithm(fake_focus/fake_count * spare_space, |
94 |
|
fake_focus, vob_height); |
95 |
|
|
96 |
|
|
97 |
for (int i=focus_index; i>=0; i--) { |
for (int i=focus_index; i>=0; i--) { |
98 |
rations[i] = sigs[focus_index-i]; |
rations[i] = sigs[focus_index-i]; |
99 |
} |
} |
100 |
|
|
101 |
sigs = countSigmund(fake_count - fake_focus); |
//sigs = countSigmund(fake_count - fake_focus); |
102 |
|
sigs = countBoxAlgorithm((fake_count - fake_focus)/fake_count * spare_space, |
103 |
|
fake_count-fake_focus, vob_height); |
104 |
for (int i=focus_index; i<vob_count; i++) { |
for (int i=focus_index; i<vob_count; i++) { |
105 |
rations[i] = sigs[Math.abs(focus_index - i)]; |
rations[i] = sigs[Math.abs(focus_index - i)]; |
106 |
} |
} |
107 |
|
|
108 |
|
//for (int i=0; i<vob_count; i++) { p("["+rations[i]+"],");} |
109 |
|
|
110 |
|
|
111 |
|
|
112 |
// focus is number ONE(the biggest) - "Uuno on numero yksi..." =) |
// focus is number ONE(the biggest) - "Uuno on numero yksi..." =) |
113 |
rations[focus_index] = 1.0f; |
rations[focus_index] = 1.0f; |
114 |
proportion(rations, focus_index, y_diff/vob_height ); |
//proportion(rations, focus_index, y_diff/vob_height ); |
|
|
|
115 |
|
|
116 |
for (int i=0; i<rations.length; i++) { |
for (int i=0; i<vob_count; i++) { |
117 |
if (dbg) pa(i+": "+ rations[i]); |
if (dbg) p("["+rations[i]+"],"); |
118 |
} |
} |
119 |
|
|
120 |
float sum = 0; |
float sum = 0; |
168 |
throw new Error("asked unknown CS: " + i); |
throw new Error("asked unknown CS: " + i); |
169 |
} |
} |
170 |
|
|
171 |
|
/** Easy algorithm |
172 |
|
*/ |
173 |
|
private float[] countBoxAlgorithm(float f, int count, float length) { |
174 |
|
|
175 |
|
if (count <= 1) return new float[]{ biggest_percent }; |
176 |
|
|
177 |
|
// first index is fake or smthng.. |
178 |
|
|
179 |
|
float[] retArray = new float[count]; |
180 |
|
retArray[1] = biggest_percent; |
181 |
|
|
182 |
|
float summ = retArray[1] * length; |
183 |
|
float percent = biggest_percent; |
184 |
|
int i= 2; |
185 |
|
|
186 |
|
while (summ < length && i < retArray.length) { |
187 |
|
retArray[i] = percent * percent_of_predecessor; |
188 |
|
if (retArray[i] < smallest_percent) |
189 |
|
retArray[i] = smallest_percent; |
190 |
|
|
191 |
|
summ += retArray[i] * length; |
192 |
|
percent = retArray[i]; |
193 |
|
i++; |
194 |
|
} |
195 |
|
|
196 |
|
for (int j=i; j<retArray.length; j++) { |
197 |
|
retArray[j] = 0; |
198 |
|
} |
199 |
|
|
200 |
|
return retArray; |
201 |
|
} |
202 |
|
|
203 |
|
|
204 |
|
|
205 |
/** Check out the sigmund function." y0 = tanh(y1)" if you like to understand ;) |
/** Check out the sigmund function." y0 = tanh(y1)" if you like to understand ;) |
206 |
*/ |
*/ |
207 |
private float[] countSigmund(int ratio) { |
private float[] countSigmund(int ratio) { |
208 |
float [] retArray = new float[ratio]; |
float [] retArray = new float[ratio]; |
209 |
|
|
210 |
float I = 10.0f; |
float I = 10.0f; |
211 |
float sigm = I*(float)Math.PI; |
float sigm = I*(float)Math.PI; |