/[gzz]/gzz/gfx/librenderables/renderables.py
ViewVC logotype

Diff of /gzz/gfx/librenderables/renderables.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.79 by humppake, Sat Sep 28 10:22:22 2002 UTC revision 1.80 by jvk, Sat Sep 28 11:23:38 2002 UTC
# Line 595  rs = [ Line 595  rs = [
595    
596    
597              // Slide v1 into [x0,x1]x[y0,y1]              // Slide v1 into [x0,x1]x[y0,y1]
598              template <class Coords>              void vert(vector<ZPt> &pts, ZPt v1) {
             void vert(Coords& coords1, ZPt v1) {  
599                  if (v1.x < x0) v1.x = x0;                  if (v1.x < x0) v1.x = x0;
600                  if (v1.x > x1) v1.x = x1;                  if (v1.x > x1) v1.x = x1;
601                  if (v1.y < y0) v1.y = y0;                  if (v1.y < y0) v1.y = y0;
602                  if (v1.y > y1) v1.y = y1;                  if (v1.y > y1) v1.y = y1;
603                  coords1.vertex(v1);                  pts.push_back(v1);
604              }              }
605    
606              // Do vert(coords1, v) for any crossings and then vert(coords1, v1)              // Do vert(pts, v) for any crossings and then vert(pts, v1)
607              template <class Coords>              void vert(vector<ZPt> &pts, ZPt v0, ZPt v1) {
             void vert(Coords& coords1, ZPt v0, ZPt v1) {  
608                  ZPt v;                  ZPt v;
609                       if ((v0.x - x0) * (v1.x - x0) < 0) v = lerp(v0, v1, (x0 - v0.x) / (v1.x - v0.x));                       if ((v0.x - x0) * (v1.x - x0) < 0) v = lerp(v0, v1, (x0 - v0.x) / (v1.x - v0.x));
610                  else if ((v0.x - x1) * (v1.x - x1) < 0) v = lerp(v0, v1, (x1 - v0.x) / (v1.x - v0.x));                  else if ((v0.x - x1) * (v1.x - x1) < 0) v = lerp(v0, v1, (x1 - v0.x) / (v1.x - v0.x));
611                  else if ((v0.y - y0) * (v1.y - y0) < 0) v = lerp(v0, v1, (y0 - v0.y) / (v1.y - v0.y));                  else if ((v0.y - y0) * (v1.y - y0) < 0) v = lerp(v0, v1, (y0 - v0.y) / (v1.y - v0.y));
612                  else if ((v0.y - y1) * (v1.y - y1) < 0) v = lerp(v0, v1, (y1 - v0.y) / (v1.y - v0.y));                  else if ((v0.y - y1) * (v1.y - y1) < 0) v = lerp(v0, v1, (y1 - v0.y) / (v1.y - v0.y));
613                  else {                  else {
614                      return vert(coords1, v1);                      return vert(pts, v1);
615                  }                  }
616                  vert(coords1, v0, v);                  vert(pts, v0, v);
617                  vert(coords1, v, v1);                  vert(pts, v, v1);
618              }              }
619    
620                // Draw a polygon as a trinagle fan from the centroid
621                template <class Coords>
622                void drawStarPoly(Coords& coords1, vector<ZPt>& p) {
623                    float A = 0, cx = 0, cy = 0;
624                    p.push_back(p[0]);
625                    for (unsigned i = 0; i < p.size() - 1; i++) {
626                       float t = p[i].x * p[i+1].y - p[i+1].x * p[i].y;
627                       A += t;
628                       cx += (p[i].x + p[i+1].x) * t;
629                       cy += (p[i].y + p[i+1].y) * t;
630                    }
631                    cx /= 3 * A;
632                    cy /= 3 * A;
633    
634                    glBegin(GL_TRIANGLE_FAN);
635                    coords1.vertex(ZPt(cx, cy, p[0].z));
636                    for (unsigned i = 0; i < p.size(); i++)
637                        coords1.vertex(p[i]);
638                    glEnd();
639                }
640                
641      """,      """,
642      "RenderCode" : """      "RenderCode" : """
643          DBG(dbg) << "Irregular quad\\n";          DBG(dbg) << "Irregular quad\\n";
# Line 737  rs = [ Line 757  rs = [
757    
758          // Disable the effect of TEXTURE1 as the clipping is done explicitly          // Disable the effect of TEXTURE1 as the clipping is done explicitly
759          glMultiTexCoord2f(1, .5, .5);          glMultiTexCoord2f(1, .5, .5);
760    
761            vector<ZPt> pts;
762                    
         glBegin(GL_TRIANGLE_FAN);  
         vert(coords1, coords2.transform(ZPt(0,0,0)));  
763          ZPt prev = poly2[0];          ZPt prev = poly2[0];
764          for (int i = 0; i < 8; i++) {          for (int i = 0; i < 8; i++) {
765              for (int d = 0; d < dice[i]; d++) {              for (int d = 0; d < dice[i]; d++) {
766                  float t = (float)d / dice[i];                  float t = (float)d / dice[i];
767                  ZPt v = lerp(poly2[i], poly2[i+1], t);                  ZPt v = lerp(poly2[i], poly2[i+1], t);
768                  vert(coords1, prev, v);                  vert(pts, prev, v);
769                  prev = v;                  prev = v;
770              }              }
771          }          }
772          vert(coords1, prev, poly2[0]);  
773          glEnd();          drawStarPoly(coords1, pts);
774    
775          #else          #else
776    

Legend:
Removed from v.1.79  
changed lines
  Added in v.1.80

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26