gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] gzz/gfx/librenderables renderables.py


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx/librenderables renderables.py
Date: Sat, 28 Sep 2002 07:23:38 -0400

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/09/28 07:23:38

Modified files:
        gfx/librenderables: renderables.py 

Log message:
        Draw the IrregularQuad inside TRIANGLE_FAN starting from the centroid

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.79&tr2=1.80&r1=text&r2=text

Patches:
Index: gzz/gfx/librenderables/renderables.py
diff -c gzz/gfx/librenderables/renderables.py:1.79 
gzz/gfx/librenderables/renderables.py:1.80
*** gzz/gfx/librenderables/renderables.py:1.79  Sat Sep 28 06:22:22 2002
--- gzz/gfx/librenderables/renderables.py       Sat Sep 28 07:23:38 2002
***************
*** 595,623 ****
  
  
              // Slide v1 into [x0,x1]x[y0,y1]
!             template <class Coords>
!             void vert(Coords& coords1, ZPt v1) {
                  if (v1.x < x0) v1.x = x0;
                  if (v1.x > x1) v1.x = x1;
                  if (v1.y < y0) v1.y = y0;
                  if (v1.y > y1) v1.y = y1;
!                 coords1.vertex(v1);
              }
  
!             // Do vert(coords1, v) for any crossings and then vert(coords1, 
v1)
!             template <class Coords>
!             void vert(Coords& coords1, ZPt v0, ZPt v1) {
                  ZPt v;
                       if ((v0.x - x0) * (v1.x - x0) < 0) v = lerp(v0, v1, (x0 
- 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));
                  else if ((v0.y - y0) * (v1.y - y0) < 0) v = lerp(v0, v1, (y0 
- 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));
                  else {
!                     return vert(coords1, v1);
                  }
!                 vert(coords1, v0, v);
!                 vert(coords1, v, v1);
              }
      """,
      "RenderCode" : """
          DBG(dbg) << "Irregular quad\\n";
--- 595,643 ----
  
  
              // Slide v1 into [x0,x1]x[y0,y1]
!             void vert(vector<ZPt> &pts, ZPt v1) {
                  if (v1.x < x0) v1.x = x0;
                  if (v1.x > x1) v1.x = x1;
                  if (v1.y < y0) v1.y = y0;
                  if (v1.y > y1) v1.y = y1;
!                 pts.push_back(v1);
              }
  
!             // Do vert(pts, v) for any crossings and then vert(pts, v1)
!             void vert(vector<ZPt> &pts, ZPt v0, ZPt v1) {
                  ZPt v;
                       if ((v0.x - x0) * (v1.x - x0) < 0) v = lerp(v0, v1, (x0 
- 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));
                  else if ((v0.y - y0) * (v1.y - y0) < 0) v = lerp(v0, v1, (y0 
- 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));
                  else {
!                     return vert(pts, v1);
                  }
!                 vert(pts, v0, v);
!                 vert(pts, v, v1);
              }
+ 
+             // Draw a polygon as a trinagle fan from the centroid
+             template <class Coords>
+             void drawStarPoly(Coords& coords1, vector<ZPt>& p) {
+                 float A = 0, cx = 0, cy = 0;
+                 p.push_back(p[0]);
+                 for (unsigned i = 0; i < p.size() - 1; i++) {
+                    float t = p[i].x * p[i+1].y - p[i+1].x * p[i].y;
+                    A += t;
+                    cx += (p[i].x + p[i+1].x) * t;
+                    cy += (p[i].y + p[i+1].y) * t;
+                 }
+                 cx /= 3 * A;
+                 cy /= 3 * A;
+ 
+                 glBegin(GL_TRIANGLE_FAN);
+                 coords1.vertex(ZPt(cx, cy, p[0].z));
+                 for (unsigned i = 0; i < p.size(); i++)
+                     coords1.vertex(p[i]);
+                 glEnd();
+             }
+             
      """,
      "RenderCode" : """
          DBG(dbg) << "Irregular quad\\n";
***************
*** 737,756 ****
  
          // Disable the effect of TEXTURE1 as the clipping is done explicitly
          glMultiTexCoord2f(1, .5, .5);
          
-         glBegin(GL_TRIANGLE_FAN);
-         vert(coords1, coords2.transform(ZPt(0,0,0)));
          ZPt prev = poly2[0];
          for (int i = 0; i < 8; i++) {
              for (int d = 0; d < dice[i]; d++) {
                  float t = (float)d / dice[i];
                  ZPt v = lerp(poly2[i], poly2[i+1], t);
!                 vert(coords1, prev, v);
                  prev = v;
              }
          }
!         vert(coords1, prev, poly2[0]);
!         glEnd();
  
          #else
  
--- 757,776 ----
  
          // Disable the effect of TEXTURE1 as the clipping is done explicitly
          glMultiTexCoord2f(1, .5, .5);
+ 
+         vector<ZPt> pts;
          
          ZPt prev = poly2[0];
          for (int i = 0; i < 8; i++) {
              for (int d = 0; d < dice[i]; d++) {
                  float t = (float)d / dice[i];
                  ZPt v = lerp(poly2[i], poly2[i+1], t);
!                 vert(pts, prev, v);
                  prev = v;
              }
          }
! 
!         drawStarPoly(coords1, pts);
  
          #else
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]