656 |
{ |
{ |
657 |
"Type" : "2", |
"Type" : "2", |
658 |
"Name": "IrregularQuad", |
"Name": "IrregularQuad", |
659 |
"Data": "float x0, y0, x1, y1, border; CallGLCode setup;", |
"Data": "float border; CallGLCode setup;", |
660 |
"Params" : """ |
"Params" : """ |
661 |
float x0, float y0, float x1, float y1, float border, String setupcode |
float border, String setupcode |
662 |
""", |
""", |
663 |
"ParamCode" : """ |
"ParamCode" : """ |
|
this->x0 = x0; |
|
|
this->y0 = y0; |
|
|
this->x1 = x1; |
|
|
this->y1 = y1; |
|
664 |
this->border = border; |
this->border = border; |
665 |
setup = CallGLCode(string(setupcode.begin(), setupcode.end()).c_str()); |
setup = CallGLCode(string(setupcode.begin(), setupcode.end()).c_str()); |
666 |
""", |
""", |
676 |
setup(); |
setup(); |
677 |
GLERR; |
GLERR; |
678 |
|
|
679 |
|
AffineCoords cs1inv = coords1.getInverse(); |
680 |
AffineCoords cs2inv = coords2.getInverse(); |
AffineCoords cs2inv = coords2.getInverse(); |
681 |
|
|
682 |
float x0b = x0 - border; |
// Normalize unit vectors inside coords2 to get border widths |
683 |
float y0b = y0 - border; |
float bx = border * cs1inv.transform(coords2.transform(cs2inv.transform(coords1.transform(Vec(1,0))).normalize())).length(); |
684 |
float x1b = x1 + border; |
float by = border * cs1inv.transform(coords2.transform(cs2inv.transform(coords1.transform(Vec(0,1))).normalize())).length(); |
685 |
float y1b = y1 + border; |
|
686 |
|
const float x0 = 1; |
687 |
float wx = (x1b - x0b) / (x1 - x0); |
const float x1 = 1 - bx; |
688 |
float wy = (y1b - y0b) / (y1 - y0); |
const float x2 = 1 - 2 * bx; |
689 |
|
const float y0 = 1; |
690 |
|
const float y1 = 1 - by; |
691 |
Pt sides[4][4] = { { Pt(x0,y0), Pt(x1, y0), Pt(x1, y0b), Pt(x0, y0b) }, |
const float y2 = 1 - 2 * by; |
692 |
{ Pt(x0,y1), Pt(x1, y1), Pt(x1, y1b), Pt(x0, y1b) }, |
const float w = .5; |
693 |
{ Pt(x0,y0), Pt(x0, y1), Pt(x0b, y1), Pt(x0b, y0) }, |
|
694 |
{ Pt(x1,y0), Pt(x1, y1), Pt(x1b, y1), Pt(x1b, y0) } }; |
// scale of last two vertices of sides |
695 |
|
float wtbl[] = { 1, 1, 1, 1, w, w, w, w }; |
696 |
|
|
697 |
|
Pt sides[][4] = { // The sides of the rectangle: |
698 |
|
{ Pt(-x0, -y2), Pt(-x0, +y2), Pt(-x1, +y2), Pt(-x1, -y2) }, |
699 |
|
{ Pt(+x0, -y2), Pt(+x0, +y2), Pt(+x1, +y2), Pt(+x1, -y2) }, |
700 |
|
{ Pt(-x2, -y0), Pt(+x2, -y0), Pt(+x2, -y1), Pt(-x2, -y1) }, |
701 |
|
{ Pt(-x2, +y0), Pt(+x2, +y0), Pt(+x2, +y1), Pt(-x2, +y1) }, |
702 |
|
// Corners: |
703 |
|
{ Pt(+x2, +y0), Pt(+x0, +y2), Pt(+x1, +y2), Pt(+x2, +y1) }, |
704 |
|
{ Pt(+x2, -y0), Pt(+x0, -y2), Pt(+x1, -y2), Pt(+x2, -y1) }, |
705 |
|
{ Pt(-x2, +y0), Pt(-x0, +y2), Pt(-x1, +y2), Pt(-x2, +y1) }, |
706 |
|
{ Pt(-x2, -y0), Pt(-x0, -y2), Pt(-x1, -y2), Pt(-x2, -y1) } |
707 |
|
}; |
708 |
|
|
709 |
/* The distance (as a fraction of border) from the square where the 1D texture slice is taken. |
/* The distance (as a fraction of border) from the square where the 1D texture slice is taken. |
710 |
* Smaller number lowers the frequency of the corner pieces |
* Smaller number lowers the frequency of the corner pieces |
712 |
float texf = 0.5; |
float texf = 0.5; |
713 |
|
|
714 |
glBegin(GL_QUADS); |
glBegin(GL_QUADS); |
715 |
for (int i = 0; i < 4; i++) { |
for (unsigned i = 0; i < sizeof(sides)/sizeof(sides[0]); i++) { |
716 |
ZPt tex0 = cs2inv.transform(coords1.transform(lerp(texf, sides[i][0], sides[i][3]))); |
ZPt tex0 = cs2inv.transform(coords1.transform(lerp(texf, sides[i][3], sides[i][0]))); |
717 |
ZPt tex1 = cs2inv.transform(coords1.transform(lerp(texf, sides[i][1], sides[i][2]))); |
ZPt tex1 = cs2inv.transform(coords1.transform(lerp(texf, sides[i][2], sides[i][1]))); |
718 |
|
|
719 |
glSecondaryColor3fEXT(1, 1, 1); |
glSecondaryColor3fEXT(0, 0, 0); |
720 |
|
|
721 |
glTexCoord2f(tex0.x, tex0.y); |
glTexCoord2f(tex0.x, tex0.y); |
722 |
coords1.vertex(sides[i][0]); |
coords1.vertex(sides[i][0]); |
724 |
glTexCoord2f(tex1.x, tex1.y); |
glTexCoord2f(tex1.x, tex1.y); |
725 |
coords1.vertex(sides[i][1]); |
coords1.vertex(sides[i][1]); |
726 |
|
|
727 |
glSecondaryColor3fEXT(0, 0, 0); |
glSecondaryColor3fEXT(1, 1, 1); |
728 |
|
|
729 |
float w = (i & 2) ? wy : wx; |
float w = wtbl[i]; |
|
w = 1; |
|
730 |
|
|
731 |
glTexCoord4f(tex1.x * w, tex1.y * w, 0, w); |
glTexCoord4f(tex1.x * w, tex1.y * w, 0, w); |
732 |
coords1.vertex(sides[i][2]); |
coords1.vertex(sides[i][2]); |
734 |
glTexCoord4f(tex0.x * w, tex0.y * w, 0, w); |
glTexCoord4f(tex0.x * w, tex0.y * w, 0, w); |
735 |
coords1.vertex(sides[i][3]); |
coords1.vertex(sides[i][3]); |
736 |
|
|
|
//cout << tex0 << coords1.transform(sides[i][0]) << "\\n"; |
|
|
//cout << tex1 << coords1.transform(sides[i][1]) << "\\n"; |
|
|
//cout << tex1 << w << coords1.transform(sides[i][2]) << "\\n"; |
|
|
//cout << tex0 << w << coords1.transform(sides[i][3]) << "\\n"; |
|
737 |
} |
} |
738 |
glEnd(); |
glEnd(); |
739 |
|
|
|
Pt corners[4][4] = { { Pt(x0, y0), Pt(x0b, y0), Pt(x0, y0b), Pt(x0b, y0b) }, |
|
|
{ Pt(x1, y0), Pt(x1b, y0), Pt(x1, y0b), Pt(x1b, y0b) }, |
|
|
{ Pt(x0, y1), Pt(x0b, y1), Pt(x0, y1b), Pt(x0b, y1b) }, |
|
|
{ Pt(x1, y1), Pt(x1b, y1), Pt(x1, y1b), Pt(x1b, y1b) } }; |
|
|
|
|
|
float w = 1E-4; |
|
|
glBegin(GL_QUADS); |
|
|
for (int i = 0; i < 4; i++) { |
|
|
ZPt tex0 = cs2inv.transform(coords1.transform(lerp(texf, corners[i][0], corners[i][1]))); |
|
|
ZPt tex1 = cs2inv.transform(coords1.transform(lerp(texf, corners[i][0], corners[i][2]))); |
|
|
|
|
|
glSecondaryColor3fEXT(1, 1, 1); |
|
|
|
|
|
glTexCoord4f(tex1.x * w, tex1.y * w, 0, w); |
|
|
coords1.vertex(corners[i][0]); |
|
|
|
|
|
glTexCoord4f(tex0.x * w, tex0.y * w, 0, w); |
|
|
coords1.vertex(corners[i][0]); |
|
|
|
|
|
glSecondaryColor3fEXT(0, 0, 0); |
|
|
|
|
|
glTexCoord2f(tex0.x, tex0.y); |
|
|
coords1.vertex(corners[i][1]); |
|
|
|
|
|
glTexCoord2f(tex1.x, tex1.y); |
|
|
coords1.vertex(corners[i][2]); |
|
|
|
|
|
} |
|
|
glEnd(); |
|
|
GLERR; |
|
|
|
|
740 |
glDisable(GL_REGISTER_COMBINERS_NV); |
glDisable(GL_REGISTER_COMBINERS_NV); |
741 |
glDisable(GL_TEXTURE_2D); |
glDisable(GL_TEXTURE_2D); |
742 |
glBegin(GL_QUADS); |
glBegin(GL_QUADS); |
743 |
coords1.vertex(Pt(x0,y0)); |
coords1.vertex(Pt(-x2,-y1)); |
744 |
coords1.vertex(Pt(x1,y0)); |
coords1.vertex(Pt(+x2,-y1)); |
745 |
coords1.vertex(Pt(x1,y1)); |
coords1.vertex(Pt(+x2,+y1)); |
746 |
coords1.vertex(Pt(x0,y1)); |
coords1.vertex(Pt(-x2,+y1)); |
747 |
|
|
748 |
|
coords1.vertex(Pt(-x1,-y2)); |
749 |
|
coords1.vertex(Pt(-x1,+y2)); |
750 |
|
coords1.vertex(Pt(-x2,+y1)); |
751 |
|
coords1.vertex(Pt(-x2,-y1)); |
752 |
|
|
753 |
|
coords1.vertex(Pt(+x1,-y2)); |
754 |
|
coords1.vertex(Pt(+x1,+y2)); |
755 |
|
coords1.vertex(Pt(+x2,+y1)); |
756 |
|
coords1.vertex(Pt(+x2,-y1)); |
757 |
glEnd(); |
glEnd(); |
758 |
GLERR; |
GLERR; |
759 |
|
|
760 |
glPopAttrib(); |
glPopAttrib(); |
|
|
|
761 |
""", |
""", |
762 |
} , |
} , |
763 |
|
|