home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Graph / RotatorCamera.m < prev    next >
Encoding:
Text File  |  1992-06-21  |  1.7 KB  |  54 lines

  1.  
  2. /*
  3.     RotatorCamera.m
  4.  
  5.     RotatorCamera is an N3DCamera that tracks the mouse to rotate the
  6.     contents of the camera using a N3DRotator.
  7.  
  8.     You may freely copy, distribute, and reuse the code in this example.
  9.     C disclaims any warranty of any kind, expressed or implied, as to its
  10.     fitness for any particular use.
  11. */
  12.  
  13. #import "Graph.h"
  14.  
  15. #define MOUSE_MASK (NX_LMOUSEDOWNMASK|NX_LMOUSEDRAGGEDMASK|NX_LMOUSEUPMASK)
  16.  
  17. @implementation RotatorCamera
  18.  
  19. /*
  20.  * As we track the mouse, we use a N3DRotator object to calculate the new
  21.  * viewing transforms, and then apply those to the camera's world shape.
  22.  * If our window's delegate is interested, we notify it that we've changed
  23.  * the document.
  24.  */
  25. - mouseDown:(NXEvent *)event {
  26.     N3DRotator *rotator = [[N3DRotator allocFromZone:[self zone]] initWithCamera:self];
  27.     RtMatrix rotationXForm;
  28.     RtMatrix inverseRotationXForm;
  29.     NXEvent newEvent;
  30.     NXPoint oldLocation, newLocation;
  31.  
  32.     oldLocation = event->location;
  33.     [self convertPoint:&oldLocation fromView:nil];
  34.     [window addToEventMask:NX_LMOUSEDRAGGEDMASK];
  35.     do {
  36.     newEvent = *[NXApp getNextEvent:MOUSE_MASK];
  37.     newLocation = newEvent.location;
  38.     [self convertPoint:&newLocation fromView:nil];
  39.     if (oldLocation.x != newLocation.x || oldLocation.y != newLocation.y) {
  40.         [rotator trackMouseFrom:&oldLocation to:&newLocation
  41.         rotationMatrix:rotationXForm andInverse:inverseRotationXForm];
  42.         [worldShape concatTransformMatrix:rotationXForm premultiply:NO];
  43.         [self display];
  44.         if ([[window delegate] respondsTo:@selector(docChanged)])
  45.         [[window delegate] docChanged];
  46.     }
  47.     oldLocation = newLocation;
  48.     } while (newEvent.type != NX_LMOUSEDOWN && newEvent.type != NX_LMOUSEUP);
  49.     [rotator free];
  50.     return self;
  51. }
  52.  
  53. @end
  54.