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

  1. // This compound command was inspired by the cool hack Steve Drucker
  2. // used in his PhD system to take some small (usually 8 or 16) views of a
  3. // "real" object and map it into a 3D virtual environment.  This
  4. // technique probably originates in flight simulators and/or video games,
  5. // but I'm stealing it from Steve, so that's who I'm crediting with the
  6. // idea...
  7.  
  8. // The 
  9.  
  10.  
  11. // WW3DVideoHack {list of texture files} width height
  12.  
  13. // The difficulty here is that I need to determine at renderSelf: time
  14. // where I am in relation to the camera's view point.  If I can do that,
  15. // I'm golden.
  16.  
  17. // what I need to do is transform the vector (0, 0, 1) 
  18.  
  19.  
  20.  
  21. #import "WW3DVideoHack.h"
  22. #import "RIBTransformBegin.h"
  23. #import "RIBScale.h"
  24. #import "RIBSphere.h"
  25. #import "RIBTransformEnd.h"
  26. #import "WWSample.h"
  27. #import "WWEveParser.h"
  28.  
  29. @implementation WW3DVideoHack
  30.  
  31. + initialize { return [WW3DVideoHack setVersion:1], self; }
  32.  
  33. - init
  34. {
  35.   [super init];
  36.  
  37.   radius = 1.0;
  38.   zMin = -1.0;
  39.   zMax =  1.0;
  40.   xScale = yScale = zScale = 1.0;
  41.   ribCommandList  = [[RIBCommandList alloc] init];
  42.   dirtyBoundingBox = YES;
  43.   
  44.   return self;
  45. }
  46.  
  47.  
  48. - awake
  49. {
  50.     [super awake];
  51.     dirtyBoundingBox = YES;
  52.     return self;
  53. }
  54.  
  55.  
  56. - setYScale:(RtFloat)newYScale
  57. {
  58.    yScale = newYScale;
  59.    xScale = zScale = 1./sqrt((double)yScale);
  60.    return self;
  61. }
  62.  
  63. - setRadius:(RtFloat)newRadius 
  64.      zMin:(RtFloat)newZMin zMax:(RtFloat)newZMax 
  65.      thetaMax:(RtFloat)newThetaMax yScale:(RtFloat)newYScale
  66.      n:(int)newN tokens:(RtToken *)newTokens parms:(RtPointer *)newParms archiveVector:(char **)newArchiveVector
  67.      printfTypeVector:(int *)newPrintfTypeVector printfNVector:(int *)newPrintfNVector
  68. {  
  69.    id  sphereObj;
  70.  
  71.  
  72.    radius = newRadius;
  73.    zMin = newZMin;
  74.    zMax = newZMax;
  75.    thetaMax = newThetaMax;
  76.    [self setYScale:newYScale];
  77.  
  78.    // I should make sure there is some non-whitespace text before I waste my time...
  79.    [ribCommandList empty];
  80.  
  81.    sphereObj = [[RIBSphere alloc] init]; 
  82.    [sphereObj setRadius:radius zMin:zMin zMax:zMax thetaMax:thetaMax
  83.                     n:newN tokens:newTokens parms:newParms archiveVector:newArchiveVector printfTypeVector:newPrintfTypeVector printfNVector:newPrintfNVector];
  84.    [sphereObj setMyShape:myShape];
  85.  
  86.    [ribCommandList insertObject:sphereObj at:0];
  87.    [ribCommandList insertObject:[[[[RIBScale alloc] init] setSX:xScale sy:yScale sz:zScale] setMyShape:myShape] at:0];
  88.    [ribCommandList insertObject:[[[RIBTransformBegin alloc] init] setMyShape:myShape] at:0];
  89.    [ribCommandList addObject:[[[RIBTransformEnd alloc] init] setMyShape:myShape]];
  90.  
  91.    dirtyBoundingBox = TRUE;
  92.   
  93.    return self;
  94. }
  95.  
  96. - setRadius:(RtFloat)newRadius { radius = newRadius; dirtyBoundingBox = TRUE; return self; }
  97. - setZMin:(RtFloat)newZMin { zMin = newZMin; dirtyBoundingBox = TRUE; return self; }
  98. - setZMax:(RtFloat)newZMax { zMax = newZMax; dirtyBoundingBox = TRUE; return self; }
  99.  
  100. - (RtFloat)radius { return radius; } 
  101. - (RtFloat)zMin { return zMin; }
  102. - (RtFloat)zMax { return zMax; }
  103.  
  104. - free
  105. {
  106.     [ribCommandList free];
  107.     return [super free];
  108. }
  109.  
  110. - (BOOL)hasBoundingBox        { return YES; }
  111. - (BOOL)isMotionBlurrable    { return YES; }
  112. - (BOOL)isCompoundCommand    { return YES; }
  113.  
  114. - setBoundingBox:(RtBound *)newBoundingBox
  115. {
  116.     N3D_CopyBound(*newBoundingBox, boundingBox);
  117.     return self;
  118. }
  119.  
  120. - calculateBoundingBoxStartingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime  
  121. {  
  122.     dirtyBoundingBox = NO;
  123.     [ribCommandList calculateBoundingBoxStartingAt:shutterOpenTime
  124.                     endingAt:shutterCloseTime];
  125.     return [self setBoundingBox:[ribCommandList boundingBox]];
  126. }
  127.  
  128. - (RtBound *)boundingBox 
  129.     if (dirtyBoundingBox) { 
  130.     [self calculateBoundingBoxStartingAt:[[myShape sceneClock] timestamp]
  131.               endingAt:[[myShape sceneClock] timestamp]];
  132.     }
  133.     return &boundingBox; 
  134. }
  135.  
  136. - (float)lastSampleIsAt { return 0.0; }
  137.  
  138. - (unsigned long int)maxSampleBandwidth { return [ribCommandList maxSampleBandwidth]; }
  139.  
  140. - setMyShape:shape
  141. {
  142.     myShape = shape;
  143.     return self;
  144. }
  145.  
  146. - shape
  147. {
  148.     return myShape;
  149. }
  150.  
  151. - renderMaps:(WW3DCamera *)camera
  152.     startingAt:(RtFloat)shutterOpenTime
  153.     endingAt:(RtFloat)shutterCloseTime usingStream:(NXStream *)ns
  154. {
  155.     return self;
  156. }
  157.  
  158. - renderMaps:(WW3DCamera *)camera usingStream:(NXStream *)ns
  159. {
  160.     return self;
  161. }
  162.  
  163. - renderMaps:(WW3DCamera *)camera
  164.     startingAt:(RtFloat)shutterOpenTime
  165.     endingAt:(RtFloat)shutterCloseTime
  166. {
  167.     return self;
  168. }
  169.  
  170. - renderMaps:(WW3DCamera *)camera
  171. {
  172.     return self;
  173. }
  174.  
  175. - renderSelf:(WW3DCamera *)camera
  176.     startingAt:(RtFloat)shutterOpenTime
  177.     endingAt:(RtFloat)shutterCloseTime
  178. {
  179.     return [ribCommandList renderSelf:camera
  180.                startingAt:shutterOpenTime
  181.                endingAt:shutterCloseTime];
  182. }
  183.  
  184. - renderSelf:(WW3DCamera *)camera
  185. {
  186.     return [ribCommandList renderSelf:camera];
  187. }
  188.  
  189. - preRenderSelf:(WW3DCamera *)camera
  190.     startingAt:(RtFloat)shutterOpenTime
  191.     endingAt:(RtFloat)shutterCloseTime
  192. {
  193.     return [ribCommandList preRenderSelf:camera
  194.                startingAt:shutterOpenTime
  195.                endingAt:shutterCloseTime];
  196. }
  197.  
  198. - preRenderSelf:(WW3DCamera *)camera
  199. {
  200.     return [ribCommandList preRenderSelf:camera];
  201. }
  202.  
  203. - transformCTM:(RtMatrix)aMatrix 
  204.     startingAt:(RtFloat)shutterOpenTime
  205.     endingAt:(RtFloat)shutterCloseTime 
  206. {
  207.     return [ribCommandList transformCTM:aMatrix
  208.                            startingAt:shutterOpenTime
  209.                endingAt:shutterCloseTime]; 
  210. }
  211.  
  212. // methods to make me look like a compound command:
  213. - (int)count {  return [ribCommandList count]; }
  214. - objectAt:(int)i {  return [ribCommandList objectAt:i]; }
  215.  
  216.  
  217. // WavesWorld archiving:
  218. // writeEve:(NXStream *)stream
  219. // writeScene:(NXStream *)stream
  220.  
  221. - writeEve:(NXStream *)stream atTabLevel:(int)tab
  222. {
  223.     int  i;
  224.     
  225.     for (i = 0; i < tab; i++) {
  226.     NXPrintf(stream, "\t");
  227.     }
  228.     NXPrintf(stream, "WW3DVideoHack %f %f %f %f", radius, zMin, zMax, thetaMax, yScale);
  229.     return self;
  230. }
  231.  
  232. - writeScene:(NXStream *)stream atTabLevel:(int)tab
  233. {
  234.     int  i;
  235.     
  236.     for (i = 0; i < tab; i++) {
  237.     NXPrintf(stream, "\t");
  238.     }
  239.     NXPrintf(stream, "WW3DVideoHack %f %f %f %f", radius, zMin, zMax, thetaMax, yScale);
  240.     return self;
  241. }
  242.  
  243. #define typeVector "ffff"
  244. #define typeValues &radius, &zMin, &zMax, &yScale
  245.  
  246. - read:(NXTypedStream *)stream 
  247. {
  248.     int version;
  249.     
  250.     [super read:stream];
  251.     version = NXTypedStreamClassVersion(stream,"WW3DVideoHack");
  252.     if (version == 0) NXReadTypes(stream, "i", &version), version = 1;
  253.     if (version == 1)
  254.     {  NXReadTypes(stream, typeVector, typeValues);
  255.        NXReadArray(stream, "f", 6, boundingBox);
  256.        myShape = NXReadObject(stream);
  257.        xScale = zScale = 1./sqrt((double)yScale);
  258.     }
  259.  
  260.     return self;
  261. }
  262.  
  263. - write:(NXTypedStream *)stream 
  264. {
  265.     [super write:stream];
  266.     NXWriteTypes(stream, typeVector, typeValues);
  267.     NXWriteArray(stream, "f", 6, boundingBox);
  268.     NXWriteObjectReference(stream, myShape);
  269.     return self;
  270. }
  271.  
  272. - (BOOL)theSameAs:otherRIBCommand
  273. {
  274.   // WAVE: really should try and return YES, but for now...
  275.   return NO;
  276. }
  277.  
  278. - (BOOL)isMoot
  279. {
  280.   return NO;
  281. }
  282.  
  283. // boy, this is dumb... This is to get around the stupid warnings from the compiler - ask wave for details
  284. - class { return [super class]; }
  285.  
  286. @end
  287.