home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Stuff / 3D_Reality / 3D_Reality_API / Examples / ControlPoint.bproj / ControlPoint.m < prev    next >
Encoding:
Text File  |  1992-10-09  |  1.8 KB  |  80 lines

  1.  
  2. /* ControlPoint.m    Peter Wickersham
  3.  *
  4.  * Methods for ControlPoint class.
  5.  *
  6.  */
  7.  
  8. #import "../Stone3DAPI/Stone3D.h"
  9. #import "ControlPoint.h"
  10. #import "Camera.h"
  11.  
  12. #import <ri/ri.h>
  13.  
  14. #define RADIUS 0.025
  15.  
  16. @implementation ControlPoint
  17.  
  18. // Initialize the bounding box and standard Shape stuff.
  19. - init 
  20. {
  21.     [super init];
  22.     [self calcBoundingBox];
  23.     return self;
  24. }
  25.  
  26. // Return the current translation of the ControlPoint by yanking the val ues
  27. // directly out of our transformation matrix.    
  28. - trans:(RtFloat *)t
  29. {
  30.     bcopy((char *)&transform[3][0],(char *)t,(3*sizeof(RtFloat)));    
  31.     return self;
  32. }
  33.  
  34. // We need to implement calcBoundingBox in order for the control tools to be
  35. // able to select our points.
  36. - calcBoundingBox
  37. {
  38.     // X Min and X Max
  39.     boundingBox[0] = -RADIUS;
  40.     boundingBox[1] = RADIUS;
  41.     
  42.     // Y Min and Y Max
  43.     boundingBox[2] = -RADIUS;
  44.     boundingBox[3] = RADIUS;
  45.     
  46.     // Z Min and Z Max
  47.     boundingBox[4] = -RADIUS;
  48.     boundingBox[5] = RADIUS;
  49.     return self;
  50. }
  51.  
  52. // doRenderSelf: is where we generate RIB for rendering.  See Patch.m for
  53. // more details.
  54. - doRenderSelf: (Camera *) camera
  55. {
  56.     RtFloat  newFidel[2] = {4.0 , 2.0};
  57.     RtInt fidel;
  58.     RtFloat  oldFidel[2];
  59.  
  60.     // If we are rendering to the screen then do it at a low resolution, 
  61.     // making to sure to store the Camera's current fidelity setting. 
  62.     if (NXDrawingStatus == NX_DRAWING) {
  63.     fidel = [camera fidelity];
  64.     oldFidel[0]=oldFidel[1]=fidel;   
  65.     [super doRenderSelf:camera];
  66.     RiGeometricApproximation(RI_TESSELATION,RI_PARAMETRIC,
  67.         (RtPointer)newFidel,RI_NULL);
  68.     }
  69.     
  70.     // Draw our control point as a sphere
  71.     RiSphere(RADIUS, -RADIUS, RADIUS, 360.0, RI_NULL);
  72.     
  73.     // Restore the Camera's settings
  74.     if (NXDrawingStatus == NX_DRAWING) {
  75.     RiGeometricApproximation(RI_TESSELATION,RI_PARAMETRIC,
  76.         (RtPointer)oldFidel,RI_NULL);
  77.     }
  78.  
  79.     return self;
  80. }