Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. I am having a problem with  coordinate systems...  
  2. I create my wheel layer,  I stick it in the centre of the screen
  3.  
  4.  
  5. -(id) init
  6. {
  7.     if( (self=[super init] )) {
  8.         Wheel * wheel = [ [ [Wheel alloc] init] autorelease];
  9.        
  10.         [wheel setupWithMagnets: 3];
  11.    
  12.         // takes orientation into account
  13.         CGSize winSize = [[CCDirector sharedDirector] winSizeInPixels];
  14.         printf("%f, %f\n", (float) winSize.width, (float) winSize.height);
  15.        
  16.         wheel.position =  ccp ( winSize.width / 2 - 1, winSize.height / 2 - 1 );
  17.         printf("%f, %f\n", (float) wheel.position.x, (float) wheel.position.y);
  18.        
  19.        
  20.         [self addChild: wheel];
  21.        
  22.         // - - -
  23.        
  24.     }
  25.     return self;
  26. }
  27.  
  28.  
  29.  
  30. Now straightaway I don't understand why it positions itself correctly with the centre of the layer in the centre of the screen
  31. surely it would only do this if the wheel's  self.anchorPoint = ccp (.5, .5);
  32.  but I never explicitly  set it,  and the default is 0,0
  33.  
  34. - (void) setupWithMagnets: (int) in_magnets
  35. {
  36.     self.magnets = in_magnets;
  37.    
  38.     self.magnetOffset = 0;
  39.    
  40.     //self.anchorPoint = ccp (.5, .5);
  41.    
  42.     CCLayerColor* colorLayer = [CCLayerColor layerWithColor: ccc4(0, 67, 67, 67)];
  43.     colorLayer.anchorPoint = ccp (.5, .5); // << makes no diff
  44.     [self addChild:colorLayer z: -1];
  45.    
  46.     thetaWheel = 0.;
  47.     dTheta_dt = 0.;
  48.     mass = K_WHEEL_MASS;
  49.     tracking = NO;
  50.    
  51.     [self schedule: @selector(displayLinkIsCallingBack:)];
  52.  
  53.    
  54.     [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate: self
  55.                                                      priority: 0
  56.                                               swallowsTouches: YES];
  57.    
  58.     //displayLink = [CADisplayLink displayLinkWithTarget: self
  59.     //                                        selector:
  60.     //             @selector(displayLinkIsCallingBack:) ];
  61.    
  62.     //[displayLink addToRunLoop: [NSRunLoop currentRunLoop]
  63.     //                forMode: NSDefaultRunLoopMode ];
  64.    
  65.     CCSprite * centerMarker = [CCSprite spriteWithFile: @"Icon.png"];
  66.     centerMarker.anchorPoint = ccp (.5, .5);
  67.     centerMarker.position = ccp(0, 0);
  68.     [self addChild: centerMarker];
  69.    
  70.     for (int i=0; i<3; i++)
  71.     {
  72.         CCSprite * button = [CCSprite spriteWithFile: @"seeker.png"];
  73.        
  74.         float RADIUS = 150.;
  75.         float theta = M_TWO_PI * (i / 3.) - M_PI / 2.;
  76.        
  77.         button.anchorPoint = ccp (.5, .5);
  78.         button.position = fromPolar(RADIUS, theta);
  79.        
  80.         [self addChild: button];
  81.     }
  82. }
  83.  
  84.  
  85. - (void) displayLinkIsCallingBack: (ccTime) deltaT
  86. {
  87.     // Display link fires every time the screen is to be refreshed
  88.     // The wheel remembers its angle and its velocity
  89.     // Each time display link fires, potentially TWO forces act upon the wheel
  90.    
  91.     // (1) When user initiated contact, fingerprint position on wheel was recorded
  92.     //     as finger moves, invisible elastic stretches between finger and fingerprint,
  93.     //     pulling wheel towards finger
  94. BLA
  95.     // (2) imagine a magnet sitting behind the centre of each button.
  96.     //     These magnets encourage the wheel to settle exactly in
  97.     //     one of its preset positions 
  98. BLA
  99.     // using CATransaction like this goes from 14fps to 19fps
  100.     //[CATransaction begin];
  101.     //[CATransaction setDisableActions: YES];
  102.    
  103.     // NEG, as coord system is flipped/fucked
  104.     //self.transform = CGAffineTransformMakeRotation(-thetaWheel);
  105.    
  106. #define FAC  (-360. / M_TWO_PI)
  107.    
  108.     self.rotation = FAC * (-thetaWheel);
  109.     //[CATransaction commit];
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement