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 libcoords...


From: Asko Soukka
Subject: [Gzz-commits] gzz/gfx librenderables/renderables.py libcoords...
Date: Fri, 08 Nov 2002 07:31:39 -0500

CVSROOT:        /cvsroot/gzz
Module name:    gzz
Changes by:     Asko Soukka <address@hidden>    02/11/08 07:31:39

Modified files:
        gfx/librenderables: renderables.py 
        gfx/libcoords  : Coords.cxx 

Log message:
        CullinCoordSys to use CoordSys::getSqSize instead of {(0,0), (1,1)} 
square. Fixed [Culled]PaperQuad's stack overflow with big dice factors.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.131&tr2=1.132&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcoords/Coords.cxx.diff?tr1=1.51&tr2=1.52&r1=text&r2=text

Patches:
Index: gzz/gfx/libcoords/Coords.cxx
diff -u gzz/gfx/libcoords/Coords.cxx:1.51 gzz/gfx/libcoords/Coords.cxx:1.52
--- gzz/gfx/libcoords/Coords.cxx:1.51   Mon Nov  4 17:15:04 2002
+++ gzz/gfx/libcoords/Coords.cxx        Fri Nov  8 07:31:39 2002
@@ -2,6 +2,7 @@
 #include "libfisheye/Fisheye.hxx"
 #include "Coords.hxx"
 #include <GL/gl.h>
+#include <math.h>
 
 namespace Coords {
     DBGVAR(dbg, "Coords.general");
@@ -832,7 +833,7 @@
 
 
     /** Culling coordsys can decide not to be drawn when its
-     * parents' unit squares do not intersect.
+     * parents' boxes do not intersect.
      */
     class CullingCoordSys : public CoordSys {
        CoordSys *testSuper;
@@ -854,7 +855,8 @@
          DBG(dbg_cull) << "(" << p1.x << "," << p1.y << "), (" << p2.x << "," 
<< p2.y << ") <=> ("
                        << p3.x << "," << p3.y << "), (" << p4.x << "," << p4.y 
<< ")\n";
          
-         
+
+         /*      
            glLineWidth(1);
            glColor3f(1, 1, 1);
            glDisable(GL_TEXTURE_2D);
@@ -870,24 +872,25 @@
            glVertex3f(p3.x, p4.y,0);
            glVertex3f(p4.x, p4.y,0);
            glVertex3f(p4.x, p3.y,0);
-         glEnd();
-         
+           glEnd();
+         */
 
          return (p2.x > p3.x) && (p4.x > p1.x) && (p2.y > p3.y) && (p4.y > 
p1.y);
        }
-       /** Finds the bounding box of coordsys' unit square after
+       /** Finds the bounding box of coordsys' box after
         * transformation. Assumes linear coordsys and transforms only
-        * corner's of the unit square.
-        * @param cs coordinate system for the unit square
+        * corner's of the box.
+        * @param cs the coordinate system, which box to use
         * @param p1 "lower left corner"
         * @param p2 "upper right corner"
         */
        void findBoundingBox(CoordSys *cs, ZPt &p1, ZPt &p2) {
          DBG(dbg_cull) << "called CullingCoordsys::findBoundingBox\n";
-           int i, j;
+           float i, j;
+           Pt box = cs->getSqSize();
            float x1, y1, x2, y2;
-           for (i=0; i<=1; i+=1) {
-               for (j=0; j<=1; j+=1) {
+           for (i=0; i<=box.x; i+=box.y) {
+               for (j=0; j<=box.y; j+=box.y) {
                    if (i==0 && j==0) {
                        /** Initializing. */
                        ZPt tmpPt = cs->transform(ZPt(i, j, 0));
@@ -906,16 +909,17 @@
            p1 = ZPt(x1, y1, 0);
            p2 = ZPt(x2, y2, 0);
        }
-       /** Finds the bounding box of coordsys' unit square after
+       /** Finds the bounding box of coordsys' box after
         * transformation. Because the coordsys may be distorted,
-        * searches bounfing box's coners also within vertices.
-        * @param cs coordinate system for the unit square
+        * searches bounding box's coners also along vertices.
+        * @param cs the coordinate system, which box to use
         * @param p1 "lower left corner"
         * @param p2 "upper right corner"
         */
        void findDistortedBoundingBox(CoordSys *cs, ZPt &p1, ZPt &p2) {
          DBG(dbg_cull) << "called CullingCoordsys::findDistortedBoundingBox\n";
            double i, step_x, step_y;
+           Pt box = cs->getSqSize();
            float x1, y1, x2, y2;
            int check_dist;
 
@@ -923,20 +927,22 @@
            check_dist = 100; // XXX Adjusts the scanning frequency.
 
            ZPt o = cs->transform(ZPt(0, 0, 0));
-           ZPt u = cs->transform(ZPt(1, 1, 0));
+           ZPt u = cs->transform(ZPt(box.x, box.y, 0));
 
-           if (fabs(o.x - u.x) / check_dist > 1) step_x = 1/(fabs(o.x - u.x) / 
check_dist);
-           else step_x = 1;
-           if (fabs(o.y - u.y) / check_dist > 1) step_y = 1/(fabs(o.y - u.y) / 
check_dist);
-           else step_y = 1;
+           if (fabs(o.x - u.x) / check_dist > box.x)
+             step_x = box.x/(fabs(o.x - u.x) / check_dist);
+           else step_x = box.x;
+           if (fabs(o.y - u.y) / check_dist > box.y)
+             step_y = box.y/(fabs(o.y - u.y) / check_dist);
+           else step_y = box.y;
            DBG(dbg_cull) << "Step_X: " << step_x << " Step_Y: " << step_y << 
"\n";         
 
            x1 = u.x; y1 = u.y;
            x2 = u.x; y2 = u.y;
 
-           /** Sweeps the unit square's vertices. */
-           /** Vertice (0,0) -> (1,0). */
-           for (i=0; i < 1.0; i+=step_x) {
+           /** Sweeps the box's vertices. */
+           /** Vertice (0,0) -> (w,0). */
+           for (i=0; i < box.x; i+=step_x) {
                ZPt tmpPt = cs->transform(ZPt(i, 0, 0));
                if (tmpPt.x < x1) x1 = tmpPt.x;
                else if (tmpPt.x > x2) x2 = tmpPt.x;
@@ -944,8 +950,8 @@
                else if (tmpPt.y > y2) y2 = tmpPt.y;
            }
            
-           /** Vertice (0,0) -> (0,1). */
-           for (i=step_y; i < 1.0; i+=step_y) {
+           /** Vertice (0,0) -> (0,h). */
+           for (i=step_y; i < box.y; i+=step_y) {
                ZPt tmpPt = cs->transform(ZPt(0, i, 0));
                if (tmpPt.x < x1) x1 = tmpPt.x;
                else if (tmpPt.x > x2) x2 = tmpPt.x;
@@ -953,18 +959,18 @@
                else if (tmpPt.y > y2) y2 = tmpPt.y;
            }
            
-           /** Vertice (0,1) -> (1,1) */
-           for (i=0; i < 1.0; i+=step_x) {
-               ZPt tmpPt = cs->transform(ZPt(i, 1, 0));
+           /** Vertice (0,h) -> (w,h) */
+           for (i=0; i < box.x; i+=step_x) {
+               ZPt tmpPt = cs->transform(ZPt(i, box.y, 0));
                if (tmpPt.x < x1) x1 = tmpPt.x;
                else if (tmpPt.x > x2) x2 = tmpPt.x;
                if (tmpPt.y < y1) y1 = tmpPt.y;
                else if (tmpPt.y > y2) y2 = tmpPt.y;
            }
            
-           /** Vertice (1,0) -> (1,1) */
-           for (i=0; i < 1.0; i+=step_y) {
-               ZPt tmpPt = cs->transform(ZPt(1, i, 0));
+           /** Vertice (w,0) -> (w,h) */
+           for (i=0; i < box.y; i+=step_y) {
+               ZPt tmpPt = cs->transform(ZPt(box.x, i, 0));
                if (tmpPt.x < x1) x1 = tmpPt.x;
                else if (tmpPt.x > x2) x2 = tmpPt.x;
                if (tmpPt.y < y1) y1 = tmpPt.y;
@@ -1012,21 +1018,28 @@
          DBG(dbg_cull) << "called CullingCoordsys::performGL\n";
            return super->performGL();
        }
-       /** Cullin coordsys' shouldBeDrawn() returns false if and only if
-        * it's sure that its parents' unit squares do not intersect.
+       /** CullingCoordSys' shouldBeDrawn() returns true always when boxes 
+        * of its test and clip coordinate systems do intersect. When
+        * the boxes don't intersect, it should retun false.  
         */
        virtual bool shouldBeDrawn() {
          DBG(dbg_cull) << "called CullingCoordsys::shouldBeDrawn\n";
+           Pt box;
+           float hyp;
            /** Lower left and upper right points of bounding boxes for
-            * parents' unit squares (after transformation).
+            * parents' box (after transformation).
             */
            ZPt p1, p2, p3, p4;
            
-           if (testSuper->nonlinearity(ZPt(0.5, 0.5, 0), 1/sqrt(2)) != 0)
+           box = testSuper->getSqSize();
+           hyp = hypot(box.x/2, box.y/2);    
+           if (testSuper->nonlinearity(ZPt(box.x/2, box.y/2, 0), hyp) > 1/hyp)
              findDistortedBoundingBox(testSuper, p1, p2);
            else findBoundingBox(testSuper, p1, p2);
            
-           if (clipSuper->nonlinearity(ZPt(0.5, 0.5, 0), 1/sqrt(2)) != 0) 
+           box = clipSuper->getSqSize();
+           hyp = hypot(box.x/2, box.y/2);
+           if (clipSuper->nonlinearity(ZPt(box.x/2, box.y/2, 0), hyp) >  
1/hyp) 
              findDistortedBoundingBox(clipSuper, p3, p4);
            else findBoundingBox(clipSuper, p3, p4);
            
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.131 
gzz/gfx/librenderables/renderables.py:1.132
--- gzz/gfx/librenderables/renderables.py:1.131 Tue Nov  5 03:21:01 2002
+++ gzz/gfx/librenderables/renderables.py       Fri Nov  8 07:31:39 2002
@@ -452,50 +452,56 @@
            int dice = (int)(len * nonl * dicefactor) + 2;
            DBG(dbg_paperquad) << "Dice: " << dice <<"\\n";
 
-           float vertices[dice][dice][5];
-           int indices[dice-1][2*dice];
+           float *vertices = new float[dice * dice * 5];
+            int *indices = new int[(dice-1) * (2*dice)];
+
+            #define VERTICES3(x, y, z) vertices[((x)*dice + (y))*5 + (z)]
+            #define VERTICES2(x, y)    vertices[((x)*dice + (y))*5]
+            #define INDICES2(x, y)     indices[(x)*2*dice + (y)]
+            #define INDICES1(x)        indices[(x)*2*dice]
+
            int *indps[dice-1];
            int counts[dice-1];
            for(int ix = 0; ix<dice; ix++) {
                if(ix < dice-1) {
                    counts[ix] = 2*dice;
-                   indps[ix] = indices[ix];
+                   indps[ix] = &INDICES1(ix);
                }
                for(int iy = 0; iy<dice; iy++) {
                    if(ix < dice-1) {
-                       indices[ix][2*iy] = dice * ix + iy;
-                       indices[ix][2*iy+1] = dice * (ix+1) + iy;
+                       INDICES2(ix, 2*iy) = dice * ix + iy;
+                       INDICES2(ix, 2*iy+1) = dice * (ix+1) + iy;
                    }
                    float x = ix / (dice - 1.0);
                    float y = iy / (dice - 1.0);
                    ZPt p(lerp(x0, x1, x), lerp(y0, y1, y), 0);
                    ZPt v = coords1.transform(p);
-                   vertices[ix][iy][2] = v.x;
-                   vertices[ix][iy][3] = v.y;
-                   vertices[ix][iy][4] = v.z;
+                   VERTICES3(ix, iy, 2) = v.x;
+                   VERTICES3(ix, iy, 3) = v.y;
+                   VERTICES3(ix, iy, 4) = v.z;
                    ZPt t;
                    if(flags & PAPERQUAD_CS2_TO_SCREEN) {
                        t = coords2inv.transform(v);
                    } else {
                        t = coords2inv.transform(p);
                    }
-                   vertices[ix][iy][0] = t.x;
-                   vertices[ix][iy][1] = t.y;
+                   VERTICES3(ix, iy, 0) = t.x;
+                   VERTICES3(ix, iy, 1) = t.y;
                    DBG(dbg_paperquad) << "   vert: " << 
                            ix << " " <<
                            iy << " : " <<
-                           vertices[ix][iy][0] << " " <<
-                           vertices[ix][iy][1] << " " <<
-                           vertices[ix][iy][2] << " " <<
-                           vertices[ix][iy][3] << " " <<
-                           vertices[ix][iy][4] << " " <<
+                           VERTICES3(ix, iy, 0) << " " <<
+                           VERTICES3(ix, iy, 1) << " " <<
+                           VERTICES3(ix, iy, 2) << " " <<
+                           VERTICES3(ix, iy, 3) << " " <<
+                           VERTICES3(ix, iy, 4) << " " <<
                            "\\n";
                }
            }
 
            glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
            glInterleavedArrays(GL_T2F_V3F, 5*sizeof(float), vertices);
-           glLockArraysEXT(0, dice*dice);
+           glLockArraysEXT(0, dice*dice*5);
 
            for(Paper::Paper::iterator it = paper->begin(); it != paper->end(); 
++it) {
 
@@ -528,13 +534,13 @@
                         glBegin(GL_QUAD_STRIP);
                         for(int iy = 0; iy<dice; iy++) {
 
-                             float tmp[4] = { vertices[ix][iy][0], 
vertices[ix][iy][1], 0 ,1 };
+                             float tmp[4] = { VERTICES3(ix, iy, 0), 
VERTICES3(ix, iy, 1), 0 ,1 };
                              (*it).texcoords_explicit( tmp );
-                             glVertex3fv( (vertices[ix][iy]+2) );
+                             glVertex3fv( (&(VERTICES2(ix, iy))+2) );
                                 
-                             float tmp2[4] = { vertices[ix+1][iy][0], 
vertices[ix+1][iy][1], 0 ,1 };
+                             float tmp2[4] = { VERTICES3(ix+1, iy, 0), 
VERTICES3(ix+1, iy, 1), 0 ,1 };
                              (*it).texcoords_explicit( tmp2 );
-                             glVertex3fv( (vertices[ix+1][iy]+2) );
+                             glVertex3fv( ((&VERTICES2(ix+1, iy))+2) );
                          }
                          glEnd();
                     }
@@ -554,7 +560,11 @@
            DBG(dbg_paperquad) << "Passes over\\n";
 
            GLERR
-       """,
+
+            delete [] vertices;
+            delete [] indices;
+            
+            """,
 }    ,
 
 # CulledPaperQuad is renderable3 version of regular PaperQuad.
@@ -653,87 +663,104 @@
            int dice = (int)(len * nonl * dicefactor) + 2;
            DBG(dbg_paperquad) << "Dice: " << dice <<"\\n";
 
-           float vertices[dice][dice][5];
-           int indices[dice-1][2*dice];
+           float *vertices = new float[dice * dice * 5];
+            int *indices = new int[(dice-1) * (2*dice)];
+
+            #define VERTICES3(x, y, z) vertices[((x)*dice + (y))*5 + (z)]
+            #define VERTICES2(x, y)    vertices[((x)*dice + (y))*5]
+            #define INDICES2(x, y)     indices[(x)*2*dice + (y)]
+            #define INDICES1(x)        indices[(x)*2*dice]
+
            int *indps[dice-1];
            int counts[dice-1];
-
            for(int ix = 0; ix<dice; ix++) {
                if(ix < dice-1) {
                    counts[ix] = 2*dice;
-                   indps[ix] = indices[ix];
+                   indps[ix] = &INDICES1(ix);
                }
                for(int iy = 0; iy<dice; iy++) {
                    if(ix < dice-1) {
-                       indices[ix][2*iy] = dice * ix + iy;
-                       indices[ix][2*iy+1] = dice * (ix+1) + iy;
+                       INDICES2(ix, 2*iy) = dice * ix + iy;
+                       INDICES2(ix, 2*iy+1) = dice * (ix+1) + iy;
                    }
                    float x = ix / (dice - 1.0);
                    float y = iy / (dice - 1.0);
                    ZPt p(lerp(x0, x1, x), lerp(y0, y1, y), 0);
                    ZPt v = coords1.transform(p);
-                   vertices[ix][iy][2] = v.x;
-                   vertices[ix][iy][3] = v.y;
-                   vertices[ix][iy][4] = v.z;
-                   ZPt t = coords2inv.transform(p);
-                   vertices[ix][iy][0] = t.x;
-                   vertices[ix][iy][1] = t.y;
+                   VERTICES3(ix, iy, 2) = v.x;
+                   VERTICES3(ix, iy, 3) = v.y;
+                   VERTICES3(ix, iy, 4) = v.z;
+                   ZPt t;
+                   if(flags & PAPERQUAD_CS2_TO_SCREEN) {
+                       t = coords2inv.transform(v);
+                   } else {
+                       t = coords2inv.transform(p);
+                   }
+                   VERTICES3(ix, iy, 0) = t.x;
+                   VERTICES3(ix, iy, 1) = t.y;
                    DBG(dbg_paperquad) << "   vert: " << 
                            ix << " " <<
                            iy << " : " <<
-                           vertices[ix][iy][0] << " " <<
-                           vertices[ix][iy][1] << " " <<
-                           vertices[ix][iy][2] << " " <<
-                           vertices[ix][iy][3] << " " << 
-                           vertices[ix][iy][4] << " " <<
+                           VERTICES3(ix, iy, 0) << " " <<
+                           VERTICES3(ix, iy, 1) << " " <<
+                           VERTICES3(ix, iy, 2) << " " <<
+                           VERTICES3(ix, iy, 3) << " " <<
+                           VERTICES3(ix, iy, 4) << " " <<
                            "\\n";
-                  }
+               }
            }
 
            glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
            glInterleavedArrays(GL_T2F_V3F, 5*sizeof(float), vertices);
-           glLockArraysEXT(0, dice*dice);
+           glLockArraysEXT(0, dice*dice*5);
 
            for(Paper::Paper::iterator it = paper->begin(); it != paper->end(); 
++it) {
 
                 if (flags & PAPERQUAD_USE_VERTEX_PROGRAM) {
-                   DBG(dbg_paperquad) << "Pass\\n";
+                    DBG(dbg_paperquad) << "Pass\\n";
+                    GLERR
                     (*it).setUp_VP(&lightParam);
-
+                    
                     DBG(dbg_paperquad) << "Going to multidraw\\n";
                     GLERR
-                    glMultiDrawElementsEXT(GL_QUAD_STRIP,
-                       counts, GL_UNSIGNED_INT, (const GLvoid **)indps, 
dice-1);
+                    glMultiDrawElementsEXT(GL_QUAD_STRIP, counts,
+                       GL_UNSIGNED_INT, (const GLvoid **)indps, dice-1);
                     DBG(dbg_paperquad) << "Teardown\\n";
                     GLERR
                     (*it).tearDown_VP();
+                
                     GLERR
                     DBG(dbg_paperquad) << "Pass over\\n";
+
                 } else {
-                   DBG(dbg_paperquad) << "Pass\\n";
+                    DBG(dbg_paperquad) << "Pass\\n";
+                    GLERR
                     (*it).setUp_explicit(&lightParam);
-
-                    DBG(dbg_paperquad) << "Going to draw elements\\n";
+                    
+                    DBG(dbg_paperquad) << "Going to set texcoords explicit\\n";
                     GLERR
 
+
                     for(int ix = 0; ix<dice-1; ix++) {
                         glBegin(GL_QUAD_STRIP);
                         for(int iy = 0; iy<dice; iy++) {
 
-                             float tmp[4] = { vertices[ix][iy][0], 
vertices[ix][iy][1], 0 ,1 };
+                             float tmp[4] = { VERTICES3(ix, iy, 0), 
VERTICES3(ix, iy, 1), 0 ,1 };
                              (*it).texcoords_explicit( tmp );
-                             glVertex3fv( (vertices[ix][iy]+2) );
+                             glVertex3fv( (&(VERTICES2(ix, iy))+2) );
                                 
-                             float tmp2[4] = { vertices[ix+1][iy][0], 
vertices[ix+1][iy][1], 0 ,1 };
+                             float tmp2[4] = { VERTICES3(ix+1, iy, 0), 
VERTICES3(ix+1, iy, 1), 0 ,1 };
                              (*it).texcoords_explicit( tmp2 );
-                             glVertex3fv( (vertices[ix+1][iy]+2) );
+                             glVertex3fv( ((&VERTICES2(ix+1, iy))+2) );
                          }
                          glEnd();
                     }
 
+
                     DBG(dbg_paperquad) << "Teardown\\n";
                     GLERR
                     (*it).tearDown_explicit();
+                
                     GLERR
                     DBG(dbg_paperquad) << "Pass over\\n";
                 }
@@ -744,6 +771,10 @@
            DBG(dbg_paperquad) << "Passes over\\n";
 
            GLERR
+
+            delete [] vertices;
+            delete [] indices;
+
        """,
 }    ,
 




reply via email to

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