home *** CD-ROM | disk | FTP | other *** search
/ Altsys Virtuoso 2.0K / virtuoso_20k.iso / DemoApps / Graphics / 2D_3D / ShaderInspector / Source / SimpleCamera.m < prev    next >
Encoding:
Text File  |  1992-12-02  |  2.4 KB  |  100 lines

  1. //    Some portions of this code are Copyright 1992  Thomas A. Dilligan
  2. //        All Rights Reserved
  3. //
  4. // For best results, set tabstop=4
  5.  
  6. #import "SimpleCamera.h"
  7.  
  8. //This code Shamelessly pinched from Simple.app and then heavily modified.
  9.  
  10. @implementation SimpleCamera
  11. - initFrame:(const NXRect *) theRect
  12. {
  13.       RtPoint fromP = {0,0,5.0}, toP = {0,0,0};
  14.     id aShape;
  15.     [super initFrame:theRect];
  16.     [self setEyeAt:fromP toward:toP roll:0.0];
  17.     aShape=[[SimpleShape alloc] init];
  18.     [[self setWorldShape:aShape] free];
  19.     [self setSurfaceTypeForAll:N3D_SmoothSolids chooseHider:YES];
  20.     theRotator=[[N3DRotator alloc] initWithCamera:self];
  21.     return self;
  22. }
  23.  
  24. - displayPhotoreal;
  25. {
  26.     char text[256];
  27.     [self setDelegate:self];
  28.     rendering=[self renderAsTIFF];
  29.     if(rendering)
  30.     {
  31.         strcpy(origionalTitle,[window title]);
  32.         sprintf(text,"%s - Rendering...",origionalTitle);
  33.         [window setTitle:text];
  34.     }
  35.     return self;
  36. }
  37.  
  38. - camera:theCamera didRenderStream:(NXStream *)imageStream  tag:(int)theJob frameNumber:(int)currentFrame
  39. {
  40.     id bitmap;
  41.     char text[256],*ending;
  42.     strcpy(text,[window title]);
  43.     ending=rindex(text,'-');
  44.     ending[-1]='\0';
  45.     [window setTitle:text];
  46.     bitmap=[[NXBitmapImageRep alloc] initFromStream:imageStream];
  47.     [self lockFocus];
  48.     [bitmap draw];
  49.     [self unlockFocus];
  50.     rendering=0;
  51.     [window flushWindow];
  52.     return self;
  53. }
  54.  
  55.  
  56. #define ACTIVEBUTTONMASK (NX_MOUSEUPMASK|NX_MOUSEDRAGGEDMASK)
  57. - mouseDown:(NXEvent *)theEvent
  58. {
  59.     int                     oldMask;
  60.     NXPoint        oldMouse, newMouse, dMouse;
  61.     RtMatrix        rmat, irmat;
  62.  
  63.     if(rendering)
  64.         return self;
  65.     [theRotator setRotationAxis:N3D_AllAxes];
  66.     [self lockFocus];
  67.     oldMask = [window addToEventMask:ACTIVEBUTTONMASK];
  68.   
  69.     [self setSurfaceTypeForAll:N3D_WireFrame chooseHider:YES];
  70.   
  71.     oldMouse = theEvent->location;
  72.     [self convertPoint:&oldMouse fromView:nil];
  73.     while (1)
  74.     {
  75.         newMouse = theEvent->location;
  76.         [self convertPoint:&newMouse fromView:nil];
  77.         dMouse.x = newMouse.x - oldMouse.x;
  78.         dMouse.y = newMouse.y - oldMouse.y;
  79.         if (dMouse.x != 0.0 || dMouse.y != 0.0)
  80.         {
  81.             [theRotator trackMouseFrom:&oldMouse to:&newMouse
  82.             rotationMatrix:rmat andInverse:irmat];
  83.             [worldShape concatTransformMatrix:rmat premultiply:NO];
  84.             [self display];
  85.         }
  86.         theEvent = [NXApp getNextEvent:ACTIVEBUTTONMASK];
  87.         if (theEvent->type == NX_MOUSEUP)
  88.             break;
  89.         oldMouse = newMouse;
  90.   }
  91.     [self setSurfaceTypeForAll:N3D_SmoothSolids chooseHider:YES];    
  92.     [self display];
  93.     [self unlockFocus];
  94.  
  95.     [window setEventMask:oldMask];
  96.     return self;
  97. }
  98.  
  99. @end
  100.