92 |
} |
} |
93 |
}; |
}; |
94 |
|
|
|
/** A set of triangles. |
|
|
*/ |
|
|
struct Triangler { |
|
|
struct Tri { |
|
|
int v[3]; |
|
|
}; |
|
|
vector<Tri> tris; |
|
|
void operator()(int i, int j, int k) { |
|
|
DBG(dbg_paperquad) << "Triangler: "<<i<<" "<<j<<" "<<k<<"\n"; |
|
|
Tri t; |
|
|
t.v[0] = i; |
|
|
t.v[1] = j; |
|
|
t.v[2] = k; |
|
|
tris.push_back(t); |
|
|
} |
|
|
void draw() { |
|
|
glDrawElements(GL_TRIANGLES, tris.size()*3, GL_UNSIGNED_INT, |
|
|
&(tris[0])); |
|
|
} |
|
|
}; |
|
|
|
|
95 |
inline float split(Verts &v, float dicelen, int i, int j) { |
inline float split(Verts &v, float dicelen, int i, int j) { |
96 |
float ret = (v.points[i].final - v.points[j].final).xylength() |
float ret = (v.points[i].final - v.points[j].final).xylength() |
97 |
/ dicelen - 1; |
/ dicelen - 1; |
100 |
return ret; |
return ret; |
101 |
} |
} |
102 |
|
|
103 |
|
inline void addToAccum(LOD::TexAccum *acc, Verts &v, |
104 |
|
int v0, int v1, int v2) { |
105 |
|
acc->add( |
106 |
|
v.points[v0].final, |
107 |
|
v.points[v1].final, |
108 |
|
v.points[v2].final, |
109 |
|
v.points[v0].orig, |
110 |
|
v.points[v1].orig, |
111 |
|
v.points[v2].orig); |
112 |
|
} |
113 |
|
|
114 |
inline int splitTri(Verts &v, float dicelen1, float dicelen2, int i, int j, int k) { |
inline int splitTri(Verts &v, float dicelen1, float dicelen2, int i, int j, int k) { |
115 |
DBG(dbg_paperquad) << "SplitTri "<<i<<" "<<j<<" "<<k<<" "<< |
DBG(dbg_paperquad) << "SplitTri "<<i<<" "<<j<<" "<<k<<" "<< |
116 |
v.points[i].orig<<" "<< |
v.points[i].orig<<" "<< |
198 |
float diceLength, diceLength2; |
float diceLength, diceLength2; |
199 |
int diceDepth; |
int diceDepth; |
200 |
|
|
201 |
|
LOD::TexAccum *texAccum; |
202 |
|
|
203 |
template<class F> void params(F &f) { |
template<class F> void params(F &f) { |
204 |
f(paper, x0, y0, x1, y1, flags, diceLength, diceLength2, diceDepth); |
f(paper, x0, y0, x1, y1, flags, diceLength, diceLength2, diceDepth, |
205 |
|
texAccum); |
206 |
} |
} |
207 |
|
|
208 |
|
|
224 |
triangler.add(0, 1, 3); |
triangler.add(0, 1, 3); |
225 |
triangler.add(0, 3, 2); |
triangler.add(0, 3, 2); |
226 |
DBG(dbg_paperquad) << "dice\n"; |
DBG(dbg_paperquad) << "dice\n"; |
227 |
|
|
228 |
|
if(texAccum) { |
229 |
|
// First, dice roughly for the texture magnification |
230 |
|
// accumulator |
231 |
|
triangler.dice(bind(splitTri, ref(verts), |
232 |
|
diceLength*2, diceLength2*2, _1, _2, _3)); |
233 |
|
// Then, calculate the texture surface estimates |
234 |
|
triangler.iterateTriangles( |
235 |
|
bind(addToAccum, texAccum, ref(verts), _1, _2, _3)); |
236 |
|
} |
237 |
|
|
238 |
|
// Dice to finish |
239 |
triangler.dice(bind(splitTri, ref(verts), diceLength, diceLength2, _1, _2, _3)); |
triangler.dice(bind(splitTri, ref(verts), diceLength, diceLength2, _1, _2, _3)); |
240 |
DBG(dbg_paperquad) << "diced\n"; |
DBG(dbg_paperquad) << "diced\n"; |
241 |
} |
} |