Results 1 to 4 of 4

Thread: Redbook Ex. 2-16/17

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    Redbook Ex. 2-16/17

    I'm a bit confused about this for loop:
    Code :
    for (i = 0; i < 3; i++) { 
          v12[i] = v1[i]+v2[i]; 
          v23[i] = v2[i]+v3[i];     
          v31[i] = v3[i]+v1[i];    
    }

    If v1[i] is 10 and v2[i] is 15, doesn't adding v1[i] to v2[i] make the resulting coordinate equal 35? But the end result seems to be 12.5, somehow - why?

    Example 2-16 : Single Subdivision

    Code :
    void drawtriangle(float *v1, float *v2, float *v3) 
    { 
       glBegin(GL_TRIANGLES); 
          glNormal3fv(v1); vlVertex3fv(v1);    
          glNormal3fv(v2); vlVertex3fv(v2);    
          glNormal3fv(v3); vlVertex3fv(v3);    
       glEnd(); 
    }
     
    void subdivide(float *v1, float *v2, float *v3) 
    { 
       GLfloat v12[3], v23[3], v31[3];    
       GLint i;
     
       for (i = 0; i < 3; i++) { 
          v12[i] = v1[i]+v2[i]; 
          v23[i] = v2[i]+v3[i];     
          v31[i] = v3[i]+v1[i];    
       } 
       normalize(v12);    
       normalize(v23); 
       normalize(v31); 
       drawtriangle(v1, v12, v31);    
       drawtriangle(v2, v23, v12);    
       drawtriangle(v3, v31, v23);    
       drawtriangle(v12, v23, v31); 
    }
     
    for (i = 0; i < 20; i++) { 
       subdivide(&amp;vdata[tindices[i][0]][0],       
                 &amp;vdata[tindices[i][1]][0],       
                 &amp;vdata[tindices[i][2]][0]); 
    }

    Also, might as well ask this now. How could this recursive subdivision below possibly work when it only creates a triangle when depth is zero?

    Example 2-17 : Recursive Subdivision

    Code :
    void subdivide(float *v1, float *v2, float *v3, long depth)
    {
       GLfloat v12[3], v23[3], v31[3];
       GLint i;
     
       if (depth == 0) {
          drawtriangle(v1, v2, v3);
          return;
       }
       for (i = 0; i < 3; i++) {
          v12[i] = v1[i]+v2[i];
          v23[i] = v2[i]+v3[i];
          v31[i] = v3[i]+v1[i];
       }
       normalize(v12);
       normalize(v23);
       normalize(v31);
       subdivide(v1, v12, v31, depth-1);
       subdivide(v2, v23, v12, depth-1);
       subdivide(v3, v31, v23, depth-1);
       subdivide(v12, v23, v31, depth-1);
    }

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Redbook Ex. 2-16/17

    Code :
    void drawtriangle(float *v1, float *v2, float *v3) 
    { 
       glBegin(GL_TRIANGLES); 
          glNormal3fv(v1); vlVertex3fv(v1);    
          glNormal3fv(v2); vlVertex3fv(v2);    
          glNormal3fv(v3); vlVertex3fv(v3);    
       glEnd(); 
    }

    What is vlVertex3f?? It is not opengl.

  3. #3
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: Redbook Ex. 2-16/17

    vlVertex is a typo. :P

    a - The normalized sum of the vertex to compute the median works only in case you want to draw a sphere centered in the origin.

    b - It's a recursive code, it compute a finer triangle on every step but it draws only the last level.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  4. #4
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    8

    Re: Redbook Ex. 2-16/17

    ahh I see now. Thx.

Similar Threads

  1. In example 1.3 of Redbook i have a question
    By Kilopopo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-29-2010, 05:11 AM
  2. The Redbook or not the Redbook?
    By whitedragon in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-17-2006, 02:45 PM
  3. redbook of opengl 1.5
    By illogic_code in forum OpenGL: Windows
    Replies: 0
    Last Post: 07-16-2004, 11:20 PM
  4. Redbook?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-28-2001, 04:36 PM
  5. REDBOOK 1.1 & REDBOOK 1.0
    By imported_Douglas in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-30-2000, 07:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean