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

  1.  
  2. #import "WW3DAxes.h"
  3. #import "RIBTransformBegin.h"
  4. #import "RIBScale.h"
  5. #import "RIBSphere.h"
  6. #import "RIBTransformEnd.h"
  7. #import "WWSample.h"
  8. #import "WWEveParser.h"
  9. #import "WW3DAttributeState.h"
  10.  
  11. @implementation WW3DAxes
  12.  
  13. + initialize { return [WW3DAxes setVersion:1], self; }
  14.  
  15. - initWithShape:newShape
  16. {
  17.   id  obj;
  18.  
  19.  
  20.   [super init];
  21.  
  22.   myShape = newShape;
  23.   ribCommandList  = [[RIBCommandList alloc] init];
  24.  
  25.   // AttributeBegin, Color 0 0 1, Cylinder, Rotate -90 1 0 0, Color 0 1 0, Cylinder, Rotate 90 0 1 0, Color 1 0 0, Cylinder, AttributeEnd
  26.   // stick them in backwards...
  27.   [ribCommandList insertObject:[[[RIBAttributeEnd alloc] init] setMyShape:myShape] at:0];
  28.   obj = [[[RIBCylinder alloc] init] 
  29.           setRadius:.1 zMin:0.0 zMax:1.0 thetaMax:360. n:0 tokens:NULL parms:NULL archiveVector:NULL printfTypeVector:NULL printfNVector:NULL];
  30.   [ribCommandList insertObject:[obj setMyShape:myShape] at:0]
  31.  
  32.   dirtyBoundingBox = YES;
  33.  
  34.   return self;
  35. }
  36.  
  37. - awake
  38. {
  39.     [super awake];
  40.     dirtyBoundingBox = YES;
  41.     return self;
  42. }
  43.  
  44.  
  45. - setRIBCommandList:newRIBCommandList { ribCommandList = newRIBCommandList; return self; }
  46. - ribCommandList { return ribCommandList; }
  47.  
  48. // see, this is potentially interesting, if a simple linear
  49. // interpolation of my ribCommandList did not represent the appropriate
  50. // linear interpolation of me, I could interpose some other list of
  51. // objects.  For example, there might some discontinuity between
  52. // this instance and "b", such as an enumerated 
  53. // parameter (i.e. "sleepy, grumpy, happy, ecstatic") which doesn't
  54. // have an obvious interpolation.  
  55. // In the case of this simple composite object, however, 
  56. // it is true that simply interpolating my ribCommandList is enough.
  57. - lerpWith:b by:(float)uValue
  58. {
  59.    return self;
  60. }
  61.  
  62. - lerpSelfWith:b by:(float)uValue
  63. {
  64.    return self;
  65. }
  66.  
  67. - (BOOL)isLerpable { return NO; }  // heck, I never change!
  68.  
  69. - (BOOL)pushesOrPopsCTM { return NO; }
  70. - (BOOL)pushesCTM { return NO; }
  71. - (BOOL)popsCTM { return NO; }
  72.  
  73. - free
  74. {
  75.     [ribCommandList free];
  76.     return [super free];
  77. }
  78.  
  79. - (BOOL)hasBoundingBox        { return YES; }
  80. - (BOOL)isMotionBlurrable    { return NO; }
  81. - (BOOL)isCompoundCommand    { return YES; }
  82.  
  83. - setBoundingBox:(RtBound *)newBoundingBox
  84. {
  85.     N3D_CopyBound(*newBoundingBox, boundingBox);
  86.     return self;
  87. }
  88.  
  89. - calculateBoundingBoxStartingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime  
  90. {  
  91.     dirtyBoundingBox = NO;
  92.     return [self setBoundingBox:[ribCommandList boundingBoxStartingAt:shutterOpenTime endingAt:shutterCloseTime]];
  93. }
  94.  
  95. - (RtBound *)boundingBoxStartingAt:(RtFloat)intervalStartTime endingAt:(RtFloat)intervalEndTime
  96.    if (dirtyBoundingBox) 
  97.    {  [self calculateBoundingBoxStartingAt:intervalStartTime endingAt:intervalEndTime];
  98.    }
  99.    return &boundingBox; 
  100. }
  101.  
  102. - (float)lastSampleIsAt { return 0.0; }
  103.  
  104. - (unsigned long int)maxSampleBandwidth { return [ribCommandList maxSampleBandwidth]; }
  105.  
  106. - setMyShape:shape
  107. {
  108.     myShape = shape;
  109.     return self;
  110. }
  111.  
  112. - shape
  113. {
  114.     return myShape;
  115. }
  116.  
  117. - renderMaps:(WW3DCamera *)camera
  118.     startingAt:(RtFloat)shutterOpenTime
  119.     endingAt:(RtFloat)shutterCloseTime usingStream:(NXStream *)ns
  120. {
  121.     return self;
  122. }
  123.  
  124. - renderMaps:(WW3DCamera *)camera usingStream:(NXStream *)ns
  125. {
  126.     return self;
  127. }
  128.  
  129. - renderMaps:(WW3DCamera *)camera
  130.     startingAt:(RtFloat)shutterOpenTime
  131.     endingAt:(RtFloat)shutterCloseTime
  132. {
  133.     return self;
  134. }
  135.  
  136. - renderMaps:(WW3DCamera *)camera
  137. {
  138.     return self;
  139. }
  140.  
  141. - renderSelfAsBox:(WW3DCamera *)camera
  142.     startingAt:(RtFloat)shutterOpenTime
  143.     endingAt:(RtFloat)shutterCloseTime
  144. {
  145.     return [ribCommandList renderSelfAsBox:camera
  146.                startingAt:shutterOpenTime
  147.                endingAt:shutterCloseTime];
  148. }
  149.  
  150. - renderSelf:(WW3DCamera *)camera
  151.     startingAt:(RtFloat)shutterOpenTime
  152.     endingAt:(RtFloat)shutterCloseTime
  153. {
  154.     return [ribCommandList renderSelf:camera
  155.                startingAt:shutterOpenTime
  156.                endingAt:shutterCloseTime];
  157. }
  158.  
  159. - renderSelf:(WW3DCamera *)camera
  160. {
  161.     return [ribCommandList renderSelf:camera];
  162. }
  163.  
  164. - preRenderSelf:(WW3DCamera *)camera
  165.     startingAt:(RtFloat)shutterOpenTime
  166.     endingAt:(RtFloat)shutterCloseTime
  167. {
  168.     return [ribCommandList preRenderSelf:camera
  169.                startingAt:shutterOpenTime
  170.                endingAt:shutterCloseTime];
  171. }
  172.  
  173. - preRenderSelf:(WW3DCamera *)camera
  174. {
  175.     return [ribCommandList preRenderSelf:camera];
  176. }
  177.  
  178. - transformCTM:(WW3DAttributeState *)attributeState
  179.     startingAt:(RtFloat)shutterOpenTime
  180.     endingAt:(RtFloat)shutterCloseTime 
  181. {
  182.     return [ribCommandList transformCTM:attributeState
  183.                            startingAt:shutterOpenTime
  184.                endingAt:shutterCloseTime]; 
  185. }
  186.  
  187. // methods to make me look like a compound command:
  188. - (int)count {  return [ribCommandList count]; }
  189. - objectAt:(int)i {  return [ribCommandList objectAt:i]; }
  190.  
  191.  
  192. // WavesWorld archiving:
  193. // writeEve:(NXStream *)stream
  194. // writeScene:(NXStream *)stream
  195.  
  196. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  197. {
  198.     int  i;
  199.     
  200.     for (i = 0; i < tab; i++) {
  201.     NXPrintf(stream, "\t");
  202.     }
  203.     NXPrintf(stream, "WW3DAxes %f %f %f %f", radius, zMin, zMax, thetaMax, yScale);
  204.     return self;
  205. }
  206.  
  207. - writeScene:(NXStream *)stream atTabLevel:(int)tab
  208. {
  209.     int  i;
  210.     
  211.     for (i = 0; i < tab; i++) {
  212.     NXPrintf(stream, "\t");
  213.     }
  214.     NXPrintf(stream, "WW3DAxes %f %f %f %f", radius, zMin, zMax, thetaMax, yScale);
  215.     return self;
  216. }
  217.  
  218. - write3DTextScene:(NXStream *)stream atTabLevel:(int)tab index:(int)index time:(float)time until:(float)lastTime
  219. {
  220.    int  i;
  221.  
  222.  
  223.    for (i = 0; i < tab; i++)
  224.    {  NXPrintf(stream, "\t");
  225.    }
  226.  
  227.    NXPrintf(stream, "startShape %s; ", [[self class] name]);
  228.    // need tab
  229.    // need index (position in current list)
  230.    NXPrintf(stream, 
  231.         "EveCmd {Translate [expr { %d * $__text__(tabLength)}] [expr {$__text__(spacingFactor) * %d * $__text__(spacing) * $__text__(fontSize)}] 0 };\n", 
  232.             tab, index); 
  233.    NXPrintf(stream, "  EveCmd {WW3DText $__text__(fontName) $__text__(fontSize) {");
  234.    [self writeEve:stream atTabLevel:tab];
  235.    NXPrintf(stream, "} left;}\n");
  236.   NXPrintf(stream, "endShape;\n");
  237.  
  238.   return self;
  239. }
  240.  
  241. - writeInventorAtTime:(float)currentTime to:(NXStream *)stream atTabLevel:(int)tab
  242. {
  243.    int  i;
  244.  
  245.  
  246.    for (i = 0; i < tab; i++)
  247.    {  NXPrintf(stream, "\t");
  248.    }
  249.    NXPrintf(stream, "# ");
  250.    [self writeEve:stream atTabLevel:tab];
  251.    NXPrintf(stream, "\n");
  252.  
  253.    return [ribCommandList writeInventorAtTime:currentTime to:stream atTabLevel:tab];
  254. }
  255.  
  256. #define typeVector "@ffff"
  257. #define typeValues &ribCommandList, &radius, &zMin, &zMax, &yScale
  258.  
  259. - read:(NXTypedStream *)stream 
  260. {
  261.     int version;
  262.     
  263.     [super read:stream];
  264.     version = NXTypedStreamClassVersion(stream,"WW3DAxes");
  265.     if (version == 0) NXReadTypes(stream, "i", &version), version = 1;
  266.     if (version == 1)
  267.     {  NXReadTypes(stream, typeVector, typeValues);
  268.        NXReadArray(stream, "f", 6, boundingBox);
  269.        myShape = NXReadObject(stream);
  270.        xScale = zScale = 1./sqrt((double)yScale);
  271.     }
  272.  
  273.     return self;
  274. }
  275.  
  276. - write:(NXTypedStream *)stream 
  277. {
  278.     [super write:stream];
  279.     NXWriteTypes(stream, typeVector, typeValues);
  280.     NXWriteArray(stream, "f", 6, boundingBox);
  281.     NXWriteObjectReference(stream, myShape);
  282.     return self;
  283. }
  284.  
  285. - (BOOL)theSameAs:otherRIBCommand
  286. {
  287.   if (radius != [otherRIBCommand radius])
  288.   {  return NO;
  289.   }
  290.   if (yScale != [otherRIBCommand yScale])
  291.   {  return NO;
  292.   }
  293.   if (zMin != [otherRIBCommand zMin])
  294.   {  return NO;
  295.   }
  296.   if (zMax != [otherRIBCommand zMax])
  297.   {  return NO;
  298.   }
  299.   if (thetaMax != [otherRIBCommand thetaMax])
  300.   {  return NO;
  301.   }
  302.   return YES;
  303. }
  304.  
  305. - (BOOL)isMoot
  306. {
  307.   return NO;
  308. }
  309.  
  310. - (BOOL)isMootStartingAt:(float)startTime endingAt:(float)endTime  {  return [self isMoot];  }
  311.  
  312. // boy, this is dumb... This is to get around the stupid warnings from the compiler - ask wave for details
  313. - class { return [super class]; }
  314.  
  315. @end
  316.