/[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.160 by jvk, Sat Nov 30 19:40:42 2002 UTC revision 1.161 by jvk, Wed Dec 11 12:20:06 2002 UTC
# Line 1433  rs = [ Line 1433  rs = [
1433  # coords1: paper => window  # coords1: paper => window
1434  # coords2: frame => paper (assumed to be affine)  # coords2: frame => paper (assumed to be affine)
1435  #  #
 # texscale is paper-texture scaling  
 # ripple_scale is the amplitude-period scale of the texture  
 {  
     "Type" : "2",  
     "Name": "IrregularEllipse",  
     "Data": """float texscale; float ripple_scale; int mode; CallGLCode setup;  
                 float dicefactor;""",  
     "Params" : """  
             float texscale, float ripple_scale, int mode, UTF8String setupcode,  
             float dicefactor  
         """,  
     "ParamCode" : """  
             this->texscale = texscale;  
             this->ripple_scale = ripple_scale;  
             this->mode = mode;  
             setup = CallGLCode(setupcode.c_str());  
             this->dicefactor = dicefactor;  
         """,  
     "RenderCode" : """  
         DBG(dbg) << "IrregularEllipse\\n";  
   
         // XXX: TODO: use coords1.nonlinearity()  
         int n = (int)(36 * dicefactor);  
         std::vector<ZPt> vert(n+1);  
         std::vector<ZVec> norm(n+1);  
   
         for (int i = 0; i <= n; i++) {  
             float a = i * 2*M_PI / n;  
             vert[i] = coords2.transform(ZPt(cos(a), sin(a), 0));  
         }  
   
         for (int i = 0; i <= n; i++) {  
             ZVec v1 = (vert[(i+1) % n] - vert[i % n]).cw90().normalize();  
             ZVec v2 = (vert[i % n] - vert[(i+n-1) % n]).cw90().normalize();  
           
             norm[i] = (v1 + v2).normalize();  
             norm[i] *= (ripple_scale * texscale) / v1.dot(norm[i]);  
         }  
   
         setup();  
         float col[] = {1,1,1,1,0,0,0,0};  
         if (!mode) glColor4f(0,0,0,1);  
         Irregu::draw(coords1, vert, norm, texscale, 2.0, 128, 0,  
                      -.5, .5, 0, col, NULL, 3, 0,  
                      Irregu::SLICE_1D + Irregu::Y_SECCOLOR +  
                      mode * Irregu::DOTVEC_COLOR + Irregu::INTERP_DOTVEC);  
   
         if (!mode) {  
             glDisable(GL_TEXTURE_2D);  
             glDisable(GL_REGISTER_COMBINERS_NV);  
             float col[4];  
             glGetFloatv(GL_CONSTANT_COLOR0_NV, col);  
             glColor4fv(col);  
             Irregu::fill(coords1, coords2.transform(ZPt(0,0,0)),  
                          vert, norm, -.5);  
         }  
   
         glPopAttrib();  
   
         DBG(dbg) << "IrregularEllipse done\\n";  
   
         """,  
 }    ,  
   
 # coords1: paper => window  
 # coords2: frame => paper (assumed to be affine)  
 #  
1436  # shape: determines the frame shape; all shapes fit in [-1,1]^2  # shape: determines the frame shape; all shapes fit in [-1,1]^2
1437  # setup: CallGL code that is run before calling Irregu::draw  # setup: CallGL code that is run before calling Irregu::draw
1438  # texscale, ..., flags: passed directly to Irregu::draw  # texscale, ..., flags: passed directly to Irregu::draw
# Line 1530  rs = [ Line 1463  rs = [
1463                  }                  }
1464                  return v;                  return v;
1465              }              }
             double power(double x, double y) {  
                 return x < 0 ? -pow(-x,y) : pow(x,y);  
             }  
1466      """,      """,
1467      "ParamCode" : """      "ParamCode" : """
1468              this->shape = shape;              this->shape = shape;
# Line 1569  rs = [ Line 1499  rs = [
1499              n = 2 + shape;              n = 2 + shape;
1500          default:          default:
1501          case 0:          case 0:
1502              for (int i = 0; i < n; i++) {              vert = Irregu::getEllipse(n, 2, 2);
                 float a = i * 2*M_PI / n;  
                 vert[i] = coords2.transform(ZPt(cos(a), sin(a), 0));  
             }  
1503              break;              break;
1504          case 7: {          case 7: {
1505              n = 4;              n = 4;
1506              vert[0] = coords2.transform(ZPt(+1, -1, 0));              vert[0] = ZPt(+1, -1, 0);
1507              vert[1] = coords2.transform(ZPt(+1, +1, 0));              vert[1] = ZPt(+1, +1, 0);
1508              vert[2] = coords2.transform(ZPt(-1, +1, 0));              vert[2] = ZPt(-1, +1, 0);
1509              vert[3] = coords2.transform(ZPt(-1, -1, 0));              vert[3] = ZPt(-1, -1, 0);
1510              }              }
1511              break;              break;
1512          case 8:          case 8:
# Line 1588  rs = [ Line 1515  rs = [
1515          case 11: {          case 11: {
1516              float xw = (coords2.transform(ZPt(1,0,0)) - coords2.transform(ZPt(0,0,0))).length();              float xw = (coords2.transform(ZPt(1,0,0)) - coords2.transform(ZPt(0,0,0))).length();
1517              float yw = (coords2.transform(ZPt(0,1,0)) - coords2.transform(ZPt(0,0,0))).length();              float yw = (coords2.transform(ZPt(0,1,0)) - coords2.transform(ZPt(0,0,0))).length();
1518                
1519              float pow = 2 + (shape - 8) * 3;              float pow = 2 + (shape - 8) * 3;
1520              float xpow = 2 / (pow * xw);              vert = Irregu::getEllipse(n, pow * xw, pow * yw);
             float ypow = 2 / (pow * yw);  
             for (int i = 0; i < n; i++) {  
                 float a = i * 2*M_PI / n;  
                 vert[i] = coords2.transform(ZPt(power(cos(a),xpow), power(sin(a),ypow), 0));  
             }  
1521              }              }
1522              break;              break;
1523          }          }
1524    
         vert[n] = vert[0];  
1525          vert.resize(n + 1);          vert.resize(n + 1);
1526            vert[n] = vert[0];
1527          std::vector<ZVec> norm(n + 1);          Irregu::transform(coords2, vert);
   
         for (int i = 0; i <= n; i++) {  
             ZVec v1 = (vert[(i+1) % n] - vert[i % n]).cw90().normalize();  
             ZVec v2 = (vert[i % n] - vert[(i+n-1) % n]).cw90().normalize();  
           
             norm[i] = (v1 + v2).normalize();  
             norm[i] *= 1.0 / v1.dot(norm[i]);  
         }  
1528    
1529          setup();          setup();
1530          GLERR;          GLERR;
# Line 1672  rs = [ Line 1585  rs = [
1585              GLERR;              GLERR;
1586                            
1587          } else {          } else {
1588                std::vector<ZVec> norm = Irregu::computeNorms(vert, n);
1589              Irregu::draw(coords1, vert, norm, texscale,              Irregu::draw(coords1, vert, norm, texscale,
1590                          linewidth, refsize, scale_pow,                          linewidth, refsize, scale_pow,
1591                          border0, border1, texslicing,                          border0, border1, texslicing,

Legend:
Removed from v.1.160  
changed lines
  Added in v.1.161

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