40 |
#include <vob/glerr.hxx> |
#include <vob/glerr.hxx> |
41 |
|
|
42 |
#include <vob/geom/Fillets.hxx> |
#include <vob/geom/Fillets.hxx> |
43 |
|
#include <vob/geom/Fillets2.hxx> |
44 |
|
|
45 |
#ifndef VOB_DEFINED |
#ifndef VOB_DEFINED |
46 |
#define VOB_DEFINED(t) |
#define VOB_DEFINED(t) |
175 |
FilletSpan sp(ctr, csize, |
FilletSpan sp(ctr, csize, |
176 |
a1, d1, th1, lerp(p0.z, p1.z, .5), |
a1, d1, th1, lerp(p0.z, p1.z, .5), |
177 |
a2, d2, th2, lerp(p0.z, p2.z, .5)); |
a2, d2, th2, lerp(p0.z, p2.z, .5)); |
|
// Render it. XXX -- jvk, you need to make this |
|
|
// render the solid fillet. |
|
178 |
if(!(flags & 8)) { |
if(!(flags & 8)) { |
179 |
if(sp.split()) { |
if(sp.split()) { |
180 |
if(flags & 1) { |
if(flags & 1) { |
256 |
} |
} |
257 |
}; |
}; |
258 |
|
|
259 |
|
|
260 |
VOB_DEFINED(FilletSpan1); |
VOB_DEFINED(FilletSpan1); |
261 |
|
|
262 |
|
struct FilletSpan2 { |
263 |
|
enum { NTrans = 3 }; |
264 |
|
|
265 |
|
int ndice; |
266 |
|
int flags; |
267 |
|
|
268 |
|
template<class T> float crad(const T &t) const { |
269 |
|
return t.getSqSize().x; |
270 |
|
} |
271 |
|
template<class T> float th(const T &t0, const T &t1, float d) const { |
272 |
|
float r0 = crad(t0); |
273 |
|
float r1 = crad(t1); |
274 |
|
float rmax = r0 >? r1; |
275 |
|
float rmin = r0 <? r1; |
276 |
|
if(d <= rmax - rmin) return .96 * rmin; |
277 |
|
float dr = (d - (rmax-rmin)) / (r0 + r1); |
278 |
|
return .96 * rmin * 1 / (1 + dr); |
279 |
|
} |
280 |
|
|
281 |
|
template<class F> void params(F &f) { |
282 |
|
f(ndice, flags); |
283 |
|
} |
284 |
|
|
285 |
|
void v(ZVec p) const { |
286 |
|
if(flags & 4) { |
287 |
|
glColor3f(1, p.z / 100, p.z / 100); |
288 |
|
} |
289 |
|
glVertex(p); |
290 |
|
} |
291 |
|
|
292 |
|
void vl(ZVec p) const { |
293 |
|
if(flags & 4) { |
294 |
|
glColor3f(0,p.z / 100, p.z / 100); |
295 |
|
} |
296 |
|
glVertex(p); |
297 |
|
} |
298 |
|
|
299 |
|
template<class G> void renderSpanSolid(const G &g) const { |
300 |
|
glBegin(GL_QUAD_STRIP); |
301 |
|
for(int i=0; i<ndice; i++) { |
302 |
|
float fract = i / (ndice-1.0); |
303 |
|
ZVec intern; |
304 |
|
ZVec pt = g.point(fract, &intern); |
305 |
|
v(pt); |
306 |
|
v(intern); |
307 |
|
} |
308 |
|
glEnd(); |
309 |
|
} |
310 |
|
|
311 |
|
template<class G> void renderSpanLine(const G &g) const { |
312 |
|
glBegin(GL_LINE_STRIP); |
313 |
|
for(int i=0; i<ndice; i++) { |
314 |
|
float fract = i / (ndice-1.0); |
315 |
|
ZVec pt = g.point(fract, 0); |
316 |
|
vl(pt); |
317 |
|
} |
318 |
|
glEnd(); |
319 |
|
} |
320 |
|
|
321 |
|
template<class G> void renderSpan(const G &g) const { |
322 |
|
if(flags & 1) |
323 |
|
renderSpanSolid(g); |
324 |
|
if(flags & 2) |
325 |
|
renderSpanLine(g); |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
template<class T> void render(const T &t0, const T &t1, const T &t2) |
331 |
|
const { |
332 |
|
ZVec p0 = t0.transform(t0.getSqSize()); |
333 |
|
ZVec p1 = t1.transform(t1.getSqSize()) ; |
334 |
|
ZVec p2 = t2.transform(t2.getSqSize()) ; |
335 |
|
|
336 |
|
ZVec ctr = p0; |
337 |
|
Vec v1 = p1 - ctr; |
338 |
|
Vec v2 = p2 - ctr; |
339 |
|
|
340 |
|
DBG(dbg_vfillets) << "FilletSpan "<<ctr<<" "<<v1<<" "<<v2<<"\n"; |
341 |
|
|
342 |
|
float a1 = v1.atan(); |
343 |
|
float a2 = v2.atan(); |
344 |
|
if(a2 < a1 || &t1 == &t2) a2 += 2*M_PI; |
345 |
|
|
346 |
|
float d1 = v1.length() / 2; |
347 |
|
float d2 = v2.length() / 2; |
348 |
|
|
349 |
|
float th1 = th(t0, t1, d1); |
350 |
|
float th2 = th(t0, t2, d2); |
351 |
|
|
352 |
|
float csize = crad(t0); |
353 |
|
|
354 |
|
DBG(dbg_vfillets) << "P: "<<ctr<<" "<<csize<<" "<< |
355 |
|
a1<<" "<<d1<<" "<<th1<<" "<< |
356 |
|
a2<<" "<<d2<<" "<<th2<<" "<< |
357 |
|
"\n"; |
358 |
|
|
359 |
|
CircularNode node(ctr, csize); |
360 |
|
LinearConnectionHalf c1(node, a1, d1, th1, 1, lerp(p0.z, p1.z, .5)); |
361 |
|
LinearConnectionHalf c2(node, a2, d2, th2, -1, lerp(p0.z, p2.z, .5)); |
362 |
|
|
363 |
|
CircleCircleFillet f1(node, c1); |
364 |
|
CircleCircleFillet f2(node, c2); |
365 |
|
|
366 |
|
// Find out how close they are. |
367 |
|
/* if(a2-a1 < M_PI && |
368 |
|
(f1.containsConnection(f2) || |
369 |
|
f2.containsConnection(f1))) { |
370 |
|
// Cleaved case |
371 |
|
} else */ if(f1.overlaps(f2)) { |
372 |
|
renderSpan(FilletBlend(f1, f2)); |
373 |
|
renderSpan(FilletBlend(f2, f1)); |
374 |
|
} else { |
375 |
|
renderSpan(f1); |
376 |
|
float ta1 = f1.dirtang.atan(); |
377 |
|
float ta2 = f2.dirtang.atan(); |
378 |
|
if(ta2 < ta1) ta2 += 2*M_PI; |
379 |
|
renderSpan(CircularNodeSpan(node, ta1, ta2)); |
380 |
|
renderSpan(f2); |
381 |
|
} |
382 |
|
|
383 |
|
} |
384 |
|
|
385 |
|
|
386 |
|
}; |
387 |
|
VOB_DEFINED(FilletSpan2); |
388 |
|
|
389 |
} |
} |
390 |
} |
} |
391 |
|
|