Changes between Version 32 and Version 33 of tutorial


Ignore:
Timestamp:
Jun 30, 2013, 4:34:04 PM (11 years ago)
Author:
leon
Comment:

FIx offset 1

Legend:

Unmodified
Added
Removed
Modified
  • tutorial

    v32 v33  
    530530#define MaxGroups   100
    531531
    532 GLfloat vertex[MaxVertices][3];
    533 GLuint  face[MaxFaces][3];
     532GLfloat vertex[MaxVertices*3];
     533GLuint  face[MaxFaces*3];
    534534char    group_name[MaxGroups][80];
    535535int     start_face[MaxGroups];
     
    547547      {
    548548      case 'v':
    549         sscanf(&line[1],  "%f %f %f", &vertex[vertices][0],
    550                &vertex[vertices][1], &vertex[vertices][2]);
     549        sscanf(&line[1],  "%f %f %f", &vertex[vertices+3],
     550               &vertex[vertices*3+1], &vertex[vertices*3+2]);
    551551        ++vertices;
    552552        break;
     
    556556        break;
    557557      case 'f':
    558         sscanf(&line[1],  "%d %d %d", &face[faces][0],
    559                &face[faces][1], &face[faces][2]);
    560         ++faces;
     558        sscanf(&line[1],  "%d %d %d", &face[faces*3],
     559               &face[faces*3+1], &face[faces*3+2]);
     560        --face[faces*3]; --face[faces*3+1];
     561        --face[faces*3+2]; ++faces;
    561562        break;
    562563      }
     
    574575  FILE *f = fopen(n, "w"); fprintf(f, "# Wavefront OBJ file\n");
    575576  for (i = 0; i < vertices; i++)
    576     fprintf(f, "v %g %g %g\n", vertex[i][0], vertex[i][1], vertex[i][2]);
     577    fprintf(f, "v %g %g %g\n", vertex[i*3], vertex[i*3+1], vertex[i*3+2]);
    577578  fprintf(f, "g %s\n", group_name[group_number]);
    578579  for (i = start_face[group_number]; i < start_face[group_number+1]; ++i)
    579     fprintf(f, "f %d %d %d\n", face[i][0], face[i][1], face[i][2]);
     580    fprintf(f, "f %d %d %d\n", face[i*3]+1, face[i*3+1]+1, face[i*3+2]+1);
    580581  fclose(f);
    581582}