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 libutil/I...


From: Janne V. Kujala
Subject: [Gzz-commits] gzz/gfx librenderables/renderables.py libutil/I...
Date: Sun, 10 Nov 2002 11:07:49 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Janne V. Kujala <address@hidden>        02/11/10 11:07:48

Modified files:
        gfx/librenderables: renderables.py 
        gfx/libutil    : Irregu.hxx 

Log message:
        cleanup

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.134&tr2=1.135&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/Irregu.hxx.diff?tr1=1.1&tr2=1.2&r1=text&r2=text

Patches:
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.134 
gzz/gfx/librenderables/renderables.py:1.135
--- gzz/gfx/librenderables/renderables.py:1.134 Sat Nov  9 15:19:26 2002
+++ gzz/gfx/librenderables/renderables.py       Sun Nov 10 11:07:47 2002
@@ -1231,7 +1231,6 @@
         int n = (int)(36 * dicefactor);
         std::vector<ZPt> vert(n+1);
         std::vector<ZVec> norm(n+1);
-        std::vector<float> texq(n+1);
 
         for (int i = 0; i <= n; i++) { 
             float a = i * 2*M_PI / n;
@@ -1239,8 +1238,10 @@
         }
 
         for (int i = 0; i <= n; i++) {
-            norm[i] = (vert[(i+1) % n] - vert[(i+n-1) % n]).cw90().normalize()
-                    * (ripple_scale * texscale);
+            norm[i] = (vert[(i+1) % n] - vert[(i+n-1) % n]).cw90().normalize();
+
+            norm[i] *= (ripple_scale * texscale) /
+                   norm[i].dot((vert[(i+1) % n] - vert[i]).cw90().normalize());
         }
 
         setup();
@@ -1250,7 +1251,7 @@
         Irregu::draw(coords1, vert, norm, texscale,
                      -.5, .5, col0, col1, 3, 0, 
                      Irregu::SLICE_1D + Irregu::Y_SECCOLOR +
-                     mode * Irregu::DOTVEC_COLOR);
+                     mode * Irregu::DOTVEC_COLOR + Irregu::INTERP_DOTVEC);
 
         if (!mode) {
             glDisable(GL_TEXTURE_2D);
Index: gzz/gfx/libutil/Irregu.hxx
diff -u gzz/gfx/libutil/Irregu.hxx:1.1 gzz/gfx/libutil/Irregu.hxx:1.2
--- gzz/gfx/libutil/Irregu.hxx:1.1      Sat Nov  9 13:32:52 2002
+++ gzz/gfx/libutil/Irregu.hxx  Sun Nov 10 11:07:47 2002
@@ -31,11 +31,20 @@
        glVertex3f(p.x, p.y, p.z);
     }
 
-    const unsigned Y_COLOR      = 1;
-    const unsigned Y_SECCOLOR   = 2;
-    const unsigned DOTVEC_COLOR = 4;
-    const unsigned SLICE_1D     = 8;
-    const unsigned SLICE_2D     = 16;
+    inline void vertex(ZPt p, float w) {
+       glVertex4f(p.x, p.y, p.z, w);
+    }
+
+    inline void vertex_mul(ZPt p, float w) {
+       glVertex4f(p.x * w, p.y * w, p.z * w, w);
+    }
+
+    const unsigned Y_COLOR       = 1;
+    const unsigned Y_SECCOLOR    = 2;
+    const unsigned DOTVEC_COLOR  = 4;
+    const unsigned INTERP_DOTVEC = 8;
+    const unsigned SLICE_1D      = 16;
+    const unsigned SLICE_2D      = 32;
 
     template <class Coords>
     void fill(Coords &coords, ZPt center,
@@ -48,6 +57,13 @@
        glEnd();
     }
 
+    /** Compute w value for the point d in quadrilateral a,b,c,d
+     * Use w(b,c,d), w(a,c,d), w(a,b,d), w(a,b,c) to get compatible 
+     * w values for all vertices
+     */
+    inline float compute_w(Pt a, Pt b, Pt c) {
+       return fabs(c.x * (b.y - a.y) + b.x * (a.y - c.y) + a.x * (c.y - b.y));
+    }
 
     template <class Coords>
     void draw(Coords &coords, 
@@ -76,52 +92,70 @@
            vert2[i][1] = coords.transform(vert[i][1]);
        }
 
-        glBegin(GL_QUADS);
-        for (unsigned i = 0, j = 1; i < pt.size(); i++) {
-
-            if (flags & DOTVEC_COLOR) {
-               // angle(norm.cw90())
-               float angle = atan2(-norm[i].x, norm[i].y); 
-               float dotvec[4] = {0,0,0,0};
-               setDotVec(angle, angles, dotvec);
-               glColor4fv(dotvec);
-           }
-
-           if (flags & SLICE_2D) {
+       if (flags & SLICE_2D) {
+           glBegin(GL_QUAD_STRIP);
+           for (unsigned i = 0; i < pt.size() - 1; i++) {
+
+               if (flags & DOTVEC_COLOR) {
+                   // angle(norm.cw90())
+                   float angle = atan2(-norm[i].x, norm[i].y); 
+                   float dotvec[4] = {0,0,0,0};
+                   setDotVec(angle, angles, dotvec);
+                   glColor4fv(dotvec);
+               }
+               
                colorfv(col0);
-               texCoord(vert[i][1], texscale);
-               vertex(vert2[i][1]);
-
-               colorfv(col1);
                texCoord(vert[i][0], texscale);
                vertex(vert2[i][0]);
-               
-               //colorfv(col1);
-               texCoord(vert[j][0], texscale);
-               vertex(vert2[j][0]);
-               
-               colorfv(col0);
-               texCoord(vert[j][1], texscale);
-               vertex(vert2[j][1]);
-           } else if (flags & SLICE_1D) {
-               ZVec dv0 = vert2[i][0] - vert2[j][0];
-               ZVec dv1 = vert2[i][1] - vert2[j][1];
-               float l2v0 = dv0.dot(dv0);
-               float l2v1 = dv1.dot(dv1);
+
+               colorfv(col1);
+               texCoord(vert[i][1], texscale);
+               vertex(vert2[i][1]);
+           }
+           glEnd();
+       }
+       
+       if (flags & SLICE_1D) {
+           glBegin(GL_QUADS);
+           for (unsigned i = 0, j = 1; j < pt.size(); i++, j++) {
 
                float d0, d1;
-               float q1 = l2v0 > 0 ? sqrt(l2v1 / l2v0) : 1.0;
+               float dy;
 
                if (multi > 0) {
+                   ZVec dv0 = vert2[i][0] - vert2[j][0];
+                   ZVec dv1 = vert2[i][1] - vert2[j][1];
                    ZVec dt = pt[j] - pt[i];
+                   float l2v0 = dv0.dot(dv0);
+                   float l2v1 = dv1.dot(dv1);
                    float l2t = dt.dot(dt);
 
                    d0 = sqrt(l2t / l2v0);
                    d1 = sqrt(l2t / l2v1);
+
+                   dy = 1.0 / 
+                       dv0.cw90().normalize().dot(vert2[i][1] - vert2[i][0]);
+
+                   // XXX: should not be hardcoded
+                   glColor4f(0,0,dy,dy);
                }
 
+               ZVec dv0 = vert[i][0] - vert[j][0];
+               ZVec dv1 = vert[i][1] - vert[j][1];
+               float q1 = dv0.dot(dv1) / dv0.dot(dv0);
                ZPt a1q = pt[i] * q1;
                ZPt b1q = pt[j] * q1;
+
+               if (flags & DOTVEC_COLOR) {
+                   float angle = flags & INTERP_DOTVEC ?
+                       atan2(-norm[i].x, norm[i].y) :
+                       atan2(pt[j].y - pt[i].y,
+                             pt[j].x - pt[i].x); 
+                   float dotvec[4] = {0,0,0,0};
+                   setDotVec(angle, angles, dotvec);
+                   glColor4fv(dotvec);
+               }
+
                GLenum u;
 
                colorfv(col1);
@@ -142,6 +176,13 @@
                }
                vertex(vert2[i][0]);
 
+               if ((flags & DOTVEC_COLOR) && (flags & INTERP_DOTVEC)) {
+                   float angle = atan2(-norm[j].x, norm[j].y); 
+                   float dotvec[4] = {0,0,0,0};
+                   setDotVec(angle, angles, dotvec);
+                   glColor4fv(dotvec);
+               }
+
                //colorfv(col0);
                texCoord(pt[j], texscale);
                u = GL_TEXTURE1;
@@ -161,9 +202,8 @@
                vertex(vert2[j][1]);
            }
 
-           if (++j == pt.size()) j = 0;
-        }
-        glEnd();
+           glEnd();
+       }
 
     }
 }




reply via email to

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