520 |
this->mode = mode; |
this->mode = mode; |
521 |
setup = CallGLCode(string(setupcode.begin(), setupcode.end()).c_str()); |
setup = CallGLCode(string(setupcode.begin(), setupcode.end()).c_str()); |
522 |
""", |
""", |
523 |
"RenderCode" : "int i=0; i++;", |
"ExtraClass" : """ |
524 |
|
ZPt lerp(float f, ZPt a, ZPt b) { |
525 |
|
return ZPt((1 - f) * a.x + f * b.x, |
526 |
|
(1 - f) * a.y + f * b.y, |
527 |
|
0); |
528 |
|
} |
529 |
|
|
530 |
|
template <class Coords> |
531 |
|
inline void vert(Coords& coords1, Coords& coords2, ZPt q) { |
532 |
|
ZPt p = coords2.transform(q); |
533 |
|
glMultiTexCoord2f(1, .25 / cs2w * p.x + .5, .25 / cs2h * p.y + .5); |
534 |
|
coords1.vertex(p); |
535 |
|
} |
536 |
|
""", |
537 |
|
"RenderCode" : """ |
538 |
|
|
539 |
|
setup(); |
540 |
|
GLERR; |
541 |
|
|
542 |
|
|
543 |
|
// Normalize tearaway part unit vectors in paper coords to get border widths |
544 |
|
// Note: we assume that coords2 is an affine transform so that the border (ripple) width |
545 |
|
// is translation invariant |
546 |
|
Coords &cs2inv = *coords2.getInverse(); |
547 |
|
ZVec xvec = (coords2.transform(ZPt(1,0,0)) - coords2.transform(ZPt(0,0,0))).normalize(); |
548 |
|
ZVec yvec = (coords2.transform(ZPt(0,1,0)) - coords2.transform(ZPt(0,0,0))).normalize(); |
549 |
|
|
550 |
|
//cout << (coords2.transform(ZPt(1,0,0)) - coords2.transform(ZPt(0,0,0))) |
551 |
|
// << (coords2.transform(ZPt(0,1,0)) - coords2.transform(ZPt(0,0,0))) << "\\n"; |
552 |
|
|
553 |
|
float bx = border * (cs2inv.transform(ZPt(0,0,0) + xvec) - cs2inv.transform(ZPt(0,0,0))).length(); |
554 |
|
float by = border * (cs2inv.transform(ZPt(0,0,0) + yvec) - cs2inv.transform(ZPt(0,0,0))).length(); |
555 |
|
|
556 |
|
//cout << bx << "," << by << "\\n"; |
557 |
|
|
558 |
|
float x0 = 1; |
559 |
|
float x1 = 1 - bx; |
560 |
|
float x2 = 1 - 2 * bx; |
561 |
|
float y0 = 1; |
562 |
|
float y1 = 1 - by; |
563 |
|
float y2 = 1 - 2 * by; |
564 |
|
float w = .5; |
565 |
|
|
566 |
|
// scale of last two vertices of sides |
567 |
|
float wtbl[] = { 1, 1, 1, 1, w, w, w, w }; |
568 |
|
|
569 |
|
ZPt sides[][4] = { // The sides of the rectangle: |
570 |
|
{ ZPt(-x0,-y2,0), ZPt(-x0,+y2,0), ZPt(-x1,+y2,0), ZPt(-x1,-y2,0) }, |
571 |
|
{ ZPt(+x0,-y2,0), ZPt(+x0,+y2,0), ZPt(+x1,+y2,0), ZPt(+x1,-y2,0) }, |
572 |
|
{ ZPt(-x2,-y0,0), ZPt(+x2,-y0,0), ZPt(+x2,-y1,0), ZPt(-x2,-y1,0) }, |
573 |
|
{ ZPt(-x2,+y0,0), ZPt(+x2,+y0,0), ZPt(+x2,+y1,0), ZPt(-x2,+y1,0) }, |
574 |
|
// Corners: |
575 |
|
{ ZPt(+x2,+y0,0), ZPt(+x0,+y2,0), ZPt(+x1,+y2,0), ZPt(+x2,+y1,0) }, |
576 |
|
{ ZPt(+x2,-y0,0), ZPt(+x0,-y2,0), ZPt(+x1,-y2,0), ZPt(+x2,-y1,0) }, |
577 |
|
{ ZPt(-x2,+y0,0), ZPt(-x0,+y2,0), ZPt(-x1,+y2,0), ZPt(-x2,+y1,0) }, |
578 |
|
{ ZPt(-x2,-y0,0), ZPt(-x0,-y2,0), ZPt(-x1,-y2,0), ZPt(-x2,-y1,0) } |
579 |
|
}; |
580 |
|
|
581 |
|
/* The distance (as a fraction of border) from the square where the 1D texture slice is taken. |
582 |
|
* Smaller number lowers the frequency of the corner pieces |
583 |
|
*/ |
584 |
|
float texf = 0.5; |
585 |
|
|
586 |
|
for (int pass = 0; pass < (mode ? 4 : 1); pass++) { |
587 |
|
|
588 |
|
if (mode) { |
589 |
|
glPushMatrix(); |
590 |
|
glTranslatef((pass & 1) ? -2 : 2, |
591 |
|
(pass & 2) ? -2 : 2, |
592 |
|
0); |
593 |
|
} |
594 |
|
|
595 |
|
glEnable(GL_REGISTER_COMBINERS_NV); |
596 |
|
glEnable(GL_TEXTURE_2D); |
597 |
|
|
598 |
|
for (unsigned i = 0; i < sizeof(sides)/sizeof(sides[0]); i++) { |
599 |
|
ZPt tex0 = coords2.transform(lerp(texf, sides[i][3], sides[i][0])); |
600 |
|
ZPt tex1 = coords2.transform(lerp(texf, sides[i][2], sides[i][1])); |
601 |
|
|
602 |
|
|
603 |
|
glBegin(GL_QUADS); |
604 |
|
glSecondaryColor3fEXT(0, 0, 0); |
605 |
|
|
606 |
|
glTexCoord2f(tex0.x, tex0.y); |
607 |
|
vert(coords1, coords2, sides[i][0]); |
608 |
|
|
609 |
|
glTexCoord2f(tex1.x, tex1.y); |
610 |
|
vert(coords1, coords2, sides[i][1]); |
611 |
|
|
612 |
|
glSecondaryColor3fEXT(1, 1, 1); |
613 |
|
|
614 |
|
float w = wtbl[i]; |
615 |
|
|
616 |
|
glTexCoord4f(tex1.x * w, tex1.y * w, 0, w); |
617 |
|
vert(coords1, coords2, sides[i][2]); |
618 |
|
|
619 |
|
glTexCoord4f(tex0.x * w, tex0.y * w, 0, w); |
620 |
|
vert(coords1, coords2, sides[i][3]); |
621 |
|
|
622 |
|
glEnd(); |
623 |
|
GLERR; |
624 |
|
|
625 |
|
} |
626 |
|
|
627 |
|
glDisable(GL_REGISTER_COMBINERS_NV); |
628 |
|
glDisable(GL_TEXTURE_2D); |
629 |
|
|
630 |
|
glBegin(GL_POLYGON); |
631 |
|
|
632 |
|
vert(coords1, coords2, ZPt(+x1,+y2,0)); |
633 |
|
vert(coords1, coords2, ZPt(+x2,+y1,0)); |
634 |
|
|
635 |
|
vert(coords1, coords2, ZPt(-x2,+y1,0)); |
636 |
|
vert(coords1, coords2, ZPt(-x1,+y2,0)); |
637 |
|
|
638 |
|
vert(coords1, coords2, ZPt(-x1,-y2,0)); |
639 |
|
vert(coords1, coords2, ZPt(-x2,-y1,0)); |
640 |
|
|
641 |
|
vert(coords1, coords2, ZPt(+x2,-y1,0)); |
642 |
|
vert(coords1, coords2, ZPt(+x1,-y2,0)); |
643 |
|
glEnd(); |
644 |
|
|
645 |
|
if (mode) glPopMatrix(); |
646 |
|
|
647 |
|
} |
648 |
|
|
649 |
|
glPopAttrib(); |
650 |
|
|
651 |
|
""", |
652 |
"BLAH" : """ |
"BLAH" : """ |
653 |
DBG(dbg) << "Irregular quad\\n"; |
DBG(dbg) << "Irregular quad\\n"; |
654 |
|
|