home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WW3DKit / RIBPointsGeneralPolygons.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  6.0 KB  |  242 lines

  1. // copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
  2. // see COPYRIGHT for reuse legalities
  3. //
  4.  
  5. #import "RIBPointsGeneralPolygons.h"
  6.  
  7. @implementation RIBPointsGeneralPolygons
  8.  
  9. + initialize { return [RIBPointsGeneralPolygons setVersion:1], self; }
  10.  
  11. - (BOOL)hasBoundingBox { return YES; }
  12.  
  13. - init
  14. {
  15.   [super init];
  16.  
  17.   nPolys = 0;
  18.   nLoops = NULL;
  19.   nVertices = NULL;
  20.   vertices = NULL;
  21.   nPolysBuf = (char *)malloc(128);
  22.   cntBuf = (char *)malloc(128);
  23.   
  24.   return self;
  25. }
  26.  
  27. - free
  28. {
  29.   //if (nLoops) {  free(nLoops); }
  30.   //if (nVertices) { free(nVertices); }
  31.   //if (vertices) { free(vertices); }
  32.   return [super free];
  33. }
  34.  
  35. - copyFromZone:(NXZone *)zone
  36. {
  37.    id   newCopy = [super copyFromZone:zone];
  38.  
  39.   NXLogError("WARNING: copyFromZone: incompletely implemented for %s : I'm leaking memory in -free", [[self class] name]);
  40.  
  41.   return newCopy;
  42. }
  43.  
  44. - setNPolys:(RtInt)newNPolys nLoops:(RtInt *)newNLoops nVertices:(RtInt *)newNVertices vertices:(RtInt *)newVertices 
  45.      n:(int)newN tokens:(RtToken *)newTokens parms:(RtPointer *)newParms archiveVector:(char **)newArchiveVector
  46.      printfTypeVector:(int *)newPrintfTypeVector printfNVector:(int *)newPrintfNVector
  47. {  
  48.    nPolys = newNPolys;
  49.    nLoops = newNLoops;
  50.    nVertices = newNVertices;
  51.    vertices = newVertices;
  52.    [self setN:newN tokens:newTokens parms:newParms archiveVector:newArchiveVector printfTypeVector:newPrintfTypeVector printfNVector:newPrintfNVector];
  53.    nPolysBuf = (char *)malloc(128);
  54.    nVerticesLengthBuf = (char *)malloc(128);
  55.    cntBuf = (char *)malloc(128);
  56.  
  57.    dirtyBoundingBox = TRUE;
  58.    return self;
  59. }
  60.  
  61. - setNPolys:(RtInt)newNPolys { nPolys = newNPolys; dirtyBoundingBox = TRUE; return self; }
  62. - setNLoops:(RtInt *)newNLoops { nLoops = newNLoops; dirtyBoundingBox = TRUE; return self; }
  63. - setNVertices:(RtInt *)newNVertices { nVertices = newNVertices; dirtyBoundingBox = TRUE; return self; }
  64. - setVertices:(RtInt *)newVertices { vertices = newVertices; dirtyBoundingBox = TRUE; return self; }
  65.  
  66. - (RtInt)nPolys { return nPolys; }
  67. - (RtInt *)nLoops { return nLoops; }
  68. - (RtInt *)nVertices { return nVertices; }
  69. - (RtInt *)vertices { return vertices; }
  70.  
  71.  
  72. - (BOOL)theSameAs:otherRIBCommand
  73. {
  74.   int    i,
  75.          nLoopsSum = 0, 
  76.          nVerticesSum = 0;
  77.   RtInt  *otherNLoops, *otherNVertices, *otherVertices;
  78.  
  79.  
  80.   if ([self class] != [otherRIBCommand class])
  81.   {  return NO;
  82.   }
  83.   if (nPolys != [otherRIBCommand nPolys])
  84.   {  return NO;
  85.   }
  86.  
  87.   otherNLoops = [otherRIBCommand nLoops];
  88.   for (i = 0; i < nPolys; i++)
  89.   {  if (nLoops[i] != otherNLoops[i])
  90.      {  return NO;
  91.      }
  92.      nLoopsSum += nLoops[i];
  93.   }
  94.   otherNVertices = [otherRIBCommand nVertices];
  95.   for (i = 0; i < nLoopsSum; i++)
  96.   {  if (nVertices[i] != otherNVertices[i])
  97.      {  return NO;
  98.      }
  99.      nVerticesSum += nVertices[i];
  100.   }
  101.  
  102.   otherVertices = [otherRIBCommand vertices];
  103.   for (i = 0; i < nVerticesSum; i++)
  104.   {  if (vertices[i] != otherVertices[i])
  105.      {  return NO;
  106.      }
  107.   }
  108.  
  109.   return [super theSameAs:otherRIBCommand];
  110. }
  111.  
  112.  
  113. - (BOOL)similarTo:otherRIBCommand
  114. {
  115.   int    i,
  116.          nLoopsSum = 0, 
  117.          nVerticesSum = 0;
  118.   RtInt  *otherNLoops, *otherNVertices, *otherVertices;
  119.  
  120.  
  121.   if ([self class] != [otherRIBCommand class])
  122.   {  return NO;
  123.   }
  124.   if (nPolys != [otherRIBCommand nPolys])
  125.   {  return NO;
  126.   }
  127.   otherNLoops = [otherRIBCommand nLoops];
  128.   for (i = 0; i < nPolys; i++)
  129.   {  if (nLoops[i] != otherNLoops[i])
  130.      {  return NO;
  131.      }
  132.      nLoopsSum += nLoops[i];
  133.   }
  134.   otherNVertices = [otherRIBCommand nVertices];
  135.   for (i = 0; i < nLoopsSum; i++)
  136.   {  if (nVertices[i] != otherNVertices[i])
  137.      {  return NO;
  138.      }
  139.      nVerticesSum += nVertices[i];
  140.   }
  141.  
  142.   otherVertices = [otherRIBCommand vertices];
  143.   for (i = 0; i < nVerticesSum; i++)
  144.   {  if (vertices[i] != otherVertices[i])
  145.      {  return NO;
  146.      }
  147.   }
  148.  
  149.   return YES;
  150. }
  151.  
  152.  
  153.  
  154. - renderSelf:(WW3DCamera *)camera startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
  155. {
  156.   RiPointsGeneralPolygonsV(nPolys, nLoops, nVertices, vertices, n, tokens, parms);
  157.   return self;
  158. }
  159.  
  160. - (BOOL)isMotionBlurrable { return YES; }
  161.  
  162. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  163. {
  164.    int  i, sum = 0;
  165.  
  166.  
  167.    for (i = 0; i < tab; i++)
  168.    {  NXPrintf(stream, "\t");
  169.    }
  170.    NXPrintf(stream, "PointsGeneralPolygons {");
  171.    for (i = 0; i < nPolys; i++)
  172.    {  NXPrintf(stream, "%d ", nLoops[i]);
  173.    }
  174.    NXPrintf(stream, "} {");
  175.    for (i = 0; i < nPolys; i++)
  176.    {  NXPrintf(stream, "%d ", nVertices[i]);
  177.      sum += nVertices[i];
  178.    }
  179.    NXPrintf(stream, "} {");
  180.    for (i = 0; i < sum; i++)
  181.    {  NXPrintf(stream, "%d ", vertices[i]);
  182.    }
  183.    NXPrintf(stream, "} ");
  184.  
  185.    [super writeParameterList:stream];
  186.    return self;
  187. }
  188.  
  189. #define typeVector "l"
  190. #define typeValues &nPolys
  191.  
  192. - read:(NXTypedStream*)stream 
  193. {
  194.     int version, i, cnt = 0, nVerticesLength = 0;
  195.     
  196.     [super read:stream];
  197.     nPolysBuf = (char *)malloc(128);
  198.     nVerticesLengthBuf = (char *)malloc(128);
  199.     cntBuf = (char *)malloc(128);
  200.     
  201.     version = NXTypedStreamClassVersion(stream,"RIBGeneralPolygon");
  202.     if (version == 0) NXReadTypes(stream,"i",&version), version=1;
  203.     if (version == 1) {
  204.     NXReadTypes(stream,typeVector,typeValues);
  205.     
  206.     nLoops = (long *)NXZoneMalloc([self zone], nPolys*sizeof(long));
  207.     NXReadArray(stream, "l", nPolys, nLoops);
  208.     for (i = 0; i < nPolys; i++) {
  209.         nVerticesLength += nLoops[i];
  210.     }
  211.     nVertices = (long *)NXZoneMalloc([self zone], nVerticesLength*sizeof(long));
  212.     NXReadArray(stream, "l", nVerticesLength, nVertices);
  213.     for (i = 0; i < nPolys; i++) {
  214.         cnt += nVertices[i];
  215.     }
  216.     vertices = (long *)NXZoneMalloc([self zone], cnt*sizeof(long));
  217.     NXReadArray(stream, "l", cnt, vertices);
  218.     } 
  219.     return self;
  220. }
  221.  
  222. - write:(NXTypedStream*)stream 
  223. {
  224.     int   i, cnt = 0, nVerticesLength = 0;
  225.     
  226.     [super write:stream];
  227.     NXWriteTypes(stream, typeVector, typeValues);
  228.     NXWriteArray(stream, "l", nPolys, nLoops);
  229.     for (i = 0; i < nPolys; i++) {
  230.     nVerticesLength += nLoops[i];
  231.     }
  232.     NXWriteArray(stream, "l", nVerticesLength, nVertices);
  233.     for (i = 0; i < nPolys; i++) {
  234.     cnt += nVertices[i];
  235.     }
  236.     NXWriteArray(stream, "l", cnt, vertices);
  237.     return self;
  238. }
  239.  
  240.  
  241. @end
  242.